/// <summary> /// Sets the data masking policy of a specific database to be based on the information provided by the model object /// </summary> public void SetDatabaseDataMaskingPolicy(DatabaseDataMaskingPolicyModel model, String clientId) { if (!IsRightServerVersionForDataMasking(model.ResourceGroupName,model.ServerName, clientId)) { throw new Exception(Properties.Resources.ServerNotApplicableForDataMasking); } DataMaskingPolicyCreateOrUpdateParameters parameters = PolicizeDatabaseDataMaskingModel(model); Communicator.SetDatabaseDataMaskingPolicy(model.ResourceGroupName, model.ServerName, model.DatabaseName, clientId, parameters); }
/// <summary> /// Updates the given model element with the cmdlet specific operation /// </summary> /// <param name="model">A model object</param> protected override DatabaseDataMaskingPolicyModel ApplyUserInputToModel(DatabaseDataMaskingPolicyModel model) { base.ApplyUserInputToModel(model); if (PrivilegedLogins != null) // empty string here means that the user clears the logins list { model.PrivilegedLogins = PrivilegedLogins; } if (!string.IsNullOrEmpty(DataMaskingState)) { model.DataMaskingState = (DataMaskingState == SecurityConstants.Enabled) ? DataMaskingStateType.Enabled : DataMaskingStateType.Disabled; } return model; }
/// <summary> /// Updates the given model element with the cmdlet specific operation /// </summary> /// <param name="model">A model object</param> protected override DatabaseDataMaskingPolicyModel ApplyUserInputToModel(DatabaseDataMaskingPolicyModel model) { base.ApplyUserInputToModel(model); if (PrivilegedLogins != null) // empty string here means that the user clears the logins list { WriteWarning("The parameter PrivilegedLogins is being deprecated and will be removed in a future release. Use the PrivilegedUsers parameter to provide SQL users excluded from masking."); model.PrivilegedUsers = PrivilegedLogins; } if (PrivilegedUsers != null) // empty string here means that the user clears the users list { model.PrivilegedUsers = PrivilegedUsers; } if (!string.IsNullOrEmpty(DataMaskingState)) { model.DataMaskingState = (DataMaskingState == SecurityConstants.Enabled) ? DataMaskingStateType.Enabled : DataMaskingStateType.Disabled; } return model; }
/// <summary> /// Takes the cmdlets model object and transform it to the policy as expected by the endpoint /// </summary> /// <param name="model">The data masking Policy model object</param> /// <returns>The communication model object</returns> private DataMaskingPolicyCreateOrUpdateParameters PolicizeDatabaseDataMaskingModel(DatabaseDataMaskingPolicyModel model) { DataMaskingPolicyCreateOrUpdateParameters updateParameters = new DataMaskingPolicyCreateOrUpdateParameters(); DataMaskingPolicyProperties properties = new DataMaskingPolicyProperties(); updateParameters.Properties = properties; properties.DataMaskingState = (model.DataMaskingState == DataMaskingStateType.Disabled) ? SecurityConstants.DataMaskingEndpoint.Disabled : SecurityConstants.DataMaskingEndpoint.Enabled; properties.ExemptPrincipals = model.PrivilegedUsers ?? ""; return updateParameters; }
/// <summary> /// Transforms a data masking policy to its cmdlet model representation /// </summary> private DatabaseDataMaskingPolicyModel ModelizeDatabaseDataMaskingPolicy(DataMaskingPolicy policy) { DatabaseDataMaskingPolicyModel dbPolicyModel = new DatabaseDataMaskingPolicyModel(); DataMaskingPolicyProperties properties = policy.Properties; dbPolicyModel.DataMaskingState = ModelizePolicyState(properties.DataMaskingState); dbPolicyModel.PrivilegedUsers = properties.ExemptPrincipals; return dbPolicyModel; }
/// <summary> /// No sending is needed as this is a Get cmdlet /// </summary> /// <param name="model">The model object with the data to be sent to the REST endpoints</param> protected override DatabaseDataMaskingPolicyModel PersistChanges(DatabaseDataMaskingPolicyModel model) { return null; }
/// <summary> /// Sets the data masking policy of a specific database to be based on the information provided by the model object /// </summary> public void SetDatabaseDataMaskingPolicy(DatabaseDataMaskingPolicyModel model, String clientId) { DataMaskingPolicyCreateOrUpdateParameters parameters = PolicizeDatabaseDataMaskingModel(model); Communicator.SetDatabaseDataMaskingPolicy(model.ResourceGroupName, model.ServerName, model.DatabaseName, clientId, parameters); }
/// <summary> /// Transforms a data masking policy to its cmdlet model representation /// </summary> private DatabaseDataMaskingPolicyModel ModelizeDatabaseDataMaskingPolicy(DataMaskingPolicy policy) { DatabaseDataMaskingPolicyModel dbPolicyModel = new DatabaseDataMaskingPolicyModel(); DataMaskingPolicyProperties properties = policy.Properties; dbPolicyModel.DataMaskingState = (properties.DataMaskingState == SecurityConstants.DataMaskingEndpoint.Enabled) ? DataMaskingStateType.Enabled : DataMaskingStateType.Disabled; dbPolicyModel.PrivilegedLogins = properties.ExemptPrincipals; return dbPolicyModel; }