-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathConfigureOptions.cs
More file actions
349 lines (287 loc) · 21.7 KB
/
ConfigureOptions.cs
File metadata and controls
349 lines (287 loc) · 21.7 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.IO.Abstractions;
using Azure.DataApiBuilder.Config;
using Azure.DataApiBuilder.Config.ObjectModel;
using Azure.DataApiBuilder.Product;
using Cli.Constants;
using CommandLine;
using Microsoft.Extensions.Logging;
using Serilog;
using static Cli.Utils;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Cli.Commands
{
/// <summary>
/// Configure command options
/// This command will be used to configure non-entity config properties.
/// </summary>
[Verb("configure", isDefault: false, HelpText = "Configure non-entity config properties", Hidden = false)]
public class ConfigureOptions : Options
{
public ConfigureOptions(
string? dataSourceDatabaseType = null,
string? dataSourceConnectionString = null,
string? dataSourceOptionsDatabase = null,
string? dataSourceOptionsContainer = null,
string? dataSourceOptionsSchema = null,
bool? dataSourceOptionsSetSessionContext = null,
string? dataSourceHealthName = null,
bool? dataSourceUserDelegatedAuthEnabled = null,
string? dataSourceUserDelegatedAuthDatabaseAudience = null,
int? depthLimit = null,
bool? runtimeGraphQLEnabled = null,
string? runtimeGraphQLPath = null,
bool? runtimeGraphQLAllowIntrospection = null,
bool? runtimeGraphQLMultipleMutationsCreateEnabled = null,
bool? runtimeRestEnabled = null,
string? runtimeRestPath = null,
bool? runtimeRestRequestBodyStrict = null,
bool? runtimeMcpEnabled = null,
string? runtimeMcpPath = null,
string? runtimeMcpDescription = null,
bool? runtimeMcpDmlToolsEnabled = null,
bool? runtimeMcpDmlToolsDescribeEntitiesEnabled = null,
bool? runtimeMcpDmlToolsCreateRecordEnabled = null,
bool? runtimeMcpDmlToolsReadRecordsEnabled = null,
bool? runtimeMcpDmlToolsUpdateRecordEnabled = null,
bool? runtimeMcpDmlToolsDeleteRecordEnabled = null,
bool? runtimeMcpDmlToolsExecuteEntityEnabled = null,
bool? runtimeMcpDmlToolsAggregateRecordsEnabled = null,
int? runtimeMcpDmlToolsAggregateRecordsQueryTimeout = null,
bool? runtimeCacheEnabled = null,
int? runtimeCacheTtl = null,
CompressionLevel? runtimeCompressionLevel = null,
HostMode? runtimeHostMode = null,
IEnumerable<string>? runtimeHostCorsOrigins = null,
bool? runtimeHostCorsAllowCredentials = null,
string? runtimeHostAuthenticationProvider = null,
string? runtimeHostAuthenticationJwtAudience = null,
string? runtimeHostAuthenticationJwtIssuer = null,
string? azureKeyVaultEndpoint = null,
AKVRetryPolicyMode? azureKeyVaultRetryPolicyMode = null,
int? azureKeyVaultRetryPolicyMaxCount = null,
int? azureKeyVaultRetryPolicyDelaySeconds = null,
int? azureKeyVaultRetryPolicyMaxDelaySeconds = null,
int? azureKeyVaultRetryPolicyNetworkTimeoutSeconds = null,
CliBool? azureLogAnalyticsEnabled = null,
string? azureLogAnalyticsDabIdentifier = null,
int? azureLogAnalyticsFlushIntervalSeconds = null,
string? azureLogAnalyticsCustomTableName = null,
string? azureLogAnalyticsDcrImmutableId = null,
string? azureLogAnalyticsDceEndpoint = null,
CliBool? fileSinkEnabled = null,
string? fileSinkPath = null,
RollingInterval? fileSinkRollingInterval = null,
int? fileSinkRetainedFileCountLimit = null,
long? fileSinkFileSizeLimitBytes = null,
bool showEffectivePermissions = false,
string? config = null)
: base(config)
{
// Data Source
DataSourceDatabaseType = dataSourceDatabaseType;
DataSourceConnectionString = dataSourceConnectionString;
DataSourceOptionsDatabase = dataSourceOptionsDatabase;
DataSourceOptionsContainer = dataSourceOptionsContainer;
DataSourceOptionsSchema = dataSourceOptionsSchema;
DataSourceOptionsSetSessionContext = dataSourceOptionsSetSessionContext;
DataSourceHealthName = dataSourceHealthName;
DataSourceUserDelegatedAuthEnabled = dataSourceUserDelegatedAuthEnabled;
DataSourceUserDelegatedAuthDatabaseAudience = dataSourceUserDelegatedAuthDatabaseAudience;
// GraphQL
DepthLimit = depthLimit;
RuntimeGraphQLEnabled = runtimeGraphQLEnabled;
RuntimeGraphQLPath = runtimeGraphQLPath;
RuntimeGraphQLAllowIntrospection = runtimeGraphQLAllowIntrospection;
RuntimeGraphQLMultipleMutationsCreateEnabled = runtimeGraphQLMultipleMutationsCreateEnabled;
// Rest
RuntimeRestEnabled = runtimeRestEnabled;
RuntimeRestPath = runtimeRestPath;
RuntimeRestRequestBodyStrict = runtimeRestRequestBodyStrict;
// Mcp
RuntimeMcpEnabled = runtimeMcpEnabled;
RuntimeMcpPath = runtimeMcpPath;
RuntimeMcpDescription = runtimeMcpDescription;
RuntimeMcpDmlToolsEnabled = runtimeMcpDmlToolsEnabled;
RuntimeMcpDmlToolsDescribeEntitiesEnabled = runtimeMcpDmlToolsDescribeEntitiesEnabled;
RuntimeMcpDmlToolsCreateRecordEnabled = runtimeMcpDmlToolsCreateRecordEnabled;
RuntimeMcpDmlToolsReadRecordsEnabled = runtimeMcpDmlToolsReadRecordsEnabled;
RuntimeMcpDmlToolsUpdateRecordEnabled = runtimeMcpDmlToolsUpdateRecordEnabled;
RuntimeMcpDmlToolsDeleteRecordEnabled = runtimeMcpDmlToolsDeleteRecordEnabled;
RuntimeMcpDmlToolsExecuteEntityEnabled = runtimeMcpDmlToolsExecuteEntityEnabled;
RuntimeMcpDmlToolsAggregateRecordsEnabled = runtimeMcpDmlToolsAggregateRecordsEnabled;
RuntimeMcpDmlToolsAggregateRecordsQueryTimeout = runtimeMcpDmlToolsAggregateRecordsQueryTimeout;
// Cache
RuntimeCacheEnabled = runtimeCacheEnabled;
RuntimeCacheTTL = runtimeCacheTtl;
// Compression
RuntimeCompressionLevel = runtimeCompressionLevel;
// Host
RuntimeHostMode = runtimeHostMode;
RuntimeHostCorsOrigins = runtimeHostCorsOrigins;
RuntimeHostCorsAllowCredentials = runtimeHostCorsAllowCredentials;
RuntimeHostAuthenticationProvider = runtimeHostAuthenticationProvider;
RuntimeHostAuthenticationJwtAudience = runtimeHostAuthenticationJwtAudience;
RuntimeHostAuthenticationJwtIssuer = runtimeHostAuthenticationJwtIssuer;
// Azure Key Vault
AzureKeyVaultEndpoint = azureKeyVaultEndpoint;
AzureKeyVaultRetryPolicyMode = azureKeyVaultRetryPolicyMode;
AzureKeyVaultRetryPolicyMaxCount = azureKeyVaultRetryPolicyMaxCount;
AzureKeyVaultRetryPolicyDelaySeconds = azureKeyVaultRetryPolicyDelaySeconds;
AzureKeyVaultRetryPolicyMaxDelaySeconds = azureKeyVaultRetryPolicyMaxDelaySeconds;
AzureKeyVaultRetryPolicyNetworkTimeoutSeconds = azureKeyVaultRetryPolicyNetworkTimeoutSeconds;
// Azure Log Analytics
AzureLogAnalyticsEnabled = azureLogAnalyticsEnabled;
AzureLogAnalyticsDabIdentifier = azureLogAnalyticsDabIdentifier;
AzureLogAnalyticsFlushIntervalSeconds = azureLogAnalyticsFlushIntervalSeconds;
AzureLogAnalyticsCustomTableName = azureLogAnalyticsCustomTableName;
AzureLogAnalyticsDcrImmutableId = azureLogAnalyticsDcrImmutableId;
AzureLogAnalyticsDceEndpoint = azureLogAnalyticsDceEndpoint;
// File
FileSinkEnabled = fileSinkEnabled;
FileSinkPath = fileSinkPath;
FileSinkRollingInterval = fileSinkRollingInterval;
FileSinkRetainedFileCountLimit = fileSinkRetainedFileCountLimit;
FileSinkFileSizeLimitBytes = fileSinkFileSizeLimitBytes;
ShowEffectivePermissions = showEffectivePermissions;
}
[Option("data-source.database-type", Required = false, HelpText = "Database type. Allowed values: mssql, postgresql, cosmosdb_nosql, cosmosdb_postgresql, mysql.")]
public string? DataSourceDatabaseType { get; }
[Option("data-source.connection-string", Required = false, HelpText = "Connection string for the data source.")]
public string? DataSourceConnectionString { get; }
[Option("data-source.options.database", Required = false, HelpText = "Database name for Cosmos DB for NoSql.")]
public string? DataSourceOptionsDatabase { get; }
[Option("data-source.options.container", Required = false, HelpText = "Container name for Cosmos DB for NoSql.")]
public string? DataSourceOptionsContainer { get; }
[Option("data-source.options.schema", Required = false, HelpText = "Schema path for Cosmos DB for NoSql.")]
public string? DataSourceOptionsSchema { get; }
[Option("data-source.options.set-session-context", Required = false, HelpText = "Enable session context. Allowed values: true, false.")]
public bool? DataSourceOptionsSetSessionContext { get; }
[Option("data-source.health.name", Required = false, HelpText = "Identifier for data source in health check report.")]
public string? DataSourceHealthName { get; }
[Option("data-source.user-delegated-auth.enabled", Required = false, HelpText = "Enable user-delegated authentication (OBO) for Azure SQL and SQL Server. Default: false (boolean).")]
public bool? DataSourceUserDelegatedAuthEnabled { get; }
[Option("data-source.user-delegated-auth.database-audience", Required = false, HelpText = "Database resource identifier for token acquisition (e.g., https://database.windows.net for Azure SQL).")]
public string? DataSourceUserDelegatedAuthDatabaseAudience { get; }
[Option("runtime.graphql.depth-limit", Required = false, HelpText = "Max allowed depth of a nested query. Allowed values: (0,2147483647] inclusive. Default: null (no limit). Use -1 to remove limit.")]
public int? DepthLimit { get; }
[Option("runtime.graphql.enabled", Required = false, HelpText = "Enable DAB's GraphQL endpoint. Default: true (boolean).")]
public bool? RuntimeGraphQLEnabled { get; }
[Option("runtime.graphql.path", Required = false, HelpText = "Customize DAB's GraphQL endpoint path. Allowed values: string. Conditions: Prefix with '/', no spaces and no reserved characters.")]
public string? RuntimeGraphQLPath { get; }
[Option("runtime.graphql.allow-introspection", Required = false, HelpText = "Allow/Deny GraphQL introspection requests in GraphQL Schema. Default: true (boolean).")]
public bool? RuntimeGraphQLAllowIntrospection { get; }
[Option("runtime.graphql.multiple-mutations.create.enabled", Required = false, HelpText = "Enable/Disable multiple-mutation create operations on DAB's generated GraphQL schema. Default: false (boolean).")]
public bool? RuntimeGraphQLMultipleMutationsCreateEnabled { get; }
[Option("runtime.rest.enabled", Required = false, HelpText = "Enable DAB's Rest endpoint. Default: true (boolean).")]
public bool? RuntimeRestEnabled { get; }
[Option("runtime.rest.path", Required = false, HelpText = "Customize DAB's REST endpoint path. Default: '/api' Conditions: Prefix path with '/'.")]
public string? RuntimeRestPath { get; }
[Option("runtime.rest.request-body-strict", Required = false, HelpText = "Prohibit extraneous REST request body fields. Default: true (boolean).")]
public bool? RuntimeRestRequestBodyStrict { get; }
[Option("runtime.mcp.enabled", Required = false, HelpText = "Enable DAB's MCP endpoint. Default: true (boolean).")]
public bool? RuntimeMcpEnabled { get; }
[Option("runtime.mcp.path", Required = false, HelpText = "Customize DAB's MCP endpoint path. Default: '/mcp' Conditions: Prefix path with '/'.")]
public string? RuntimeMcpPath { get; }
[Option("runtime.mcp.description", Required = false, HelpText = "Set the MCP server description to be exposed in the initialize response.")]
public string? RuntimeMcpDescription { get; }
[Option("runtime.mcp.dml-tools.enabled", Required = false, HelpText = "Enable DAB's MCP DML tools endpoint. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsEnabled { get; }
[Option("runtime.mcp.dml-tools.describe-entities.enabled", Required = false, HelpText = "Enable DAB's MCP describe entities tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsDescribeEntitiesEnabled { get; }
[Option("runtime.mcp.dml-tools.create-record.enabled", Required = false, HelpText = "Enable DAB's MCP create record tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsCreateRecordEnabled { get; }
[Option("runtime.mcp.dml-tools.read-records.enabled", Required = false, HelpText = "Enable DAB's MCP read record tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsReadRecordsEnabled { get; }
[Option("runtime.mcp.dml-tools.update-record.enabled", Required = false, HelpText = "Enable DAB's MCP update record tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsUpdateRecordEnabled { get; }
[Option("runtime.mcp.dml-tools.delete-record.enabled", Required = false, HelpText = "Enable DAB's MCP delete record tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsDeleteRecordEnabled { get; }
[Option("runtime.mcp.dml-tools.execute-entity.enabled", Required = false, HelpText = "Enable DAB's MCP execute entity tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsExecuteEntityEnabled { get; }
[Option("runtime.mcp.dml-tools.aggregate-records.enabled", Required = false, HelpText = "Enable DAB's MCP aggregate records tool. Default: true (boolean).")]
public bool? RuntimeMcpDmlToolsAggregateRecordsEnabled { get; }
[Option("runtime.mcp.dml-tools.aggregate-records.query-timeout", Required = false, HelpText = "Set the execution timeout in seconds for the aggregate-records MCP tool. Default: 30 (integer). Range: 1-600.")]
public int? RuntimeMcpDmlToolsAggregateRecordsQueryTimeout { get; }
[Option("runtime.cache.enabled", Required = false, HelpText = "Enable DAB's cache globally. (You must also enable each entity's cache separately.). Default: false (boolean).")]
public bool? RuntimeCacheEnabled { get; }
[Option("runtime.cache.ttl-seconds", Required = false, HelpText = "Customize the DAB cache's global default time to live in seconds. Default: 5 seconds (Integer).")]
public int? RuntimeCacheTTL { get; }
[Option("runtime.compression.level", Required = false, HelpText = "Set the response compression level. Allowed values: optimal (default), fastest, none.")]
public CompressionLevel? RuntimeCompressionLevel { get; }
[Option("runtime.host.mode", Required = false, HelpText = "Set the host running mode of DAB in Development or Production. Default: production.")]
public HostMode? RuntimeHostMode { get; }
[Option("runtime.host.cors.origins", Required = false, HelpText = "Overwrite Allowed Origins in CORS. Default: [] (Space separated array of strings).")]
public IEnumerable<string>? RuntimeHostCorsOrigins { get; }
[Option("runtime.host.cors.allow-credentials", Required = false, HelpText = "Set value for Access-Control-Allow-Credentials header in Host.Cors. Default: false (boolean).")]
public bool? RuntimeHostCorsAllowCredentials { get; }
[Option("runtime.host.authentication.provider", Required = false, HelpText = "Configure the name of authentication provider. Default: Unauthenticated.")]
public string? RuntimeHostAuthenticationProvider { get; }
[Option("runtime.host.authentication.jwt.audience", Required = false, HelpText = "Configure the intended recipient(s) of the Jwt Token.")]
public string? RuntimeHostAuthenticationJwtAudience { get; }
[Option("runtime.host.authentication.jwt.issuer", Required = false, HelpText = "Configure the entity that issued the Jwt Token.")]
public string? RuntimeHostAuthenticationJwtIssuer { get; }
[Option("azure-key-vault.endpoint", Required = false, HelpText = "Configure the Azure Key Vault endpoint URL.")]
public string? AzureKeyVaultEndpoint { get; }
[Option("azure-key-vault.retry-policy.mode", Required = false, HelpText = "Configure the retry policy mode. Allowed values: fixed, exponential. Default: exponential.")]
public AKVRetryPolicyMode? AzureKeyVaultRetryPolicyMode { get; }
[Option("azure-key-vault.retry-policy.max-count", Required = false, HelpText = "Configure the maximum number of retry attempts. Default: 3.")]
public int? AzureKeyVaultRetryPolicyMaxCount { get; }
[Option("azure-key-vault.retry-policy.delay-seconds", Required = false, HelpText = "Configure the initial delay between retries in seconds. Default: 1.")]
public int? AzureKeyVaultRetryPolicyDelaySeconds { get; }
[Option("azure-key-vault.retry-policy.max-delay-seconds", Required = false, HelpText = "Configure the maximum delay between retries in seconds (for exponential mode). Default: 60.")]
public int? AzureKeyVaultRetryPolicyMaxDelaySeconds { get; }
[Option("azure-key-vault.retry-policy.network-timeout-seconds", Required = false, HelpText = "Configure the network timeout for requests in seconds. Default: 60.")]
public int? AzureKeyVaultRetryPolicyNetworkTimeoutSeconds { get; }
[Option("runtime.telemetry.azure-log-analytics.enabled", Required = false, HelpText = "Enable/Disable Azure Log Analytics. Default: False (boolean)")]
public CliBool? AzureLogAnalyticsEnabled { get; }
[Option("runtime.telemetry.azure-log-analytics.dab-identifier", Required = false, HelpText = "Configure DAB Identifier to allow user to differentiate which logs come from DAB in Azure Log Analytics . Default: DABLogs")]
public string? AzureLogAnalyticsDabIdentifier { get; }
[Option("runtime.telemetry.azure-log-analytics.flush-interval-seconds", Required = false, HelpText = "Configure Flush Interval in seconds for Azure Log Analytics to specify the time interval to send the telemetry data. Default: 5")]
public int? AzureLogAnalyticsFlushIntervalSeconds { get; }
[Option("runtime.telemetry.azure-log-analytics.auth.custom-table-name", Required = false, HelpText = "Configure Custom Table Name for Azure Log Analytics used to find table to connect")]
public string? AzureLogAnalyticsCustomTableName { get; }
[Option("runtime.telemetry.azure-log-analytics.auth.dcr-immutable-id", Required = false, HelpText = "Configure DCR Immutable ID for Azure Log Analytics to find the data collection rule that defines how data is collected")]
public string? AzureLogAnalyticsDcrImmutableId { get; }
[Option("runtime.telemetry.azure-log-analytics.auth.dce-endpoint", Required = false, HelpText = "Configure DCE Endpoint for Azure Log Analytics to find table to send telemetry data")]
public string? AzureLogAnalyticsDceEndpoint { get; }
[Option("runtime.telemetry.file.enabled", Required = false, HelpText = "Enable/Disable File Sink logging. Default: False (boolean)")]
public CliBool? FileSinkEnabled { get; }
[Option("runtime.telemetry.file.path", Required = false, HelpText = "Configure path for File Sink logging. Default: /logs/dab-log.txt")]
public string? FileSinkPath { get; }
[Option("runtime.telemetry.file.rolling-interval", Required = false, HelpText = "Configure rolling interval for File Sink logging. Default: Day")]
public RollingInterval? FileSinkRollingInterval { get; }
[Option("runtime.telemetry.file.retained-file-count-limit", Required = false, HelpText = "Configure maximum number of retained files. Default: 1")]
public int? FileSinkRetainedFileCountLimit { get; }
[Option("runtime.telemetry.file.file-size-limit-bytes", Required = false, HelpText = "Configure maximum file size limit in bytes. Default: 1048576")]
public long? FileSinkFileSizeLimitBytes { get; }
[Option("show-effective-permissions", Required = false, HelpText = "Display effective permissions for all entities, including inherited permissions. Entities are listed in alphabetical order.")]
public bool ShowEffectivePermissions { get; }
public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem)
{
logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion());
if (ShowEffectivePermissions)
{
bool isSuccess = ConfigGenerator.TryShowEffectivePermissions(this, loader, fileSystem);
if (!isSuccess)
{
logger.LogError("Failed to display effective permissions.");
return CliReturnCode.GENERAL_ERROR;
}
return CliReturnCode.SUCCESS;
}
bool configSuccess = ConfigGenerator.TryConfigureSettings(this, loader, fileSystem);
if (configSuccess)
{
logger.LogInformation("Successfully updated runtime settings in the config file.");
return CliReturnCode.SUCCESS;
}
else
{
logger.LogError("Failed to update runtime settings in the config file.");
return CliReturnCode.GENERAL_ERROR;
}
}
}
}