-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathRegistryRepositoryListCommand.cs
More file actions
80 lines (69 loc) · 2.92 KB
/
Copy pathRegistryRepositoryListCommand.cs
File metadata and controls
80 lines (69 loc) · 2.92 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Azure.Mcp.Tools.Acr.Options;
using Azure.Mcp.Tools.Acr.Options.Registry;
using Azure.Mcp.Tools.Acr.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Extensions;
using Microsoft.Mcp.Core.Models.Command;
namespace Azure.Mcp.Tools.Acr.Commands.Registry;
[CommandMetadata(
Id = "adc6eb20-ad98-4624-954d-61581f6fbca9",
Name = "list",
Title = "List Container Registry Repositories",
Description = """
List repositories in Azure Container Registries. By default, lists repositories for all registries in the subscription.
You can narrow the scope using resource group and/or registry to list repositories for a specific registry only.
""",
Destructive = false,
Idempotent = true,
OpenWorld = false,
ReadOnly = true,
Secret = false,
LocalRequired = false)]
public sealed class RegistryRepositoryListCommand(ILogger<RegistryRepositoryListCommand> logger, IAcrService acrService)
: BaseAcrCommand<RegistryRepositoryListOptions>
{
private readonly ILogger<RegistryRepositoryListCommand> _logger = logger;
private readonly IAcrService _acrService = acrService;
protected override void RegisterOptions(Command command)
{
base.RegisterOptions(command);
command.Options.Add(AcrOptionDefinitions.Registry);
}
protected override RegistryRepositoryListOptions BindOptions(ParseResult parseResult)
{
var options = base.BindOptions(parseResult);
options.Registry ??= parseResult.GetValueOrDefault(AcrOptionDefinitions.Registry);
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 map = await _acrService.ListRegistryRepositories(
options.Subscription!,
options.ResourceGroup,
options.Registry,
options.Tenant,
options.RetryPolicy,
cancellationToken);
context.Response.Results = ResponseResult.Create(new(map ?? []), AcrJsonContext.Default.RegistryRepositoryListCommandResult);
}
catch (Exception ex)
{
_logger.LogError(ex,
"Error listing ACR repositories. Subscription: {Subscription}, ResourceGroup: {ResourceGroup}, Registry: {Registry}",
options.Subscription, options.ResourceGroup, options.Registry);
HandleException(context, ex);
}
return context.Response;
}
internal record RegistryRepositoryListCommandResult(Dictionary<string, List<string>> RepositoriesByRegistry);
}