public async Task <Response <EncryptionScope> > PutAsync(string resourceGroupName, string accountName, string encryptionScopeName, EncryptionScope encryptionScope, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (accountName == null) { throw new ArgumentNullException(nameof(accountName)); } if (encryptionScopeName == null) { throw new ArgumentNullException(nameof(encryptionScopeName)); } if (encryptionScope == null) { throw new ArgumentNullException(nameof(encryptionScope)); } using var message = CreatePutRequest(resourceGroupName, accountName, encryptionScopeName, encryptionScope); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: { EncryptionScope value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = EncryptionScope.DeserializeEncryptionScope(document.RootElement); return(Response.FromValue(value, message.Response)); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (ShouldProcess(this.EncryptionScopeName, "Update Encryption scope")) { switch (ParameterSetName) { case AccountObjectParameterSet: case AccountObjectKeyVaultParameterSet: this.ResourceGroupName = StorageAccount.ResourceGroupName; this.StorageAccountName = StorageAccount.StorageAccountName; break; case EncryptionScopeObjectParameterSet: case EncryptionScopeObjectKeyVaultParameterSet: this.ResourceGroupName = InputObject.ResourceGroupName; this.StorageAccountName = InputObject.StorageAccountName; this.EncryptionScopeName = InputObject.Name; break; default: // For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly break; } EncryptionScope scope = new EncryptionScope(); if (this.KeyvaultEncryption.IsPresent) { scope.Source = EncryptionScopeSource.MicrosoftKeyVault; scope.KeyVaultProperties = new EncryptionScopeKeyVaultProperties(this.KeyUri); } if (this.StorageEncryption.IsPresent) { scope.Source = EncryptionScopeSource.MicrosoftStorage; } if (this.State != null) { if (this.State.Equals(EncryptionScopeState.Enabled, StringComparison.CurrentCultureIgnoreCase)) { scope.State = EncryptionScopeState.Enabled; } if (this.State.Equals(EncryptionScopeState.Disabled, StringComparison.CurrentCultureIgnoreCase)) { scope.State = EncryptionScopeState.Disabled; } } scope = this.StorageClient.EncryptionScopes.Patch( this.ResourceGroupName, this.StorageAccountName, this.EncryptionScopeName, scope); WriteObject(new PSEncryptionScope(scope)); } }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (ShouldProcess(this.EncryptionScopeName, "Create Encryption scope")) { switch (ParameterSetName) { case AccountObjectParameterSet: case AccountObjectKeyVaultParameterSet: this.ResourceGroupName = StorageAccount.ResourceGroupName; this.StorageAccountName = StorageAccount.StorageAccountName; break; default: // For AccountNameParameterSet, the ResourceGroupName and StorageAccountName can get from input directly break; } EncryptionScope scope = new EncryptionScope(); if (this.KeyvaultEncryption.IsPresent) { scope.Source = EncryptionScopeSource.MicrosoftKeyVault; scope.KeyVaultProperties = new EncryptionScopeKeyVaultProperties(this.KeyUri); } else { scope.Source = EncryptionScopeSource.MicrosoftStorage; } if (this.RequireInfrastructureEncryption.IsPresent) { scope.RequireInfrastructureEncryption = true; } scope = this.StorageClient.EncryptionScopes.Put( this.ResourceGroupName, this.StorageAccountName, this.EncryptionScopeName, scope); WriteObject(new PSEncryptionScope(scope)); } }
public async Task CreateUpdateGetEncryptionScope() { //create resource group and storage account string accountName = await CreateValidAccountNameAsync(namePrefix); _resourceGroup = await CreateResourceGroupAsync(); StorageAccountContainer storageAccountContainer = _resourceGroup.GetStorageAccounts(); StorageAccountCreateParameters parameters = GetDefaultStorageAccountParameters(kind: Kind.StorageV2); StorageAccount account = (await storageAccountContainer.CreateOrUpdateAsync(accountName, parameters)).Value; EncryptionScopeContainer encryptionScopeContainer = account.GetEncryptionScopes(); //create encryption scope EncryptionScopeData parameter = new EncryptionScopeData() { Source = EncryptionScopeSource.MicrosoftStorage, State = EncryptionScopeState.Enabled, RequireInfrastructureEncryption = false }; EncryptionScope encryptionScope = (await encryptionScopeContainer.CreateOrUpdateAsync("scope", parameter)).Value; Assert.AreEqual("scope", encryptionScope.Id.Name); Assert.AreEqual(EncryptionScopeState.Enabled, encryptionScope.Data.State); Assert.AreEqual(EncryptionScopeSource.MicrosoftStorage, encryptionScope.Data.Source); //patch encryption scope encryptionScope.Data.State = EncryptionScopeState.Disabled; encryptionScope = await encryptionScope.PatchAsync(encryptionScope.Data); Assert.AreEqual(encryptionScope.Data.State, EncryptionScopeState.Disabled); //get all encryption scopes List <EncryptionScope> encryptionScopes = await encryptionScopeContainer.GetAllAsync().ToEnumerableAsync(); encryptionScope = encryptionScopes.First(); Assert.AreEqual("scope", encryptionScope.Id.Name); Assert.AreEqual(EncryptionScopeState.Disabled, encryptionScope.Data.State); Assert.AreEqual(EncryptionScopeSource.MicrosoftStorage, encryptionScope.Data.Source); }
internal HttpMessage CreatePutRequest(string resourceGroupName, string accountName, string encryptionScopeName, EncryptionScope encryptionScope) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Put; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/resourceGroups/", false); uri.AppendPath(resourceGroupName, true); uri.AppendPath("/providers/Microsoft.Storage/storageAccounts/", false); uri.AppendPath(accountName, true); uri.AppendPath("/encryptionScopes/", false); uri.AppendPath(encryptionScopeName, true); uri.AppendQuery("api-version", apiVersion, true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(encryptionScope); request.Content = content; return(message); }
public virtual async Task <Response <EncryptionScope> > PatchAsync(string resourceGroupName, string accountName, string encryptionScopeName, EncryptionScope encryptionScope, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("EncryptionScopesClient.Patch"); scope.Start(); try { return(await RestClient.PatchAsync(resourceGroupName, accountName, encryptionScopeName, encryptionScope, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <EncryptionScope> Put(string resourceGroupName, string accountName, string encryptionScopeName, EncryptionScope encryptionScope, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("EncryptionScopesClient.Put"); scope.Start(); try { return(RestClient.Put(resourceGroupName, accountName, encryptionScopeName, encryptionScope, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Synchronously creates or updates an encryption scope under the specified /// storage account. If an encryption scope is already created and a subsequent /// request is issued with different properties, the encryption scope /// properties will be updated per the specified request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. The name is /// case insensitive. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and use /// numbers and lower-case letters only. /// </param> /// <param name='encryptionScopeName'> /// The name of the encryption scope within the specified storage account. /// Encryption scope names must be between 3 and 63 characters in length and /// use numbers, lower-case letters and dash (-) only. Every dash (-) character /// must be immediately preceded and followed by a letter or number. /// </param> /// <param name='encryptionScope'> /// Encryption scope properties to be used for the create or update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <EncryptionScope> PutAsync(this IEncryptionScopesOperations operations, string resourceGroupName, string accountName, string encryptionScopeName, EncryptionScope encryptionScope, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PutWithHttpMessagesAsync(resourceGroupName, accountName, encryptionScopeName, encryptionScope, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Synchronously creates or updates an encryption scope under the specified /// storage account. If an encryption scope is already created and a subsequent /// request is issued with different properties, the encryption scope /// properties will be updated per the specified request. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. The name is /// case insensitive. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and use /// numbers and lower-case letters only. /// </param> /// <param name='encryptionScopeName'> /// The name of the encryption scope within the specified storage account. /// Encryption scope names must be between 3 and 63 characters in length and /// use numbers, lower-case letters and dash (-) only. Every dash (-) character /// must be immediately preceded and followed by a letter or number. /// </param> /// <param name='encryptionScope'> /// Encryption scope properties to be used for the create or update. /// </param> public static EncryptionScope Put(this IEncryptionScopesOperations operations, string resourceGroupName, string accountName, string encryptionScopeName, EncryptionScope encryptionScope) { return(operations.PutAsync(resourceGroupName, accountName, encryptionScopeName, encryptionScope).GetAwaiter().GetResult()); }