-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathCollaborationCreateCommand.cs
More file actions
101 lines (92 loc) · 4.35 KB
/
Copy pathCollaborationCreateCommand.cs
File metadata and controls
101 lines (92 loc) · 4.35 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Net;
using Azure.Mcp.Core.Commands.Subscription;
using Azure.Mcp.Core.Services.Azure.Subscription;
using Azure.Mcp.Tools.ManagedCleanroom.Options.Collaboration;
using Azure.Mcp.Tools.ManagedCleanroom.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Mcp.Core.Commands;
using Microsoft.Mcp.Core.Models.Command;
namespace Azure.Mcp.Tools.ManagedCleanroom.Commands.Collaboration;
[CommandMetadata(
Id = "e247b9e0-2d87-43a7-8e5d-57eea22237a3",
Name = "create",
Title = "Create Cleanroom Collaboration",
Description = """
Creates an Azure Cleanroom collaboration ARM resource in the specified resource group and location.
Polls provisioningState every 30 seconds until the resource reaches a terminal state (expected ~25 minutes).
Returns the final ARM resource properties and a summary message with the outcome and elapsed time.
Required options:
- --name: unique collaboration name within the resource group
- --location: Azure region for the ARM resource (e.g., 'eastus')
- --resource-group: resource group to create the collaboration in
- --subscription: Azure subscription
""",
Destructive = false,
Idempotent = true,
OpenWorld = false,
ReadOnly = false,
Secret = false,
LocalRequired = false)]
public sealed class CollaborationCreateCommand(
ILogger<CollaborationCreateCommand> logger,
IManagedCleanroomService service,
ISubscriptionResolver subscriptionResolver)
: SubscriptionCommand<CollaborationCreateOptions, CollaborationCreateCommand.CollaborationCreateCommandResult>(subscriptionResolver)
{
private readonly ILogger<CollaborationCreateCommand> _logger = logger;
private readonly IManagedCleanroomService _service = service;
public override async Task<CommandResponse> ExecuteAsync(
CommandContext context, CollaborationCreateOptions options, CancellationToken cancellationToken)
{
try
{
var result = await _service.CreateCollaborationArmResourceAsync(
options.Name,
options.ResourceGroup,
options.Subscription!,
options.Location,
options.ResourceLocation,
options.Collaborators,
options.Tenant,
options.RetryPolicy,
cancellationToken).ConfigureAwait(false);
context.Response.Message = result.Message;
context.Response.Results = ResponseResult.Create(
result.Properties,
ManagedCleanroomJsonContext.Default.JsonElement);
}
catch (Exception ex)
{
_logger.LogError(ex,
"Error creating cleanroom collaboration. Name: {Name}, ResourceGroup: {ResourceGroup}, Subscription: {Subscription}",
options.Name, options.ResourceGroup, options.Subscription);
HandleException(context, ex);
}
return context.Response;
}
protected override string GetErrorMessage(Exception ex) => ex switch
{
RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.Conflict =>
"A collaboration with this name already exists in the resource group.",
RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.Forbidden =>
$"Authorization failed creating the collaboration. Details: {reqEx.Message}",
RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.NotFound =>
"Resource group not found. Verify the resource group exists and you have access.",
RequestFailedException reqEx => reqEx.Message,
_ => base.GetErrorMessage(ex)
};
protected override HttpStatusCode GetStatusCode(Exception ex) => ex switch
{
RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.Conflict =>
HttpStatusCode.Conflict,
RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.Forbidden =>
HttpStatusCode.Forbidden,
RequestFailedException reqEx when reqEx.Status == (int)HttpStatusCode.NotFound =>
HttpStatusCode.NotFound,
RequestFailedException reqEx => (HttpStatusCode)reqEx.Status,
_ => base.GetStatusCode(ex)
};
public record CollaborationCreateCommandResult;
}