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