Exemplo n.º 1
0
        /// <summary>
        /// Gets a Server Key Vault Key for a server
        /// </summary>
        /// <param name="resourceGroupName">Name of resource group</param>
        /// <param name="serverName">Name of SQL server</param>
        /// <param name="keyId">KeyId of the Server Key Vault Key</param>
        /// <returns>The Server Key Vault Key</returns>
        public AzureSqlServerKeyVaultKeyModel Get(string resourceGroupName, string serverName, string keyId)
        {
            string keyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(keyId);
            var    resp    = Communicator.Get(resourceGroupName, serverName, keyName, Util.GenerateTracingId());

            return(CreateServerKeyModelFromResponse(resourceGroupName, serverName, keyName, resp));
        }
        /// <summary>
        /// Creates or Updates a Server Key Vault Key
        /// </summary>
        /// <param name="model">The Server Key Vault Key model to create</param>
        /// <returns>The updated server key Vault Key model</returns>
        public AzureSqlServerKeyVaultKeyModel CreateOrUpdate(AzureSqlServerKeyVaultKeyModel model)
        {
            var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.ServerKeyName, new ServerKeyCreateOrUpdateParameters()
            {
                Properties = new ServerKeyCreateOrUpdateProperties()
                {
                    ServerKeyType = ServerKeyType.AzureKeyVault,
                    Uri           = model.Uri
                }
            });

            return(CreateServerKeyModelFromResponse(model.ResourceGroupName, model.ServerName, model.ServerKeyName, resp));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs the model to send to the update API
        /// </summary>
        /// <param name="model">The result of the get operation</param>
        /// <returns>The model to send to the update</returns>
        protected override IEnumerable <Model.AzureSqlServerTransparentDataEncryptionProtectorModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlServerTransparentDataEncryptionProtectorModel> model)
        {
            List <Model.AzureSqlServerTransparentDataEncryptionProtectorModel> newEntity = new List <Model.AzureSqlServerTransparentDataEncryptionProtectorModel>();

            newEntity.Add(new Model.AzureSqlServerTransparentDataEncryptionProtectorModel()
            {
                ResourceGroupName = this.ResourceGroupName,
                ServerName        = this.ServerName,
                Type = this.Type,
                ServerKeyVaultKeyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(this.KeyId),
                KeyId = this.KeyId
            });
            return(newEntity);
        }
        /// <summary>
        /// Generates the model from user input.
        /// </summary>
        /// <param name="model">This is null since the model doesn't exist yet</param>
        /// <returns>The generated model from user input</returns>
        protected override IEnumerable <AzureSqlServerKeyVaultKeyModel> ApplyUserInputToModel(IEnumerable <AzureSqlServerKeyVaultKeyModel> model)
        {
            List <AzureSqlServerKeyVaultKeyModel> newEntity = new List <AzureSqlServerKeyVaultKeyModel>();

            newEntity.Add(new AzureSqlServerKeyVaultKeyModel()
            {
                ResourceGroupName = this.ResourceGroupName,
                ServerName        = this.ServerName,
                ServerKeyName     = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(this.KeyId),
                Uri  = this.KeyId,
                Type = AzureSqlServerKeyVaultKeyModel.ServerKeyType.AzureKeyVault
            });

            return(newEntity);
        }
        /// <summary>
        /// Convert a Management.Sql.LegacySdk.Models.ServerKey to AzureSqlServerKeyVaultKeyModel
        /// </summary>
        /// <param name="resourceGroup">The resource group the server is in</param>
        /// <param name="serverName">The name of the server</param>
        /// <param name="resp">The management client server key response to convert</param>
        /// <returns>The converted server key vault key model</returns>
        private static AzureSqlServerKeyVaultKeyModel CreateServerKeyModelFromResponse(string resourceGroup, string serverName, string keyName, Microsoft.Azure.Management.Sql.LegacySdk.Models.ServerKey resp)
        {
            AzureSqlServerKeyVaultKeyModel ServerKey = new AzureSqlServerKeyVaultKeyModel();

            ServerKey.ResourceGroupName = resourceGroup;
            ServerKey.ServerName        = serverName;
            ServerKey.ServerKeyName     = resp.Name;
            AzureSqlServerKeyVaultKeyModel.ServerKeyType type = AzureSqlServerKeyVaultKeyModel.ServerKeyType.AzureKeyVault;
            Enum.TryParse <AzureSqlServerKeyVaultKeyModel.ServerKeyType>(resp.Properties.ServerKeyType, out type);
            ServerKey.Type       = type;
            ServerKey.Uri        = resp.Properties.Uri;
            ServerKey.Thumbprint = resp.Properties.Thumbprint;

            if (type == AzureSqlServerKeyVaultKeyModel.ServerKeyType.AzureKeyVault)
            {
                ServerKey.CreationDate = resp.Properties.CreationDate;
            }
            else
            {
                ServerKey.CreationDate = null;
            }

            return(ServerKey);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Deletes a Server Key Vault Key
        /// </summary>
        /// <param name="resourceGroupName">Name of resource group</param>
        /// <param name="serverName">Name of SQL server</param>
        /// <param name="keyId">KeyId of the Server Key Vault Key</param>
        public void Delete(string resourceGroupName, string serverName, string keyId)
        {
            string keyName = AzureSqlServerKeyVaultKeyModel.CreateServerKeyNameFromKeyId(keyId);

            Communicator.Delete(resourceGroupName, serverName, keyName, Util.GenerateTracingId());
        }