-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathInitOptions.cs
More file actions
165 lines (138 loc) · 8.21 KB
/
InitOptions.cs
File metadata and controls
165 lines (138 loc) · 8.21 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
// 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 static Cli.Utils;
namespace Cli.Commands
{
/// <summary>
/// Init command options
/// </summary>
[Verb("init", isDefault: false, HelpText = "Initialize configuration file.", Hidden = false)]
public class InitOptions : Options
{
public InitOptions(
DatabaseType databaseType,
string? connectionString,
string? cosmosNoSqlDatabase,
string? cosmosNoSqlContainer,
string? graphQLSchemaPath,
bool setSessionContext,
HostMode hostMode,
IEnumerable<string>? corsOrigin,
string authenticationProvider,
string? audience = null,
string? issuer = null,
string restPath = RestRuntimeOptions.DEFAULT_PATH,
string? runtimeBaseRoute = null,
bool restDisabled = false,
string graphQLPath = GraphQLRuntimeOptions.DEFAULT_PATH,
bool graphqlDisabled = false,
string mcpPath = McpRuntimeOptions.DEFAULT_PATH,
bool mcpDisabled = false,
CliBool restEnabled = CliBool.None,
CliBool graphqlEnabled = CliBool.None,
CliBool mcpEnabled = CliBool.None,
CliBool restRequestBodyStrict = CliBool.None,
CliBool multipleCreateOperationEnabled = CliBool.None,
int? mcpAggregateRecordsQueryTimeout = null,
string? config = null)
: base(config)
{
DatabaseType = databaseType;
ConnectionString = connectionString;
CosmosNoSqlDatabase = cosmosNoSqlDatabase;
CosmosNoSqlContainer = cosmosNoSqlContainer;
GraphQLSchemaPath = graphQLSchemaPath;
SetSessionContext = setSessionContext;
HostMode = hostMode;
CorsOrigin = corsOrigin;
AuthenticationProvider = authenticationProvider;
Audience = audience;
Issuer = issuer;
RestPath = restPath;
RuntimeBaseRoute = runtimeBaseRoute;
RestDisabled = restDisabled;
GraphQLPath = graphQLPath;
GraphQLDisabled = graphqlDisabled;
McpPath = mcpPath;
McpDisabled = mcpDisabled;
RestEnabled = restEnabled;
GraphQLEnabled = graphqlEnabled;
McpEnabled = mcpEnabled;
RestRequestBodyStrict = restRequestBodyStrict;
MultipleCreateOperationEnabled = multipleCreateOperationEnabled;
McpAggregateRecordsQueryTimeout = mcpAggregateRecordsQueryTimeout;
}
[Option("database-type", Required = true, HelpText = "Type of database to connect. Supported values: mssql, cosmosdb_nosql, cosmosdb_postgresql, mysql, postgresql")]
public DatabaseType DatabaseType { get; }
[Option("connection-string", Required = false, HelpText = "(Default: '') Connection details to connect to the database.")]
public string? ConnectionString { get; }
[Option("cosmosdb_nosql-database", Required = false, HelpText = "Database name for Azure Cosmos DB for NoSql.")]
public string? CosmosNoSqlDatabase { get; }
[Option("cosmosdb_nosql-container", Required = false, HelpText = "Container name for Azure Cosmos DB for NoSql.")]
public string? CosmosNoSqlContainer { get; }
[Option("graphql-schema", Required = false, HelpText = "GraphQL schema Path.")]
public string? GraphQLSchemaPath { get; }
[Option("set-session-context", Default = false, Required = false, HelpText = "Enable sending data to MsSql using session context.")]
public bool SetSessionContext { get; }
[Option("host-mode", Default = HostMode.Production, Required = false, HelpText = "Specify the Host mode - Development or Production")]
public HostMode HostMode { get; }
[Option("cors-origin", Separator = ',', Required = false, HelpText = "Specify the list of allowed origins.")]
public IEnumerable<string>? CorsOrigin { get; }
[Option("auth.provider", Default = "Unauthenticated", Required = false, HelpText = "Specify the Identity Provider.")]
public string AuthenticationProvider { get; }
[Option("auth.audience", Required = false, HelpText = "Identifies the recipients that the JWT is intended for.")]
public string? Audience { get; }
[Option("auth.issuer", Required = false, HelpText = "Specify the party that issued the jwt token.")]
public string? Issuer { get; }
[Option("rest.path", Default = RestRuntimeOptions.DEFAULT_PATH, Required = false, HelpText = "Specify the REST endpoint's default prefix.")]
public string RestPath { get; }
[Option("runtime.base-route", Default = null, Required = false, HelpText = "Specifies the base route for API requests.")]
public string? RuntimeBaseRoute { get; }
[Option("rest.disabled", Default = false, Required = false, HelpText = "Disables REST endpoint for all entities.")]
public bool RestDisabled { get; }
[Option("graphql.path", Default = GraphQLRuntimeOptions.DEFAULT_PATH, Required = false, HelpText = "Specify the GraphQL endpoint's default prefix.")]
public string GraphQLPath { get; }
[Option("graphql.disabled", Default = false, Required = false, HelpText = "Disables GraphQL endpoint for all entities.")]
public bool GraphQLDisabled { get; }
[Option("mcp.path", Default = McpRuntimeOptions.DEFAULT_PATH, Required = false, HelpText = "Specify the MCP endpoint's default prefix.")]
public string McpPath { get; }
[Option("mcp.disabled", Default = false, Required = false, HelpText = "Disables MCP endpoint for all entities.")]
public bool McpDisabled { get; }
[Option("rest.enabled", Required = false, HelpText = "(Default: true) Enables REST endpoint for all entities. Supported values: true, false.")]
public CliBool RestEnabled { get; }
[Option("graphql.enabled", Required = false, HelpText = "(Default: true) Enables GraphQL endpoint for all entities. Supported values: true, false.")]
public CliBool GraphQLEnabled { get; }
[Option("mcp.enabled", Required = false, HelpText = "(Default: true) Enables MCP endpoint for all entities. Supported values: true, false.")]
public CliBool McpEnabled { get; }
// When true, DAB rejects extraneous/unmapped fields in the REST request body (strict mode). When false, extraneous fields are allowed and ignored.
[Option("rest.request-body-strict", Required = false, HelpText = "(Default: true) When true, rejects extraneous/unmapped fields in the REST request body. When false, allows and ignores them.")]
public CliBool RestRequestBodyStrict { get; }
[Option("graphql.multiple-create.enabled", Required = false, HelpText = "(Default: false) Enables multiple create operation for GraphQL. Supported values: true, false.")]
public CliBool MultipleCreateOperationEnabled { get; }
[Option("mcp.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? McpAggregateRecordsQueryTimeout { get; }
public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem)
{
logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion());
bool isSuccess = ConfigGenerator.TryGenerateConfig(this, loader, fileSystem);
if (isSuccess)
{
logger.LogInformation("Config file generated.");
logger.LogInformation("SUGGESTION: Use 'dab add [entity-name] [options]' to add new entities in your config.");
return CliReturnCode.SUCCESS;
}
else
{
logger.LogError("Could not generate config file.");
return CliReturnCode.GENERAL_ERROR;
}
}
}
}