From 5f800ddde8297551468102be35504696686d5f7f Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Tue, 6 Nov 2018 08:43:12 +0000 Subject: [PATCH] Generated from 299395494bd8984518fec288f4e564e9b9852a13 fix blob auditing alignment --- .../preview/preview/sql/mgmt/sql/models.go | 3 + .../sql/mgmt/2015-05-01-preview/sql/models.go | 9 +- .../sql/databasevulnerabilityassessments.go | 126 ++++++++++++- .../sql/mgmt/2017-03-01-preview/sql/models.go | 177 ++++++++++++++++-- ...manageddatabasevulnerabilityassessments.go | 126 ++++++++++++- .../sql/mgmt/2017-10-01-preview/sql/models.go | 141 +++++++++++++- 6 files changed, 542 insertions(+), 40 deletions(-) diff --git a/profiles/preview/preview/sql/mgmt/sql/models.go b/profiles/preview/preview/sql/mgmt/sql/models.go index fd036a62ffaa..e834c15f9203 100644 --- a/profiles/preview/preview/sql/mgmt/sql/models.go +++ b/profiles/preview/preview/sql/mgmt/sql/models.go @@ -253,6 +253,9 @@ type DatabasesUpdateFuture = original.DatabasesUpdateFuture type DatabasesUpgradeDataWarehouseFuture = original.DatabasesUpgradeDataWarehouseFuture type DatabaseUpdate = original.DatabaseUpdate type DatabaseVulnerabilityAssessment = original.DatabaseVulnerabilityAssessment +type DatabaseVulnerabilityAssessmentListResult = original.DatabaseVulnerabilityAssessmentListResult +type DatabaseVulnerabilityAssessmentListResultIterator = original.DatabaseVulnerabilityAssessmentListResultIterator +type DatabaseVulnerabilityAssessmentListResultPage = original.DatabaseVulnerabilityAssessmentListResultPage type DatabaseVulnerabilityAssessmentProperties = original.DatabaseVulnerabilityAssessmentProperties type DatabaseVulnerabilityAssessmentRuleBaseline = original.DatabaseVulnerabilityAssessmentRuleBaseline type DatabaseVulnerabilityAssessmentRuleBaselineItem = original.DatabaseVulnerabilityAssessmentRuleBaselineItem diff --git a/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go b/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go index b8e9e65d794c..26eae0790499 100644 --- a/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go +++ b/services/preview/sql/mgmt/2015-05-01-preview/sql/models.go @@ -1615,9 +1615,9 @@ type DatabaseBlobAuditingPolicyProperties struct { // REFERENCES // // The general form for defining an action to be audited is: - // ON BY + // {action} ON {object} BY {principal} // - // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE:: and SCHEMA:: are used, respectively. + // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. // // For example: // SELECT on dbo.myTable by public @@ -1634,9 +1634,10 @@ type DatabaseBlobAuditingPolicyProperties struct { // In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. // // When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. - // Note that for server level audit you should use the 'master' database as . + // Note that for server level audit you should use the 'master' database as {databaseName}. + // // Diagnostic Settings URI format: - // PUT https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases//providers/microsoft.insights/diagnosticSettings/?api-version=2017-05-01-preview + // PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview // // For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207) // or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043) diff --git a/services/preview/sql/mgmt/2017-03-01-preview/sql/databasevulnerabilityassessments.go b/services/preview/sql/mgmt/2017-03-01-preview/sql/databasevulnerabilityassessments.go index b6f7556da535..ae404a51d105 100644 --- a/services/preview/sql/mgmt/2017-03-01-preview/sql/databasevulnerabilityassessments.go +++ b/services/preview/sql/mgmt/2017-03-01-preview/sql/databasevulnerabilityassessments.go @@ -21,7 +21,6 @@ import ( "context" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" "github.com/Azure/go-autorest/tracing" "net/http" ) @@ -62,13 +61,6 @@ func (client DatabaseVulnerabilityAssessmentsClient) CreateOrUpdate(ctx context. tracing.EndSpan(ctx, sc, err) }() } - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.DatabaseVulnerabilityAssessmentProperties", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.DatabaseVulnerabilityAssessmentProperties.StorageContainerPath", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { - return result, validation.NewError("sql.DatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", err.Error()) - } - req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, databaseName, parameters) if err != nil { err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", nil, "Failure preparing request") @@ -295,3 +287,121 @@ func (client DatabaseVulnerabilityAssessmentsClient) GetResponder(resp *http.Res result.Response = autorest.Response{Response: resp} return } + +// ListByDatabase lists the vulnerability assessment policies associated with a database. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// serverName - the name of the server. +// databaseName - the name of the database for which the vulnerability assessment policies are defined. +func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseVulnerabilityAssessmentListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.ListByDatabase") + defer func() { + sc := -1 + if result.dvalr.Response.Response != nil { + sc = result.dvalr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listByDatabaseNextResults + req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "ListByDatabase", nil, "Failure preparing request") + return + } + + resp, err := client.ListByDatabaseSender(req) + if err != nil { + result.dvalr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "ListByDatabase", resp, "Failure sending request") + return + } + + result.dvalr, err = client.ListByDatabaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "ListByDatabase", resp, "Failure responding to request") + } + + return +} + +// ListByDatabasePreparer prepares the ListByDatabase request. +func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "databaseName": autorest.Encode("path", databaseName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serverName": autorest.Encode("path", serverName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-03-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByDatabaseSender sends the ListByDatabase request. The method will close the +// http.Response Body if it receives an error. +func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always +// closes the http.Response Body. +func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabaseResponder(resp *http.Response) (result DatabaseVulnerabilityAssessmentListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByDatabaseNextResults retrieves the next set of results, if any. +func (client DatabaseVulnerabilityAssessmentsClient) listByDatabaseNextResults(ctx context.Context, lastResults DatabaseVulnerabilityAssessmentListResult) (result DatabaseVulnerabilityAssessmentListResult, err error) { + req, err := lastResults.databaseVulnerabilityAssessmentListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByDatabaseSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByDatabaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByDatabaseComplete enumerates all values, automatically crossing page boundaries as required. +func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabaseComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseVulnerabilityAssessmentListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.ListByDatabase") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListByDatabase(ctx, resourceGroupName, serverName, databaseName) + return +} diff --git a/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go b/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go index a1b6ea4df8e1..2a7266add3d4 100644 --- a/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go +++ b/services/preview/sql/mgmt/2017-03-01-preview/sql/models.go @@ -2150,9 +2150,9 @@ type DatabaseBlobAuditingPolicyProperties struct { // REFERENCES // // The general form for defining an action to be audited is: - // ON BY + // {action} ON {object} BY {principal} // - // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE:: and SCHEMA:: are used, respectively. + // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. // // For example: // SELECT on dbo.myTable by public @@ -2169,9 +2169,10 @@ type DatabaseBlobAuditingPolicyProperties struct { // In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. // // When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. - // Note that for server level audit you should use the 'master' database as . + // Note that for server level audit you should use the 'master' database as {databaseName}. + // // Diagnostic Settings URI format: - // PUT https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases//providers/microsoft.insights/diagnosticSettings/?api-version=2017-05-01-preview + // PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview // // For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207) // or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043) @@ -3021,13 +3022,150 @@ func (dva *DatabaseVulnerabilityAssessment) UnmarshalJSON(body []byte) error { return nil } +// DatabaseVulnerabilityAssessmentListResult a list of the database's vulnerability assessments. +type DatabaseVulnerabilityAssessmentListResult struct { + autorest.Response `json:"-"` + // Value - Array of results. + Value *[]DatabaseVulnerabilityAssessment `json:"value,omitempty"` + // NextLink - Link to retrieve next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// DatabaseVulnerabilityAssessmentListResultIterator provides access to a complete listing of +// DatabaseVulnerabilityAssessment values. +type DatabaseVulnerabilityAssessmentListResultIterator struct { + i int + page DatabaseVulnerabilityAssessmentListResultPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DatabaseVulnerabilityAssessmentListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentListResultIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DatabaseVulnerabilityAssessmentListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DatabaseVulnerabilityAssessmentListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DatabaseVulnerabilityAssessmentListResultIterator) Response() DatabaseVulnerabilityAssessmentListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DatabaseVulnerabilityAssessmentListResultIterator) Value() DatabaseVulnerabilityAssessment { + if !iter.page.NotDone() { + return DatabaseVulnerabilityAssessment{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (dvalr DatabaseVulnerabilityAssessmentListResult) IsEmpty() bool { + return dvalr.Value == nil || len(*dvalr.Value) == 0 +} + +// databaseVulnerabilityAssessmentListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dvalr DatabaseVulnerabilityAssessmentListResult) databaseVulnerabilityAssessmentListResultPreparer(ctx context.Context) (*http.Request, error) { + if dvalr.NextLink == nil || len(to.String(dvalr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dvalr.NextLink))) +} + +// DatabaseVulnerabilityAssessmentListResultPage contains a page of DatabaseVulnerabilityAssessment values. +type DatabaseVulnerabilityAssessmentListResultPage struct { + fn func(context.Context, DatabaseVulnerabilityAssessmentListResult) (DatabaseVulnerabilityAssessmentListResult, error) + dvalr DatabaseVulnerabilityAssessmentListResult +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DatabaseVulnerabilityAssessmentListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentListResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.dvalr) + if err != nil { + return err + } + page.dvalr = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DatabaseVulnerabilityAssessmentListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DatabaseVulnerabilityAssessmentListResultPage) NotDone() bool { + return !page.dvalr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DatabaseVulnerabilityAssessmentListResultPage) Response() DatabaseVulnerabilityAssessmentListResult { + return page.dvalr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DatabaseVulnerabilityAssessmentListResultPage) Values() []DatabaseVulnerabilityAssessment { + if page.dvalr.IsEmpty() { + return nil + } + return *page.dvalr.Value +} + // DatabaseVulnerabilityAssessmentProperties properties of a database Vulnerability Assessment. type DatabaseVulnerabilityAssessmentProperties struct { - // StorageContainerPath - A blob storage container path to hold the scan results (e.g. https://myStorage.blob.core.windows.net/VaScans/). + // StorageContainerPath - A blob storage container path to hold the scan results (e.g. https://myStorage.blob.core.windows.net/VaScans/). It is required if server level vulnerability assessment policy doesn't set StorageContainerPath *string `json:"storageContainerPath,omitempty"` // StorageContainerSasKey - A shared access signature (SAS Key) that has write access to the blob container specified in 'storageContainerPath' parameter. If 'storageAccountAccessKey' isn't specified, StorageContainerSasKey is required. StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` - // StorageAccountAccessKey - Specifies the identifier key of the vulnerability assessment storage account. If 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is required. + // StorageAccountAccessKey - Specifies the identifier key of the storage account for vulnerability assessment scan results. If 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is required. StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` // RecurringScans - The recurring scans settings RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` @@ -4580,9 +4718,9 @@ type ExtendedDatabaseBlobAuditingPolicyProperties struct { // REFERENCES // // The general form for defining an action to be audited is: - // ON BY + // {action} ON {object} BY {principal} // - // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE:: and SCHEMA:: are used, respectively. + // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. // // For example: // SELECT on dbo.myTable by public @@ -4599,9 +4737,10 @@ type ExtendedDatabaseBlobAuditingPolicyProperties struct { // In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. // // When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. - // Note that for server level audit you should use the 'master' database as . + // Note that for server level audit you should use the 'master' database as {databaseName}. + // // Diagnostic Settings URI format: - // PUT https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases//providers/microsoft.insights/diagnosticSettings/?api-version=2017-05-01-preview + // PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview // // For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207) // or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043) @@ -4778,9 +4917,9 @@ type ExtendedServerBlobAuditingPolicyProperties struct { // REFERENCES // // The general form for defining an action to be audited is: - // ON BY + // {action} ON {object} BY {principal} // - // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE:: and SCHEMA:: are used, respectively. + // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. // // For example: // SELECT on dbo.myTable by public @@ -4797,9 +4936,10 @@ type ExtendedServerBlobAuditingPolicyProperties struct { // In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. // // When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. - // Note that for server level audit you should use the 'master' database as . + // Note that for server level audit you should use the 'master' database as {databaseName}. + // // Diagnostic Settings URI format: - // PUT https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases//providers/microsoft.insights/diagnosticSettings/?api-version=2017-05-01-preview + // PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview // // For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207) // or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043) @@ -10000,9 +10140,9 @@ type ServerBlobAuditingPolicyProperties struct { // REFERENCES // // The general form for defining an action to be audited is: - // ON BY + // {action} ON {object} BY {principal} // - // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE:: and SCHEMA:: are used, respectively. + // Note that in the above format can refer to an object like a table, view, or stored procedure, or an entire database or schema. For the latter cases, the forms DATABASE::{db_name} and SCHEMA::{schema_name} are used, respectively. // // For example: // SELECT on dbo.myTable by public @@ -10019,9 +10159,10 @@ type ServerBlobAuditingPolicyProperties struct { // In order to send the events to Azure Monitor, specify 'State' as 'Enabled' and 'IsAzureMonitorTargetEnabled' as true. // // When using REST API to configure auditing, Diagnostic Settings with 'SQLSecurityAuditEvents' diagnostic logs category on the database should be also created. - // Note that for server level audit you should use the 'master' database as . + // Note that for server level audit you should use the 'master' database as {databaseName}. + // // Diagnostic Settings URI format: - // PUT https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Sql/servers//databases//providers/microsoft.insights/diagnosticSettings/?api-version=2017-05-01-preview + // PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/providers/microsoft.insights/diagnosticSettings/{settingsName}?api-version=2017-05-01-preview // // For more information, see [Diagnostic Settings REST API](https://go.microsoft.com/fwlink/?linkid=2033207) // or [Diagnostic Settings PowerShell](https://go.microsoft.com/fwlink/?linkid=2033043) diff --git a/services/preview/sql/mgmt/2017-10-01-preview/sql/manageddatabasevulnerabilityassessments.go b/services/preview/sql/mgmt/2017-10-01-preview/sql/manageddatabasevulnerabilityassessments.go index e743a4088217..5cb37b16fe4b 100644 --- a/services/preview/sql/mgmt/2017-10-01-preview/sql/manageddatabasevulnerabilityassessments.go +++ b/services/preview/sql/mgmt/2017-10-01-preview/sql/manageddatabasevulnerabilityassessments.go @@ -21,7 +21,6 @@ import ( "context" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/validation" "github.com/Azure/go-autorest/tracing" "net/http" ) @@ -63,13 +62,6 @@ func (client ManagedDatabaseVulnerabilityAssessmentsClient) CreateOrUpdate(ctx c tracing.EndSpan(ctx, sc, err) }() } - if err := validation.Validate([]validation.Validation{ - {TargetValue: parameters, - Constraints: []validation.Constraint{{Target: "parameters.DatabaseVulnerabilityAssessmentProperties", Name: validation.Null, Rule: false, - Chain: []validation.Constraint{{Target: "parameters.DatabaseVulnerabilityAssessmentProperties.StorageContainerPath", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { - return result, validation.NewError("sql.ManagedDatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", err.Error()) - } - req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, managedInstanceName, databaseName, parameters) if err != nil { err = autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", nil, "Failure preparing request") @@ -296,3 +288,121 @@ func (client ManagedDatabaseVulnerabilityAssessmentsClient) GetResponder(resp *h result.Response = autorest.Response{Response: resp} return } + +// ListByDatabase lists the vulnerability assessments of a managed database. +// Parameters: +// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value +// from the Azure Resource Manager API or the portal. +// managedInstanceName - the name of the managed instance. +// databaseName - the name of the database for which the vulnerability assessment is defined. +func (client ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabase(ctx context.Context, resourceGroupName string, managedInstanceName string, databaseName string) (result DatabaseVulnerabilityAssessmentListResultPage, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedDatabaseVulnerabilityAssessmentsClient.ListByDatabase") + defer func() { + sc := -1 + if result.dvalr.Response.Response != nil { + sc = result.dvalr.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.fn = client.listByDatabaseNextResults + req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, managedInstanceName, databaseName) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "ListByDatabase", nil, "Failure preparing request") + return + } + + resp, err := client.ListByDatabaseSender(req) + if err != nil { + result.dvalr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "ListByDatabase", resp, "Failure sending request") + return + } + + result.dvalr, err = client.ListByDatabaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "ListByDatabase", resp, "Failure responding to request") + } + + return +} + +// ListByDatabasePreparer prepares the ListByDatabase request. +func (client ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, managedInstanceName string, databaseName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "databaseName": autorest.Encode("path", databaseName), + "managedInstanceName": autorest.Encode("path", managedInstanceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-10-01-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByDatabaseSender sends the ListByDatabase request. The method will close the +// http.Response Body if it receives an error. +func (client ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always +// closes the http.Response Body. +func (client ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabaseResponder(resp *http.Response) (result DatabaseVulnerabilityAssessmentListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByDatabaseNextResults retrieves the next set of results, if any. +func (client ManagedDatabaseVulnerabilityAssessmentsClient) listByDatabaseNextResults(ctx context.Context, lastResults DatabaseVulnerabilityAssessmentListResult) (result DatabaseVulnerabilityAssessmentListResult, err error) { + req, err := lastResults.databaseVulnerabilityAssessmentListResultPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByDatabaseSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByDatabaseResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "sql.ManagedDatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByDatabaseComplete enumerates all values, automatically crossing page boundaries as required. +func (client ManagedDatabaseVulnerabilityAssessmentsClient) ListByDatabaseComplete(ctx context.Context, resourceGroupName string, managedInstanceName string, databaseName string) (result DatabaseVulnerabilityAssessmentListResultIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ManagedDatabaseVulnerabilityAssessmentsClient.ListByDatabase") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.ListByDatabase(ctx, resourceGroupName, managedInstanceName, databaseName) + return +} diff --git a/services/preview/sql/mgmt/2017-10-01-preview/sql/models.go b/services/preview/sql/mgmt/2017-10-01-preview/sql/models.go index 330355579c62..2fc30baf6904 100644 --- a/services/preview/sql/mgmt/2017-10-01-preview/sql/models.go +++ b/services/preview/sql/mgmt/2017-10-01-preview/sql/models.go @@ -1631,13 +1631,150 @@ func (dva *DatabaseVulnerabilityAssessment) UnmarshalJSON(body []byte) error { return nil } +// DatabaseVulnerabilityAssessmentListResult a list of the database's vulnerability assessments. +type DatabaseVulnerabilityAssessmentListResult struct { + autorest.Response `json:"-"` + // Value - Array of results. + Value *[]DatabaseVulnerabilityAssessment `json:"value,omitempty"` + // NextLink - Link to retrieve next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// DatabaseVulnerabilityAssessmentListResultIterator provides access to a complete listing of +// DatabaseVulnerabilityAssessment values. +type DatabaseVulnerabilityAssessmentListResultIterator struct { + i int + page DatabaseVulnerabilityAssessmentListResultPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *DatabaseVulnerabilityAssessmentListResultIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentListResultIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *DatabaseVulnerabilityAssessmentListResultIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter DatabaseVulnerabilityAssessmentListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter DatabaseVulnerabilityAssessmentListResultIterator) Response() DatabaseVulnerabilityAssessmentListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter DatabaseVulnerabilityAssessmentListResultIterator) Value() DatabaseVulnerabilityAssessment { + if !iter.page.NotDone() { + return DatabaseVulnerabilityAssessment{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (dvalr DatabaseVulnerabilityAssessmentListResult) IsEmpty() bool { + return dvalr.Value == nil || len(*dvalr.Value) == 0 +} + +// databaseVulnerabilityAssessmentListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (dvalr DatabaseVulnerabilityAssessmentListResult) databaseVulnerabilityAssessmentListResultPreparer(ctx context.Context) (*http.Request, error) { + if dvalr.NextLink == nil || len(to.String(dvalr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(dvalr.NextLink))) +} + +// DatabaseVulnerabilityAssessmentListResultPage contains a page of DatabaseVulnerabilityAssessment values. +type DatabaseVulnerabilityAssessmentListResultPage struct { + fn func(context.Context, DatabaseVulnerabilityAssessmentListResult) (DatabaseVulnerabilityAssessmentListResult, error) + dvalr DatabaseVulnerabilityAssessmentListResult +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *DatabaseVulnerabilityAssessmentListResultPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentListResultPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.dvalr) + if err != nil { + return err + } + page.dvalr = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *DatabaseVulnerabilityAssessmentListResultPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page DatabaseVulnerabilityAssessmentListResultPage) NotDone() bool { + return !page.dvalr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page DatabaseVulnerabilityAssessmentListResultPage) Response() DatabaseVulnerabilityAssessmentListResult { + return page.dvalr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page DatabaseVulnerabilityAssessmentListResultPage) Values() []DatabaseVulnerabilityAssessment { + if page.dvalr.IsEmpty() { + return nil + } + return *page.dvalr.Value +} + // DatabaseVulnerabilityAssessmentProperties properties of a database Vulnerability Assessment. type DatabaseVulnerabilityAssessmentProperties struct { - // StorageContainerPath - A blob storage container path to hold the scan results (e.g. https://myStorage.blob.core.windows.net/VaScans/). + // StorageContainerPath - A blob storage container path to hold the scan results (e.g. https://myStorage.blob.core.windows.net/VaScans/). It is required if server level vulnerability assessment policy doesn't set StorageContainerPath *string `json:"storageContainerPath,omitempty"` // StorageContainerSasKey - A shared access signature (SAS Key) that has write access to the blob container specified in 'storageContainerPath' parameter. If 'storageAccountAccessKey' isn't specified, StorageContainerSasKey is required. StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` - // StorageAccountAccessKey - Specifies the identifier key of the vulnerability assessment storage account. If 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is required. + // StorageAccountAccessKey - Specifies the identifier key of the storage account for vulnerability assessment scan results. If 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is required. StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` // RecurringScans - The recurring scans settings RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"`