Пример #1
0
        public async Task <KeyDescription> RegenerateKeyAsync(
            string requestId,
            string subscriptionId,
            string resourceGroupName,
            string accountName,
            RegenerateKeyParameter parameter)
        {
            await this.ValidateSubscriptionRegistration(subscriptionId);

            var accountKey = new AccountKey
            {
                Name         = parameter.Name,
                IsPrimaryKey = parameter.Rank == KeyRank.PrimaryKey,
                Value        = SASHelper.GenerateKey(DefaultSASKeys.DefaultKeyLength),
            };

            var updated = await this.tenantCacheClient.ResetKeyAsync(
                requestId,
                subscriptionId,
                resourceGroupName,
                accountName,
                accountKey);

            return(new KeyDescription
            {
                Name = updated.Name,
                Rank = updated.IsPrimaryKey ? KeyRank.PrimaryKey : KeyRank.SecondaryKey,
                Value = updated.Value
            });
        }
Пример #2
0
 public async Task <KeyDescription> RegenerateKeyAsync(
     string requestId,
     string subscriptionId,
     string resourceGroupName,
     string accountName,
     RegenerateKeyParameter parameter)
 {
     return(await Task.FromResult(new KeyDescription
     {
         Name = parameter.Name,
         Rank = parameter.Rank,
         Value = "<key value>"
     }));
 }
Пример #3
0
        public async Task <KeyDescription> RegenerateKeyAsync(
            [GlobalParameter("subscriptionId")] string subscriptionId,
            [GlobalParameter("resourceGroupName")] string resourceGroupName,
            [GlobalParameter("accountName")] string accountName,
            [FromBody] RegenerateKeyParameter parameter,
            [GlobalParameter("api-version"), FromQuery("api-version")] string apiVersion)
        {
            if (!this.ModelState.IsValid)
            {
                var error = this.ModelState.Values
                            .SelectMany(s => s.Errors)
                            .FirstOrDefault();

                throw new InvalidArgumentException(error?.Exception?.Message ?? "Invalid model");
            }

            ApiVersionStore.ValidateApiVersion(apiVersion);
            Validator.ArgumentValidGuid(subscriptionId, nameof(subscriptionId));
            Validator.ArgumentNotNullOrrWhiteSpace(resourceGroupName, nameof(resourceGroupName));
            Validator.ArgumentNotNullOrrWhiteSpace(accountName, nameof(accountName));
            Validator.ArgumentNotNullOrrWhiteSpace(parameter.Name, nameof(parameter.Name));

            this.LogActionBegin(
                $"Key name = {parameter.Name}\n" +
                $"Key rank = {parameter.Rank}");

            var result = await this.accountManager.RegenerateKeyAsync(
                this.Request.GetRequestId(),
                subscriptionId,
                resourceGroupName,
                accountName,
                parameter);

            this.LogActionEnd();
            return(result);
        }