forked from NpgsqlRest/NpgsqlRest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
94 lines (76 loc) · 3.51 KB
/
Copy pathProgram.cs
File metadata and controls
94 lines (76 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// dotnet publish -r win-x64 -c Release
// dotnet publish -r linux-x64 -c Release
using System.Diagnostics;
using NpgsqlRest;
using NpgsqlRest.Defaults;
using NpgsqlRestClient;
using static NpgsqlRestClient.Config;
using static NpgsqlRestClient.Builder;
using static NpgsqlRestClient.App;
if (Arguments.Parse(args) is false)
{
return;
}
Stopwatch sw = new();
sw.Start();
Build(args);
BuildInstance();
BuildLogger();
var connectionString = BuildConnectionString();
if (connectionString is null)
{
return;
}
BuildAuthentication();
BuildCors();
WebApplication app = Build();
Configure(app, () =>
{
sw.Stop();
Logger?.Information("Started in {0}", sw);
Logger?.Information("Listening on {0}", app.Urls);
});
ConfigureStaticFiles(app);
NpgsqlRestOptions options = new()
{
ConnectionString = connectionString,
ConnectionFromServiceProvider = false,
SchemaSimilarTo = GetConfigStr("SchemaSimilarTo", NpgsqlRestCfg),
SchemaNotSimilarTo = GetConfigStr("SchemaNotSimilarTo", NpgsqlRestCfg),
IncludeSchemas = GetConfigEnumerable("IncludeSchemas", NpgsqlRestCfg)?.ToArray(),
ExcludeSchemas = GetConfigEnumerable("ExcludeSchemas", NpgsqlRestCfg)?.ToArray(),
NameSimilarTo = GetConfigStr("NameSimilarTo", NpgsqlRestCfg),
NameNotSimilarTo = GetConfigStr("NameNotSimilarTo", NpgsqlRestCfg),
IncludeNames = GetConfigEnumerable("IncludeNames", NpgsqlRestCfg)?.ToArray(),
ExcludeNames = GetConfigEnumerable("ExcludeNames", NpgsqlRestCfg)?.ToArray(),
UrlPathPrefix = GetConfigStr("UrlPathPrefix", NpgsqlRestCfg),
UrlPathBuilder = GetConfigBool("KebabCaseUrls", NpgsqlRestCfg) ? DefaultUrlBuilder.CreateUrl : App.CreateUrl,
NameConverter = GetConfigBool("CamelCaseNames", NpgsqlRestCfg) ? DefaultNameConverter.ConvertToCamelCase : n => n?.Trim('"'),
RequiresAuthorization = GetConfigBool("RequiresAuthorization", NpgsqlRestCfg),
LogEndpointCreatedInfo = GetConfigBool("LogEndpointCreatedInfo", NpgsqlRestCfg),
LogAnnotationSetInfo = GetConfigBool("LogEndpointCreatedInfo", NpgsqlRestCfg),
LogConnectionNoticeEvents = GetConfigBool("LogConnectionNoticeEvents", NpgsqlRestCfg),
LogCommands = GetConfigBool("LogCommands", NpgsqlRestCfg),
LogCommandParameters = GetConfigBool("LogCommandParameters", NpgsqlRestCfg),
CommandTimeout = GetConfigInt("CommandTimeout", NpgsqlRestCfg),
DefaultHttpMethod = GetConfigEnum<Method?>("DefaultHttpMethod", NpgsqlRestCfg),
DefaultRequestParamType = GetConfigEnum<RequestParamType?>("DefaultRequestParamType", NpgsqlRestCfg),
CommentsMode = GetConfigEnum<CommentsMode>("CommentsMode", NpgsqlRestCfg),
RequestHeadersMode = GetConfigEnum<RequestHeadersMode>("RequestHeadersMode", NpgsqlRestCfg),
RequestHeadersParameterName = GetConfigStr("RequestHeadersParameterName", NpgsqlRestCfg) ?? "headers",
EndpointCreated = CreateEndpointCreatedHandler(),
ValidateParameters = CreateValidateParametersHandler(),
ReturnNpgsqlExceptionMessage = GetConfigBool("ReturnNpgsqlExceptionMessage", NpgsqlRestCfg, true),
PostgreSqlErrorCodeToHttpStatusCodeMapping = CreatePostgreSqlErrorCodeToHttpStatusCodeMapping(),
BeforeConnectionOpen = BeforeConnectionOpen(connectionString),
AuthenticationOptions = new()
{
DefaultAuthenticationType = GetConfigStr("DefaultAuthenticationType", AuthCfg)
},
EndpointCreateHandlers = CreateCodeGenHandlers(connectionString),
SourcesCreated = SourcesCreated,
CustomRequestHeaders = GetCustomHeaders()
};
ExternalAuth.Configure(app, options);
app.UseNpgsqlRest(options);
app.Run();