/// <summary> /// Creates policy given the provider data /// </summary> /// <returns>Created policy object as returned by the service</returns> public ProtectionPolicyResource CreatePolicy() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string policyName = (string)ProviderData[PolicyParams.PolicyName]; CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType]; RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; ValidateAzureSqlWorkloadType(workloadType); // validate RetentionPolicy ValidateAzureSqlRetentionPolicy(retentionPolicy); Logger.Instance.WriteDebug("Validation of Retention policy is successful"); // construct Hydra policy request ProtectionPolicyResource protectionPolicyResource = new ProtectionPolicyResource() { Properties = new AzureSqlProtectionPolicy() { RetentionPolicy = PolicyHelpers.GetServiceClientSimpleRetentionPolicy( (CmdletModel.SimpleRetentionPolicy)retentionPolicy) } }; return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy( policyName, protectionPolicyResource, vaultName: vaultName, resourceGroupName: resourceGroupName).Body); }
/// <summary> /// Modifies policy using the provider data /// </summary> /// <returns>Modified policy object as returned by the service</returns> public RestAzureNS.AzureOperationResponse <ProtectionPolicyResource> ModifyPolicy() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; PolicyBase policy = ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ? (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] : null; // RetentionPolicy if (retentionPolicy == null) { throw new ArgumentException(Resources.RetentionPolicyEmptyInAzureSql); } else { ValidateAzureSqlRetentionPolicy(retentionPolicy); ((AzureSqlPolicy)policy).RetentionPolicy = retentionPolicy; Logger.Instance.WriteDebug("Validation of Retention policy is successful"); } CmdletModel.SimpleRetentionPolicy sqlRetentionPolicy = (CmdletModel.SimpleRetentionPolicy)((AzureSqlPolicy)policy).RetentionPolicy; ProtectionPolicyResource protectionPolicyResource = new ProtectionPolicyResource() { Properties = new AzureSqlProtectionPolicy() { RetentionPolicy = PolicyHelpers.GetServiceClientSimpleRetentionPolicy(sqlRetentionPolicy) } }; return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy( policy.Name, protectionPolicyResource, vaultName: vaultName, resourceGroupName: resourceGroupName)); }
/// <summary> /// Modifies policy using the provider data /// </summary> /// <returns>Modified policy object as returned by the service</returns> public ProtectionPolicyResponse ModifyPolicy() { RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; PolicyBase policy = ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ? (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] : null; // RetentionPolicy if (retentionPolicy == null) { throw new ArgumentException(Resources.RetentionPolicyEmptyInAzureSql); } else { ValidateAzureSqlRetentionPolicy(retentionPolicy); ((AzureSqlPolicy)policy).RetentionPolicy = retentionPolicy; Logger.Instance.WriteDebug("Validation of Retention policy is successful"); } CmdletModel.SimpleRetentionPolicy sqlRetentionPolicy = (CmdletModel.SimpleRetentionPolicy)((AzureSqlPolicy)policy).RetentionPolicy; ProtectionPolicyRequest hydraRequest = new ProtectionPolicyRequest() { Item = new ProtectionPolicyResource() { Properties = new AzureSqlProtectionPolicy() { RetentionPolicy = PolicyHelpers.GetServiceClientSimpleRetentionPolicy(sqlRetentionPolicy) } } }; return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(policy.Name, hydraRequest)); }