-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathAccountListCommand.cs
More file actions
77 lines (66 loc) · 2.77 KB
/
Copy pathAccountListCommand.cs
File metadata and controls
77 lines (66 loc) · 2.77 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Azure.Mcp.Core.Commands.Subscription;
using Azure.Mcp.Tools.AppConfig.Models;
using Azure.Mcp.Tools.AppConfig.Options.Account;
using Azure.Mcp.Tools.AppConfig.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Models.Command;
using Microsoft.Mcp.Core.Models.Option;
namespace Azure.Mcp.Tools.AppConfig.Commands.Account;
[CommandMetadata(
Id = "e403c988-b57b-4ac1-afb7-25ba3fdd6e6a",
Name = "list",
Title = "List App Configuration Stores",
Description = """
List all App Configuration stores in a subscription. Results include store names returned as a JSON array.
""",
Destructive = false,
Idempotent = true,
OpenWorld = false,
ReadOnly = true,
Secret = false,
LocalRequired = false)]
public sealed class AccountListCommand(ILogger<AccountListCommand> logger, IAppConfigService appConfigService) : SubscriptionCommand<AccountListOptions>()
{
private readonly ILogger<AccountListCommand> _logger = logger;
private readonly IAppConfigService _appConfigService = appConfigService;
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(OptionDefinitions.Common.ResourceGroup.AsOptional());
}
protected override AccountListOptions BindOptions(ParseResult parseResult)
{
var options = base.BindOptions(parseResult);
options.ResourceGroup = parseResult.GetValueOrDefault<string>(OptionDefinitions.Common.ResourceGroup.Name);
return options;
}
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult, CancellationToken cancellationToken)
{
if (!Validate(parseResult.CommandResult, context.Response).IsValid)
{
return context.Response;
}
var options = BindOptions(parseResult);
try
{
var accounts = await _appConfigService.GetAppConfigAccounts(
options.Subscription!,
options.ResourceGroup,
options.Tenant,
options.RetryPolicy,
cancellationToken);
context.Response.Results = ResponseResult.Create(new(accounts?.Results ?? [], accounts?.AreResultsTruncated ?? false), AppConfigJsonContext.Default.AccountListCommandResult);
}
catch (Exception ex)
{
_logger.LogError(ex, "An exception occurred listing accounts.");
HandleException(context, ex);
}
return context.Response;
}
internal record AccountListCommandResult(List<AppConfigurationAccount> Accounts, bool AreResultsTruncated);
}