public AuditingPolicy GetServerAuditingPolicy(string resourceGroup, string serverName, string requestId) { DatabaseSecurityPolicy policy = Communicator.GetServerSecurityPolicy(resourceGroup, serverName, requestId); AuditingPolicy wrapper = WrapPolicy(policy); wrapper.ResourceGroupName = resourceGroup; wrapper.ServerName = serverName; return(wrapper); }
public AuditingPolicy GetDatabaseAuditingPolicy(string resourceGroup, string serverName, string databaseName, string requestId) { DatabaseSecurityPolicy policy = Communicator.GetDatabaseSecurityPolicy(resourceGroup, serverName, databaseName, requestId); AuditingPolicy wrapper = WrapPolicy(policy); wrapper.ResourceGroupName = resourceGroup; wrapper.ServerName = serverName; wrapper.DatabaseName = databaseName; AddConnectionStringsToWrapperFromPolicy(wrapper, policy.Properties); return(wrapper); }
private AuditingPolicy WrapPolicy(DatabaseSecurityPolicy policy) { AuditingPolicy wrapper = new AuditingPolicy(); DatabaseSecurityPolicyProperties properties = policy.Properties; wrapper.UseServerDefault = properties.UseServerDefault; wrapper.IsEnabled = properties.IsAuditingEnabled; wrapper.StorageAccountName = properties.StorageAccountName; AddEventTypesToWrapperFromPolicy(wrapper, properties); this.FetchedProperties = properties; return(wrapper); }
private AuditingPolicy WrapPolicy(DatabaseSecurityPolicy policy) { AuditingPolicy wrapper = new AuditingPolicy(); DatabaseSecurityPolicyProperties properties = policy.Properties; wrapper.UseServerDefault = properties.UseServerDefault; wrapper.IsEnabled = properties.IsAuditingEnabled; wrapper.DirectAccessEnabled = !properties.IsBlockDirectAccessEnabled; addStorageInfoToWrapperFromPolicy(wrapper, properties); AddEventTypesToWrapperFromPolicy(wrapper, properties); this.FetchedProperties = properties; return(wrapper); }
/// <summary> /// Gets Azure SQL Database security policy object according to a given /// Azure SQL Database Server and Database. /// </summary> /// <param name='resourceGroupName'> /// Required. The name of the Resource Group to which the Azure SQL /// Database Server belongs. /// </param> /// <param name='serverName'> /// Required. The name of the Azure SQL Database Server on which the /// Azure SQL Database hosted. /// </param> /// <param name='databaseName'> /// Required. The name of the Azure SQL Database for which the security /// policy is being retreived. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Represents the response to a get Azure SQL Database security policy /// request /// </returns> public async Task <DatabaseSecurityPolicyGetResponse> GetAsync(string resourceGroupName, string serverName, string databaseName, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (serverName == null) { throw new ArgumentNullException("serverName"); } if (databaseName == null) { throw new ArgumentNullException("databaseName"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("serverName", serverName); tracingParameters.Add("databaseName", databaseName); TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/resourceGroups/"; url = url + Uri.EscapeDataString(resourceGroupName); url = url + "/providers/"; url = url + "Microsoft.Sql"; url = url + "/servers/"; url = url + Uri.EscapeDataString(serverName); url = url + "/databaseSecurityPolicies/"; url = url + Uri.EscapeDataString(databaseName); List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-04-01"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result DatabaseSecurityPolicyGetResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new DatabaseSecurityPolicyGetResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { DatabaseSecurityPolicy databaseSecurityPolicyInstance = new DatabaseSecurityPolicy(); result.DatabaseSecurityPolicy = databaseSecurityPolicyInstance; JToken nameValue = responseDoc["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); databaseSecurityPolicyInstance.Name = nameInstance; } JToken propertiesValue = responseDoc["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { DatabaseSecurityPolicyProperties propertiesInstance = new DatabaseSecurityPolicyProperties(); databaseSecurityPolicyInstance.Properties = propertiesInstance; JToken isAuditingEnabledValue = propertiesValue["isAuditingEnabled"]; if (isAuditingEnabledValue != null && isAuditingEnabledValue.Type != JTokenType.Null) { bool isAuditingEnabledInstance = ((bool)isAuditingEnabledValue); propertiesInstance.IsAuditingEnabled = isAuditingEnabledInstance; } JToken retentionDaysValue = propertiesValue["retentionDays"]; if (retentionDaysValue != null && retentionDaysValue.Type != JTokenType.Null) { int retentionDaysInstance = ((int)retentionDaysValue); propertiesInstance.RetentionDays = retentionDaysInstance; } JToken isEventTypeDataAccessEnabledValue = propertiesValue["isEventTypeDataAccessEnabled"]; if (isEventTypeDataAccessEnabledValue != null && isEventTypeDataAccessEnabledValue.Type != JTokenType.Null) { bool isEventTypeDataAccessEnabledInstance = ((bool)isEventTypeDataAccessEnabledValue); propertiesInstance.IsEventTypeDataAccessEnabled = isEventTypeDataAccessEnabledInstance; } JToken isEventTypeSchemaChangeEnabledValue = propertiesValue["isEventTypeSchemaChangeEnabled"]; if (isEventTypeSchemaChangeEnabledValue != null && isEventTypeSchemaChangeEnabledValue.Type != JTokenType.Null) { bool isEventTypeSchemaChangeEnabledInstance = ((bool)isEventTypeSchemaChangeEnabledValue); propertiesInstance.IsEventTypeSchemaChangeEnabled = isEventTypeSchemaChangeEnabledInstance; } JToken isEventTypeDataChangesEnabledValue = propertiesValue["isEventTypeDataChangesEnabled"]; if (isEventTypeDataChangesEnabledValue != null && isEventTypeDataChangesEnabledValue.Type != JTokenType.Null) { bool isEventTypeDataChangesEnabledInstance = ((bool)isEventTypeDataChangesEnabledValue); propertiesInstance.IsEventTypeDataChangesEnabled = isEventTypeDataChangesEnabledInstance; } JToken isEventTypeSecurityExceptionsEnabledValue = propertiesValue["isEventTypeSecurityExceptionsEnabled"]; if (isEventTypeSecurityExceptionsEnabledValue != null && isEventTypeSecurityExceptionsEnabledValue.Type != JTokenType.Null) { bool isEventTypeSecurityExceptionsEnabledInstance = ((bool)isEventTypeSecurityExceptionsEnabledValue); propertiesInstance.IsEventTypeSecurityExceptionsEnabled = isEventTypeSecurityExceptionsEnabledInstance; } JToken isEventTypeGrantRevokePermissionsEnabledValue = propertiesValue["isEventTypeGrantRevokePermissionsEnabled"]; if (isEventTypeGrantRevokePermissionsEnabledValue != null && isEventTypeGrantRevokePermissionsEnabledValue.Type != JTokenType.Null) { bool isEventTypeGrantRevokePermissionsEnabledInstance = ((bool)isEventTypeGrantRevokePermissionsEnabledValue); propertiesInstance.IsEventTypeGrantRevokePermissionsEnabled = isEventTypeGrantRevokePermissionsEnabledInstance; } JToken storageAccountNameValue = propertiesValue["storageAccountName"]; if (storageAccountNameValue != null && storageAccountNameValue.Type != JTokenType.Null) { string storageAccountNameInstance = ((string)storageAccountNameValue); propertiesInstance.StorageAccountName = storageAccountNameInstance; } JToken storageAccountKeyValue = propertiesValue["storageAccountKey"]; if (storageAccountKeyValue != null && storageAccountKeyValue.Type != JTokenType.Null) { string storageAccountKeyInstance = ((string)storageAccountKeyValue); propertiesInstance.StorageAccountKey = storageAccountKeyInstance; } JToken secondaryStorageAccountKeyValue = propertiesValue["secondaryStorageAccountKey"]; if (secondaryStorageAccountKeyValue != null && secondaryStorageAccountKeyValue.Type != JTokenType.Null) { string secondaryStorageAccountKeyInstance = ((string)secondaryStorageAccountKeyValue); propertiesInstance.SecondaryStorageAccountKey = secondaryStorageAccountKeyInstance; } JToken storageTableEndpointValue = propertiesValue["storageTableEndpoint"]; if (storageTableEndpointValue != null && storageTableEndpointValue.Type != JTokenType.Null) { string storageTableEndpointInstance = ((string)storageTableEndpointValue); propertiesInstance.StorageTableEndpoint = storageTableEndpointInstance; } JToken storageAccountResourceGroupNameValue = propertiesValue["storageAccountResourceGroupName"]; if (storageAccountResourceGroupNameValue != null && storageAccountResourceGroupNameValue.Type != JTokenType.Null) { string storageAccountResourceGroupNameInstance = ((string)storageAccountResourceGroupNameValue); propertiesInstance.StorageAccountResourceGroupName = storageAccountResourceGroupNameInstance; } JToken storageAccountSubscriptionIdValue = propertiesValue["storageAccountSubscriptionId"]; if (storageAccountSubscriptionIdValue != null && storageAccountSubscriptionIdValue.Type != JTokenType.Null) { string storageAccountSubscriptionIdInstance = ((string)storageAccountSubscriptionIdValue); propertiesInstance.StorageAccountSubscriptionId = storageAccountSubscriptionIdInstance; } JToken proxyDnsNameValue = propertiesValue["proxyDnsName"]; if (proxyDnsNameValue != null && proxyDnsNameValue.Type != JTokenType.Null) { string proxyDnsNameInstance = ((string)proxyDnsNameValue); propertiesInstance.ProxyDnsName = proxyDnsNameInstance; } JToken proxyPortValue = propertiesValue["proxyPort"]; if (proxyPortValue != null && proxyPortValue.Type != JTokenType.Null) { string proxyPortInstance = ((string)proxyPortValue); propertiesInstance.ProxyPort = proxyPortInstance; } JToken useServerDefaultValue = propertiesValue["useServerDefault"]; if (useServerDefaultValue != null && useServerDefaultValue.Type != JTokenType.Null) { bool useServerDefaultInstance = ((bool)useServerDefaultValue); propertiesInstance.UseServerDefault = useServerDefaultInstance; } JToken isBlockDirectAccessEnabledValue = propertiesValue["isBlockDirectAccessEnabled"]; if (isBlockDirectAccessEnabledValue != null && isBlockDirectAccessEnabledValue.Type != JTokenType.Null) { bool isBlockDirectAccessEnabledInstance = ((bool)isBlockDirectAccessEnabledValue); propertiesInstance.IsBlockDirectAccessEnabled = isBlockDirectAccessEnabledInstance; } } JToken idValue = responseDoc["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); databaseSecurityPolicyInstance.Id = idInstance; } JToken typeValue = responseDoc["type"]; if (typeValue != null && typeValue.Type != JTokenType.Null) { string typeInstance = ((string)typeValue); databaseSecurityPolicyInstance.Type = typeInstance; } JToken locationValue = responseDoc["location"]; if (locationValue != null && locationValue.Type != JTokenType.Null) { string locationInstance = ((string)locationValue); databaseSecurityPolicyInstance.Location = locationInstance; } JToken tagsSequenceElement = ((JToken)responseDoc["tags"]); if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null) { foreach (JProperty property in tagsSequenceElement) { string tagsKey = ((string)property.Name); string tagsValue = ((string)property.Value); databaseSecurityPolicyInstance.Tags.Add(tagsKey, tagsValue); } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }