diff --git a/services/automation/mgmt/2015-10-31/automation/dscconfiguration.go b/services/automation/mgmt/2015-10-31/automation/dscconfiguration.go index 3c9716597392..14df2b443916 100644 --- a/services/automation/mgmt/2015-10-31/automation/dscconfiguration.go +++ b/services/automation/mgmt/2015-10-31/automation/dscconfiguration.go @@ -442,3 +442,82 @@ func (client DscConfigurationClient) ListByAutomationAccountComplete(ctx context result.page, err = client.ListByAutomationAccount(ctx, automationAccountName) return } + +// Update create the configuration identified by configuration name. +// +// automationAccountName is the automation account name. configurationName is the create or update parameters for +// configuration. parameters is the create or update parameters for configuration. +func (client DscConfigurationClient) Update(ctx context.Context, automationAccountName string, configurationName string, parameters *DscConfigurationUpdateParameters) (result DscConfiguration, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: client.ResourceGroupName, + Constraints: []validation.Constraint{{Target: "client.ResourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("automation.DscConfigurationClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, automationAccountName, configurationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "automation.DscConfigurationClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automation.DscConfigurationClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automation.DscConfigurationClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DscConfigurationClient) UpdatePreparer(ctx context.Context, automationAccountName string, configurationName string, parameters *DscConfigurationUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "automationAccountName": autorest.Encode("path", automationAccountName), + "configurationName": autorest.Encode("path", configurationName), + "resourceGroupName": autorest.Encode("path", client.ResourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-10-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/configurations/{configurationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if parameters != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(parameters)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DscConfigurationClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DscConfigurationClient) UpdateResponder(resp *http.Response) (result DscConfiguration, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/automation/mgmt/2015-10-31/automation/models.go b/services/automation/mgmt/2015-10-31/automation/models.go index 2b1c94dcf7db..f28783338934 100644 --- a/services/automation/mgmt/2015-10-31/automation/models.go +++ b/services/automation/mgmt/2015-10-31/automation/models.go @@ -3287,6 +3287,73 @@ func (dcp DscConfigurationProperties) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// DscConfigurationUpdateParameters the parameters supplied to the create or update configuration operation. +type DscConfigurationUpdateParameters struct { + // DscConfigurationCreateOrUpdateProperties - Gets or sets configuration create or update properties. + *DscConfigurationCreateOrUpdateProperties `json:"properties,omitempty"` + // Name - Gets or sets name of the resource. + Name *string `json:"name,omitempty"` + // Tags - Gets or sets the tags attached to the resource. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for DscConfigurationUpdateParameters. +func (dcup DscConfigurationUpdateParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dcup.DscConfigurationCreateOrUpdateProperties != nil { + objectMap["properties"] = dcup.DscConfigurationCreateOrUpdateProperties + } + if dcup.Name != nil { + objectMap["name"] = dcup.Name + } + if dcup.Tags != nil { + objectMap["tags"] = dcup.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for DscConfigurationUpdateParameters struct. +func (dcup *DscConfigurationUpdateParameters) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var dscConfigurationCreateOrUpdateProperties DscConfigurationCreateOrUpdateProperties + err = json.Unmarshal(*v, &dscConfigurationCreateOrUpdateProperties) + if err != nil { + return err + } + dcup.DscConfigurationCreateOrUpdateProperties = &dscConfigurationCreateOrUpdateProperties + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + dcup.Name = &name + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + dcup.Tags = tags + } + } + } + + return nil +} + // DscMetaConfiguration definition of the DSC Meta Configuration. type DscMetaConfiguration struct { // ConfigurationModeFrequencyMins - Gets or sets the ConfigurationModeFrequencyMins value of the meta configuration. diff --git a/services/automation/mgmt/2017-05-15-preview/automation/dscconfiguration.go b/services/automation/mgmt/2017-05-15-preview/automation/dscconfiguration.go index 6963bb010ac6..f6cfb2d98cdc 100644 --- a/services/automation/mgmt/2017-05-15-preview/automation/dscconfiguration.go +++ b/services/automation/mgmt/2017-05-15-preview/automation/dscconfiguration.go @@ -442,3 +442,82 @@ func (client DscConfigurationClient) ListByAutomationAccountComplete(ctx context result.page, err = client.ListByAutomationAccount(ctx, automationAccountName) return } + +// Update create the configuration identified by configuration name. +// +// automationAccountName is the automation account name. configurationName is the create or update parameters for +// configuration. parameters is the create or update parameters for configuration. +func (client DscConfigurationClient) Update(ctx context.Context, automationAccountName string, configurationName string, parameters *DscConfigurationUpdateParameters) (result DscConfiguration, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: client.ResourceGroupName, + Constraints: []validation.Constraint{{Target: "client.ResourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("automation.DscConfigurationClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, automationAccountName, configurationName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "automation.DscConfigurationClient", "Update", nil, "Failure preparing request") + return + } + + resp, err := client.UpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "automation.DscConfigurationClient", "Update", resp, "Failure sending request") + return + } + + result, err = client.UpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "automation.DscConfigurationClient", "Update", resp, "Failure responding to request") + } + + return +} + +// UpdatePreparer prepares the Update request. +func (client DscConfigurationClient) UpdatePreparer(ctx context.Context, automationAccountName string, configurationName string, parameters *DscConfigurationUpdateParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "automationAccountName": autorest.Encode("path", automationAccountName), + "configurationName": autorest.Encode("path", configurationName), + "resourceGroupName": autorest.Encode("path", client.ResourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2015-10-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/configurations/{configurationName}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + if parameters != nil { + preparer = autorest.DecoratePreparer(preparer, + autorest.WithJSON(parameters)) + } + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client DscConfigurationClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client DscConfigurationClient) UpdateResponder(resp *http.Response) (result DscConfiguration, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/automation/mgmt/2017-05-15-preview/automation/models.go b/services/automation/mgmt/2017-05-15-preview/automation/models.go index bc3ac79fcb1d..b31284476bc0 100644 --- a/services/automation/mgmt/2017-05-15-preview/automation/models.go +++ b/services/automation/mgmt/2017-05-15-preview/automation/models.go @@ -3391,6 +3391,73 @@ func (dcp DscConfigurationProperties) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// DscConfigurationUpdateParameters the parameters supplied to the create or update configuration operation. +type DscConfigurationUpdateParameters struct { + // DscConfigurationCreateOrUpdateProperties - Gets or sets configuration create or update properties. + *DscConfigurationCreateOrUpdateProperties `json:"properties,omitempty"` + // Name - Gets or sets name of the resource. + Name *string `json:"name,omitempty"` + // Tags - Gets or sets the tags attached to the resource. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for DscConfigurationUpdateParameters. +func (dcup DscConfigurationUpdateParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if dcup.DscConfigurationCreateOrUpdateProperties != nil { + objectMap["properties"] = dcup.DscConfigurationCreateOrUpdateProperties + } + if dcup.Name != nil { + objectMap["name"] = dcup.Name + } + if dcup.Tags != nil { + objectMap["tags"] = dcup.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for DscConfigurationUpdateParameters struct. +func (dcup *DscConfigurationUpdateParameters) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var dscConfigurationCreateOrUpdateProperties DscConfigurationCreateOrUpdateProperties + err = json.Unmarshal(*v, &dscConfigurationCreateOrUpdateProperties) + if err != nil { + return err + } + dcup.DscConfigurationCreateOrUpdateProperties = &dscConfigurationCreateOrUpdateProperties + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + dcup.Name = &name + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + dcup.Tags = tags + } + } + } + + return nil +} + // DscMetaConfiguration definition of the DSC Meta Configuration. type DscMetaConfiguration struct { // ConfigurationModeFrequencyMins - Gets or sets the ConfigurationModeFrequencyMins value of the meta configuration.