1package automation
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"github.com/gofrs/uuid"
16	"net/http"
17)
18
19// SoftwareUpdateConfigurationRunsClient is the automation Client
20type SoftwareUpdateConfigurationRunsClient struct {
21	BaseClient
22}
23
24// NewSoftwareUpdateConfigurationRunsClient creates an instance of the SoftwareUpdateConfigurationRunsClient client.
25func NewSoftwareUpdateConfigurationRunsClient(subscriptionID string) SoftwareUpdateConfigurationRunsClient {
26	return NewSoftwareUpdateConfigurationRunsClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewSoftwareUpdateConfigurationRunsClientWithBaseURI creates an instance of the SoftwareUpdateConfigurationRunsClient
30// client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
31// (sovereign clouds, Azure stack).
32func NewSoftwareUpdateConfigurationRunsClientWithBaseURI(baseURI string, subscriptionID string) SoftwareUpdateConfigurationRunsClient {
33	return SoftwareUpdateConfigurationRunsClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// GetByID get a single software update configuration Run by Id.
37// Parameters:
38// resourceGroupName - name of an Azure Resource group.
39// automationAccountName - the name of the automation account.
40// softwareUpdateConfigurationRunID - the Id of the software update configuration run.
41// clientRequestID - identifies this specific client request.
42func (client SoftwareUpdateConfigurationRunsClient) GetByID(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationRunID uuid.UUID, clientRequestID string) (result SoftwareUpdateConfigurationRun, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareUpdateConfigurationRunsClient.GetByID")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	if err := validation.Validate([]validation.Validation{
54		{TargetValue: resourceGroupName,
55			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
56				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
57				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
58		return result, validation.NewError("automation.SoftwareUpdateConfigurationRunsClient", "GetByID", err.Error())
59	}
60
61	req, err := client.GetByIDPreparer(ctx, resourceGroupName, automationAccountName, softwareUpdateConfigurationRunID, clientRequestID)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationRunsClient", "GetByID", nil, "Failure preparing request")
64		return
65	}
66
67	resp, err := client.GetByIDSender(req)
68	if err != nil {
69		result.Response = autorest.Response{Response: resp}
70		err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationRunsClient", "GetByID", resp, "Failure sending request")
71		return
72	}
73
74	result, err = client.GetByIDResponder(resp)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationRunsClient", "GetByID", resp, "Failure responding to request")
77		return
78	}
79
80	return
81}
82
83// GetByIDPreparer prepares the GetByID request.
84func (client SoftwareUpdateConfigurationRunsClient) GetByIDPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, softwareUpdateConfigurationRunID uuid.UUID, clientRequestID string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"automationAccountName":            autorest.Encode("path", automationAccountName),
87		"resourceGroupName":                autorest.Encode("path", resourceGroupName),
88		"softwareUpdateConfigurationRunId": autorest.Encode("path", softwareUpdateConfigurationRunID),
89		"subscriptionId":                   autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2019-06-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsGet(),
99		autorest.WithBaseURL(client.BaseURI),
100		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/softwareUpdateConfigurationRuns/{softwareUpdateConfigurationRunId}", pathParameters),
101		autorest.WithQueryParameters(queryParameters))
102	if len(clientRequestID) > 0 {
103		preparer = autorest.DecoratePreparer(preparer,
104			autorest.WithHeader("clientRequestId", autorest.String(clientRequestID)))
105	}
106	return preparer.Prepare((&http.Request{}).WithContext(ctx))
107}
108
109// GetByIDSender sends the GetByID request. The method will close the
110// http.Response Body if it receives an error.
111func (client SoftwareUpdateConfigurationRunsClient) GetByIDSender(req *http.Request) (*http.Response, error) {
112	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
113}
114
115// GetByIDResponder handles the response to the GetByID request. The method always
116// closes the http.Response Body.
117func (client SoftwareUpdateConfigurationRunsClient) GetByIDResponder(resp *http.Response) (result SoftwareUpdateConfigurationRun, err error) {
118	err = autorest.Respond(
119		resp,
120		azure.WithErrorUnlessStatusCode(http.StatusOK),
121		autorest.ByUnmarshallingJSON(&result),
122		autorest.ByClosing())
123	result.Response = autorest.Response{Response: resp}
124	return
125}
126
127// List return list of software update configuration runs
128// Parameters:
129// resourceGroupName - name of an Azure Resource group.
130// automationAccountName - the name of the automation account.
131// clientRequestID - identifies this specific client request.
132// filter - the filter to apply on the operation. You can use the following filters: 'properties/osType',
133// 'properties/status', 'properties/startTime', and 'properties/softwareUpdateConfiguration/name'
134// skip - number of entries you skip before returning results
135// top - maximum number of entries returned in the results collection
136func (client SoftwareUpdateConfigurationRunsClient) List(ctx context.Context, resourceGroupName string, automationAccountName string, clientRequestID string, filter string, skip string, top string) (result SoftwareUpdateConfigurationRunListResult, err error) {
137	if tracing.IsEnabled() {
138		ctx = tracing.StartSpan(ctx, fqdn+"/SoftwareUpdateConfigurationRunsClient.List")
139		defer func() {
140			sc := -1
141			if result.Response.Response != nil {
142				sc = result.Response.Response.StatusCode
143			}
144			tracing.EndSpan(ctx, sc, err)
145		}()
146	}
147	if err := validation.Validate([]validation.Validation{
148		{TargetValue: resourceGroupName,
149			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
150				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
151				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
152		return result, validation.NewError("automation.SoftwareUpdateConfigurationRunsClient", "List", err.Error())
153	}
154
155	req, err := client.ListPreparer(ctx, resourceGroupName, automationAccountName, clientRequestID, filter, skip, top)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationRunsClient", "List", nil, "Failure preparing request")
158		return
159	}
160
161	resp, err := client.ListSender(req)
162	if err != nil {
163		result.Response = autorest.Response{Response: resp}
164		err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationRunsClient", "List", resp, "Failure sending request")
165		return
166	}
167
168	result, err = client.ListResponder(resp)
169	if err != nil {
170		err = autorest.NewErrorWithError(err, "automation.SoftwareUpdateConfigurationRunsClient", "List", resp, "Failure responding to request")
171		return
172	}
173
174	return
175}
176
177// ListPreparer prepares the List request.
178func (client SoftwareUpdateConfigurationRunsClient) ListPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, clientRequestID string, filter string, skip string, top string) (*http.Request, error) {
179	pathParameters := map[string]interface{}{
180		"automationAccountName": autorest.Encode("path", automationAccountName),
181		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
182		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
183	}
184
185	const APIVersion = "2019-06-01"
186	queryParameters := map[string]interface{}{
187		"api-version": APIVersion,
188	}
189	if len(filter) > 0 {
190		queryParameters["$filter"] = autorest.Encode("query", filter)
191	}
192	if len(skip) > 0 {
193		queryParameters["$skip"] = autorest.Encode("query", skip)
194	}
195	if len(top) > 0 {
196		queryParameters["$top"] = autorest.Encode("query", top)
197	}
198
199	preparer := autorest.CreatePreparer(
200		autorest.AsGet(),
201		autorest.WithBaseURL(client.BaseURI),
202		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/softwareUpdateConfigurationRuns", pathParameters),
203		autorest.WithQueryParameters(queryParameters))
204	if len(clientRequestID) > 0 {
205		preparer = autorest.DecoratePreparer(preparer,
206			autorest.WithHeader("clientRequestId", autorest.String(clientRequestID)))
207	}
208	return preparer.Prepare((&http.Request{}).WithContext(ctx))
209}
210
211// ListSender sends the List request. The method will close the
212// http.Response Body if it receives an error.
213func (client SoftwareUpdateConfigurationRunsClient) ListSender(req *http.Request) (*http.Response, error) {
214	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
215}
216
217// ListResponder handles the response to the List request. The method always
218// closes the http.Response Body.
219func (client SoftwareUpdateConfigurationRunsClient) ListResponder(resp *http.Response) (result SoftwareUpdateConfigurationRunListResult, err error) {
220	err = autorest.Respond(
221		resp,
222		azure.WithErrorUnlessStatusCode(http.StatusOK),
223		autorest.ByUnmarshallingJSON(&result),
224		autorest.ByClosing())
225	result.Response = autorest.Response{Response: resp}
226	return
227}
228