/// <summary> /// Internal constructor used by KeyVaultDataServiceClient /// </summary> /// <param name="secret">secret returned from service</param> /// <param name="vaultUriHelper">helper class</param> internal Secret(Azure.KeyVault.Secret secret, VaultUriHelper vaultUriHelper) { if (secret == null) throw new ArgumentNullException("secret"); SetObjectIdentifier(vaultUriHelper, secret.SecretIdentifier); if (secret.Value != null) SecretValue = secret.Value.ConvertToSecureString(); Attributes = new SecretAttributes( secret.Attributes.Enabled, secret.Attributes.Expires, secret.Attributes.NotBefore, secret.Attributes.Created, secret.Attributes.Updated, secret.ContentType, secret.Tags); }
public SetKeyVaultSecretTests() { base.SetupTest(); secretAttributes = new SecretAttributes(true, null, null, null, null); secureSecretValue = SecretValue.ConvertToSecureString(); secret = new Secret() { VaultName = VaultName, Name = SecretName, Version = SecretVersion, SecretValue = secureSecretValue, Attributes = secretAttributes }; cmdlet = new SetAzureKeyVaultSecret() { CommandRuntime = commandRuntimeMock.Object, DataServiceClient = keyVaultClientMock.Object, VaultName = secret.VaultName, Name = secret.Name, SecretValue = secret.SecretValue, Disable = new SwitchParameter(!(secretAttributes.Enabled.Value)), Expires = secretAttributes.Expires, NotBefore = secretAttributes.NotBefore, ContentType = secretAttributes.ContentType, Tag = secretAttributes.Tags }; }
public SetKeyVaultSecretAttributeTests() { base.SetupTest(); secretAttributes = new SecretAttributes(true, DateTime.UtcNow.AddYears(2), DateTime.UtcNow, "contenttype", null); secret = new Secret() { VaultName = VaultName, Name = SecretName, Version = SecretVersion, SecretValue = null, Attributes = secretAttributes }; cmdlet = new SetAzureKeyVaultSecretAttribute() { CommandRuntime = commandRuntimeMock.Object, DataServiceClient = keyVaultClientMock.Object, VaultName = secret.VaultName, Name = secret.Name, Version = secret.Version, Enable = secretAttributes.Enabled, Expires = secretAttributes.Expires, NotBefore = secretAttributes.NotBefore, ContentType = secretAttributes.ContentType, Tags = secretAttributes.Tags, PassThru = true }; }
/// <summary> /// Internal constructor used by KeyVaultDataServiceClient /// </summary> /// <param name="secret">secret returned from service</param> /// <param name="vaultUriHelper">helper class</param> internal Secret(Azure.KeyVault.Secret secret, VaultUriHelper vaultUriHelper) { if (secret == null) { throw new ArgumentNullException("secret"); } SetObjectIdentifier(vaultUriHelper, secret.SecretIdentifier); if (secret.Value != null) { SecretValue = secret.Value.ConvertToSecureString(); } Attributes = new SecretAttributes( secret.Attributes.Enabled, secret.Attributes.Expires, secret.Attributes.NotBefore, secret.Attributes.Created, secret.Attributes.Updated, secret.ContentType, secret.Tags); }
public Secret UpdateSecret(string vaultName, string secretName, string secretVersion, SecretAttributes secretAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(secretName)) { throw new ArgumentNullException("secretName"); } if (secretAttributes == null) { throw new ArgumentNullException("secretAttributes"); } var secretIdentifier = new SecretIdentifier(this.vaultUriHelper.CreateVaultAddress(vaultName), secretName, secretVersion); Azure.KeyVault.Models.SecretAttributes attributes = (Azure.KeyVault.Models.SecretAttributes)secretAttributes; SecretBundle secret; try { secret = this.keyVaultClient.UpdateSecretAsync(secretIdentifier.Identifier, secretAttributes.ContentType, attributes, secretAttributes.TagsDictionary).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new Secret(secret, this.vaultUriHelper)); }
public Secret SetSecret(string vaultName, string secretName, SecureString secretValue, SecretAttributes secretAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(secretName)) { throw new ArgumentNullException("secretName"); } if (secretValue == null) { throw new ArgumentNullException("secretValue"); } if (secretAttributes == null) { throw new ArgumentNullException("secretAttributes"); } string value = secretValue.ConvertToString(); string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); var attributes = (Azure.KeyVault.Models.SecretAttributes)secretAttributes; Azure.KeyVault.Models.SecretBundle secret; try { secret = this.keyVaultClient.SetSecretAsync(vaultAddress, secretName, value, secretAttributes.TagsDictionary, secretAttributes.ContentType, attributes).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new Secret(secret, this.vaultUriHelper)); }