in src/Commands/AppConfig/KeyValue/KeyValueUnlockCommand.cs [13:63]
public sealed class KeyValueUnlockCommand(ILogger<KeyValueUnlockCommand> logger) : BaseKeyValueCommand<KeyValueUnlockArguments>()
{
private readonly ILogger<KeyValueUnlockCommand> _logger = logger;
protected override string GetCommandName() => "unlock";
protected override string GetCommandDescription() =>
"""
Unlock a key-value setting in an App Configuration store. This command removes the read-only mode from a
key-value setting, allowing modifications to its value. You must specify an account name and key. Optionally,
you can specify a label to unlock a specific labeled version of the setting, otherwise the setting with the
default label will be unlocked.
""";
[McpServerTool(Destructive = false, ReadOnly = false)]
public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult)
{
var args = BindArguments(parseResult);
try
{
if (!await ProcessArguments(context, args))
{
return context.Response;
}
var appConfigService = context.GetService<IAppConfigService>();
await appConfigService.UnlockKeyValue(
args.Account!,
args.Key!,
args.Subscription!,
args.Tenant,
args.RetryPolicy,
args.Label);
context.Response.Results =
ResponseResult.Create(
new KeyValueUnlockResult(args.Key, args.Label),
AppConfigJsonContext.Default.KeyValueUnlockResult);
}
catch (Exception ex)
{
_logger.LogError(ex, "An exception occurred unlocking key. Key: {Key}.", args.Key);
HandleException(context.Response, ex);
}
return context.Response;
}
internal record KeyValueUnlockResult(string? Key, string? Label);
}