|
14 | 14 | using EdgeDB; |
15 | 15 | using Microsoft.AspNetCore.Routing.Internal; |
16 | 16 | using Newtonsoft.Json; |
| 17 | +using Wissance.EdgeDb.Configurator; |
17 | 18 | using Wissance.WeatherControl.WebApi.V2.Config; |
18 | 19 | using Wissance.WeatherControl.WebApi.V2.Data; |
19 | 20 |
|
@@ -72,84 +73,22 @@ private void ConfigureLogging(IServiceCollection services) |
72 | 73 |
|
73 | 74 | private void ConfigureDatabase(IServiceCollection services) |
74 | 75 | { |
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() |
83 | 77 | { |
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); |
90 | 85 | } |
91 | 86 |
|
92 | 87 | private void ConfigureWebApi(IServiceCollection services) |
93 | 88 | { |
94 | 89 | services.AddControllers(); |
95 | 90 | } |
96 | 91 |
|
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 | | - |
153 | 92 | public ApplicationSettings Settings { get; set; } |
154 | 93 | private IConfiguration Configuration { get; } |
155 | 94 | public IWebHostEnvironment Environment { get; } |
|
0 commit comments