Skip to content

Commit daac831

Browse files
committed
edgedb configurator used
1 parent 7d60ff9 commit daac831

File tree

3 files changed

+12
-72
lines changed

3 files changed

+12
-72
lines changed

WeatherControl/Wissance.WeatherControl.EdgeDb.Data/Wissance.WeatherControl.EdgeDb.Data.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="EdgeDB.Net.Driver" Version="1.0.4" />
9+
<PackageReference Include="EdgeDB.Net.Driver" Version="1.2.3" />
1010
<PackageReference Include="Wissance.WebApiToolkit" Version="1.3.0" />
1111
</ItemGroup>
1212

WeatherControl/Wissance.WeatherControl.WebApi.V2/Startup.cs

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using EdgeDB;
1515
using Microsoft.AspNetCore.Routing.Internal;
1616
using Newtonsoft.Json;
17+
using Wissance.EdgeDb.Configurator;
1718
using Wissance.WeatherControl.WebApi.V2.Config;
1819
using Wissance.WeatherControl.WebApi.V2.Data;
1920

@@ -72,84 +73,22 @@ private void ConfigureLogging(IServiceCollection services)
7273

7374
private void ConfigureDatabase(IServiceCollection services)
7475
{
75-
ILoggerFactory loggerFactory = services.BuildServiceProvider().GetRequiredService<ILoggerFactory>();
76-
// todo(UMV): Resolve security settings using Project Name: that is why important to have same project name for all Backend developers
77-
// use ~AppData\Local\EdgeDB\config\credentials
78-
string connStr = GetEdgeDbConnStrByProjectName(Settings.Database.ProjectName, loggerFactory);
79-
EdgeDBConnection conn = EdgeDBConnection.FromDSN(connStr);
80-
conn.TLSSecurity = TLSSecurityMode.Insecure;
81-
82-
services.AddEdgeDB(conn, cfg =>
76+
EdgeDBClientPoolConfig poolCfg = new EdgeDBClientPoolConfig()
8377
{
84-
cfg.ClientType = EdgeDBClientType.Tcp;
85-
cfg.SchemaNamingStrategy = INamingStrategy.CamelCaseNamingStrategy;
86-
cfg.DefaultPoolSize = 256;
87-
cfg.ConnectionTimeout = 5000;
88-
cfg.MessageTimeout = 10000;
89-
});
78+
ClientType = EdgeDBClientType.Tcp,
79+
SchemaNamingStrategy = INamingStrategy.CamelCaseNamingStrategy,
80+
DefaultPoolSize = 256,
81+
ConnectionTimeout = 5000,
82+
MessageTimeout = 10000
83+
};
84+
services.ConfigureEdgeDbDatabase(Settings.Database.ProjectName, poolCfg);
9085
}
9186

9287
private void ConfigureWebApi(IServiceCollection services)
9388
{
9489
services.AddControllers();
9590
}
9691

97-
/*private void ConfigureManagers(IServiceCollection services)
98-
{
99-
// services.AddScoped<StationManager>();
100-
// services.AddScoped<MeasurementsManager>();
101-
}*/
102-
103-
private string GetEdgeDbConnStrByProjectName(string projectName, ILoggerFactory loggerFactory)
104-
{
105-
ILogger<Startup> logger = loggerFactory.CreateLogger<Startup>();
106-
try
107-
{
108-
string projectCredentialsFile = GetEdgeDbProjectCredentialFile(projectName);
109-
string content = File.ReadAllText(projectCredentialsFile);
110-
EdgeDbProjectCredentials credentials = JsonConvert.DeserializeObject<EdgeDbProjectCredentials>(content);
111-
//JsonSerializer.Deserialize<EdgeDbProjectCredentials>(content);
112-
return string.Format(EdgeDbConnStrTemplate, credentials.User, credentials.Password, "localhost",
113-
credentials.Port,
114-
credentials.Database);
115-
}
116-
catch (Exception e)
117-
{
118-
logger.LogError($"An error occurred during attempt to build edgedb connection str: {e.Message}");
119-
return string.Empty;
120-
}
121-
}
122-
123-
private string GetEdgeDbProjectCredentialFile(string projectName)
124-
{
125-
string projectCredentialsFile = string.Empty;
126-
if (OperatingSystem.IsWindows())
127-
{
128-
// should be using ~AppData\Local\EdgeDB\config\credentials\{projectName}.json as a path
129-
string appData = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);
130-
projectCredentialsFile = Path.Combine(new string[]
131-
{
132-
appData,
133-
"EdgeDB", "config", "credentials",
134-
projectName + ".json"
135-
});
136-
}
137-
138-
if (OperatingSystem.IsLinux())
139-
{
140-
// linux - /.config/edgedb/credentials/{projectName}.json relative to home dir
141-
string home = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
142-
projectCredentialsFile = Path.Combine(new string[]
143-
{
144-
home,
145-
".config", "edgedb", "credentials",
146-
projectName + ".json"
147-
});
148-
}
149-
150-
return projectCredentialsFile;
151-
}
152-
15392
public ApplicationSettings Settings { get; set; }
15493
private IConfiguration Configuration { get; }
15594
public IWebHostEnvironment Environment { get; }

WeatherControl/Wissance.WeatherControl.WebApi.V2/Wissance.WeatherControl.WebApi.V2.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="EdgeDB.Net.Driver" Version="1.1.2" />
8+
<PackageReference Include="EdgeDB.Net.Driver" Version="1.2.3" />
99
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
1010
<PackageReference Include="Serilog" Version="2.11.0" />
1111
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
1212
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
1313
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
14+
<PackageReference Include="Wissance.EdgeDb.Configurator" Version="1.0.0" />
1415
<PackageReference Include="Wissance.WebApiToolkit" Version="1.3.0" />
1516
</ItemGroup>
1617

0 commit comments

Comments
 (0)