-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathAutoConfigOptions.cs
More file actions
104 lines (89 loc) · 5.23 KB
/
AutoConfigOptions.cs
File metadata and controls
104 lines (89 loc) · 5.23 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.IO.Abstractions;
using Azure.DataApiBuilder.Config;
using Azure.DataApiBuilder.Product;
using Cli.Constants;
using CommandLine;
using Microsoft.Extensions.Logging;
using static Cli.Utils;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Cli.Commands
{
/// <summary>
/// AutoConfigOptions command options
/// This command will be used to configure autoentities definitions in the config file.
/// </summary>
[Verb("auto-config", isDefault: false, HelpText = "Configure autoentities definitions", Hidden = false)]
public class AutoConfigOptions : Options
{
public AutoConfigOptions(
string definitionName,
IEnumerable<string>? patternsInclude = null,
IEnumerable<string>? patternsExclude = null,
string? patternsName = null,
string? templateMcpDmlTools = null,
bool? templateRestEnabled = null,
bool? templateGraphqlEnabled = null,
bool? templateCacheEnabled = null,
int? templateCacheTtlSeconds = null,
string? templateCacheLevel = null,
bool? templateHealthEnabled = null,
IEnumerable<string>? permissions = null,
string? config = null)
: base(config)
{
DefinitionName = definitionName;
PatternsInclude = patternsInclude;
PatternsExclude = patternsExclude;
PatternsName = patternsName;
TemplateMcpDmlTools = templateMcpDmlTools;
TemplateRestEnabled = templateRestEnabled;
TemplateGraphqlEnabled = templateGraphqlEnabled;
TemplateCacheEnabled = templateCacheEnabled;
TemplateCacheTtlSeconds = templateCacheTtlSeconds;
TemplateCacheLevel = templateCacheLevel;
TemplateHealthEnabled = templateHealthEnabled;
Permissions = permissions;
}
[Value(0, Required = true, HelpText = "Name of the autoentities definition to configure.")]
public string DefinitionName { get; }
[Option("patterns.include", Required = false, HelpText = "T-SQL LIKE pattern(s) to include database objects. Space-separated array of patterns. Default: '%.%'.")]
public IEnumerable<string>? PatternsInclude { get; }
[Option("patterns.exclude", Required = false, HelpText = "T-SQL LIKE pattern(s) to exclude database objects. Space-separated array of patterns. Default: null")]
public IEnumerable<string>? PatternsExclude { get; }
[Option("patterns.name", Required = false, HelpText = "Interpolation syntax for entity naming (must be unique for each generated entity). Default: '{object}'")]
public string? PatternsName { get; }
[Option("template.mcp.dml-tools", Required = false, HelpText = "Enable/disable DML tools for generated entities. Allowed values: true, false. Default: true")]
public string? TemplateMcpDmlTools { get; }
[Option("template.rest.enabled", Required = false, HelpText = "Enable/disable REST endpoint for generated entities. Allowed values: true, false. Default: true")]
public bool? TemplateRestEnabled { get; }
[Option("template.graphql.enabled", Required = false, HelpText = "Enable/disable GraphQL endpoint for generated entities. Allowed values: true, false. Default: true")]
public bool? TemplateGraphqlEnabled { get; }
[Option("template.cache.enabled", Required = false, HelpText = "Enable/disable cache for generated entities. Allowed values: true, false. Default: false")]
public bool? TemplateCacheEnabled { get; }
[Option("template.cache.ttl-seconds", Required = false, HelpText = "Cache time-to-live in seconds for generated entities. Default: null")]
public int? TemplateCacheTtlSeconds { get; }
[Option("template.cache.level", Required = false, HelpText = "Cache level for generated entities. Allowed values: L1, L1L2. Default: L1L2")]
public string? TemplateCacheLevel { get; }
[Option("template.health.enabled", Required = false, HelpText = "Enable/disable health check for generated entities. Allowed values: true, false. Default: true")]
public bool? TemplateHealthEnabled { get; }
[Option("permissions", Required = false, Separator = ':', HelpText = "Permissions for generated entities in the format role:actions (e.g., anonymous:read). Default: null")]
public IEnumerable<string>? Permissions { get; }
public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem)
{
logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion());
bool isSuccess = ConfigGenerator.TryConfigureAutoentities(this, loader, fileSystem);
if (isSuccess)
{
logger.LogInformation("Successfully configured autoentities definition: {DefinitionName}.", DefinitionName);
return CliReturnCode.SUCCESS;
}
else
{
logger.LogError("Failed to configure autoentities definition: {DefinitionName}.", DefinitionName);
return CliReturnCode.GENERAL_ERROR;
}
}
}
}