1package dtl
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	"net/http"
25)
26
27// ArtifactSourceClient is the azure DevTest Labs REST API version 2015-05-21-preview.
28type ArtifactSourceClient struct {
29	BaseClient
30}
31
32// NewArtifactSourceClient creates an instance of the ArtifactSourceClient client.
33func NewArtifactSourceClient(subscriptionID string) ArtifactSourceClient {
34	return NewArtifactSourceClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewArtifactSourceClientWithBaseURI creates an instance of the ArtifactSourceClient client.
38func NewArtifactSourceClientWithBaseURI(baseURI string, subscriptionID string) ArtifactSourceClient {
39	return ArtifactSourceClient{NewWithBaseURI(baseURI, subscriptionID)}
40}
41
42// CreateOrUpdateResource create or replace an existing artifact source.
43// Parameters:
44// resourceGroupName - the name of the resource group.
45// labName - the name of the lab.
46// name - the name of the artifact source.
47func (client ArtifactSourceClient) CreateOrUpdateResource(ctx context.Context, resourceGroupName string, labName string, name string, artifactSource ArtifactSource) (result ArtifactSource, err error) {
48	req, err := client.CreateOrUpdateResourcePreparer(ctx, resourceGroupName, labName, name, artifactSource)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "CreateOrUpdateResource", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.CreateOrUpdateResourceSender(req)
55	if err != nil {
56		result.Response = autorest.Response{Response: resp}
57		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "CreateOrUpdateResource", resp, "Failure sending request")
58		return
59	}
60
61	result, err = client.CreateOrUpdateResourceResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "CreateOrUpdateResource", resp, "Failure responding to request")
64	}
65
66	return
67}
68
69// CreateOrUpdateResourcePreparer prepares the CreateOrUpdateResource request.
70func (client ArtifactSourceClient) CreateOrUpdateResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, artifactSource ArtifactSource) (*http.Request, error) {
71	pathParameters := map[string]interface{}{
72		"labName":           autorest.Encode("path", labName),
73		"name":              autorest.Encode("path", name),
74		"resourceGroupName": autorest.Encode("path", resourceGroupName),
75		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
76	}
77
78	const APIVersion = "2015-05-21-preview"
79	queryParameters := map[string]interface{}{
80		"api-version": APIVersion,
81	}
82
83	preparer := autorest.CreatePreparer(
84		autorest.AsContentType("application/json; charset=utf-8"),
85		autorest.AsPut(),
86		autorest.WithBaseURL(client.BaseURI),
87		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}", pathParameters),
88		autorest.WithJSON(artifactSource),
89		autorest.WithQueryParameters(queryParameters))
90	return preparer.Prepare((&http.Request{}).WithContext(ctx))
91}
92
93// CreateOrUpdateResourceSender sends the CreateOrUpdateResource request. The method will close the
94// http.Response Body if it receives an error.
95func (client ArtifactSourceClient) CreateOrUpdateResourceSender(req *http.Request) (*http.Response, error) {
96	return autorest.SendWithSender(client, req,
97		azure.DoRetryWithRegistration(client.Client))
98}
99
100// CreateOrUpdateResourceResponder handles the response to the CreateOrUpdateResource request. The method always
101// closes the http.Response Body.
102func (client ArtifactSourceClient) CreateOrUpdateResourceResponder(resp *http.Response) (result ArtifactSource, err error) {
103	err = autorest.Respond(
104		resp,
105		client.ByInspecting(),
106		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
107		autorest.ByUnmarshallingJSON(&result),
108		autorest.ByClosing())
109	result.Response = autorest.Response{Response: resp}
110	return
111}
112
113// DeleteResource delete artifact source.
114// Parameters:
115// resourceGroupName - the name of the resource group.
116// labName - the name of the lab.
117// name - the name of the artifact source.
118func (client ArtifactSourceClient) DeleteResource(ctx context.Context, resourceGroupName string, labName string, name string) (result autorest.Response, err error) {
119	req, err := client.DeleteResourcePreparer(ctx, resourceGroupName, labName, name)
120	if err != nil {
121		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "DeleteResource", nil, "Failure preparing request")
122		return
123	}
124
125	resp, err := client.DeleteResourceSender(req)
126	if err != nil {
127		result.Response = resp
128		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "DeleteResource", resp, "Failure sending request")
129		return
130	}
131
132	result, err = client.DeleteResourceResponder(resp)
133	if err != nil {
134		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "DeleteResource", resp, "Failure responding to request")
135	}
136
137	return
138}
139
140// DeleteResourcePreparer prepares the DeleteResource request.
141func (client ArtifactSourceClient) DeleteResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
142	pathParameters := map[string]interface{}{
143		"labName":           autorest.Encode("path", labName),
144		"name":              autorest.Encode("path", name),
145		"resourceGroupName": autorest.Encode("path", resourceGroupName),
146		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
147	}
148
149	const APIVersion = "2015-05-21-preview"
150	queryParameters := map[string]interface{}{
151		"api-version": APIVersion,
152	}
153
154	preparer := autorest.CreatePreparer(
155		autorest.AsDelete(),
156		autorest.WithBaseURL(client.BaseURI),
157		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}", pathParameters),
158		autorest.WithQueryParameters(queryParameters))
159	return preparer.Prepare((&http.Request{}).WithContext(ctx))
160}
161
162// DeleteResourceSender sends the DeleteResource request. The method will close the
163// http.Response Body if it receives an error.
164func (client ArtifactSourceClient) DeleteResourceSender(req *http.Request) (*http.Response, error) {
165	return autorest.SendWithSender(client, req,
166		azure.DoRetryWithRegistration(client.Client))
167}
168
169// DeleteResourceResponder handles the response to the DeleteResource request. The method always
170// closes the http.Response Body.
171func (client ArtifactSourceClient) DeleteResourceResponder(resp *http.Response) (result autorest.Response, err error) {
172	err = autorest.Respond(
173		resp,
174		client.ByInspecting(),
175		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
176		autorest.ByClosing())
177	result.Response = resp
178	return
179}
180
181// GetResource get artifact source.
182// Parameters:
183// resourceGroupName - the name of the resource group.
184// labName - the name of the lab.
185// name - the name of the artifact source.
186func (client ArtifactSourceClient) GetResource(ctx context.Context, resourceGroupName string, labName string, name string) (result ArtifactSource, err error) {
187	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, name)
188	if err != nil {
189		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "GetResource", nil, "Failure preparing request")
190		return
191	}
192
193	resp, err := client.GetResourceSender(req)
194	if err != nil {
195		result.Response = autorest.Response{Response: resp}
196		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "GetResource", resp, "Failure sending request")
197		return
198	}
199
200	result, err = client.GetResourceResponder(resp)
201	if err != nil {
202		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "GetResource", resp, "Failure responding to request")
203	}
204
205	return
206}
207
208// GetResourcePreparer prepares the GetResource request.
209func (client ArtifactSourceClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
210	pathParameters := map[string]interface{}{
211		"labName":           autorest.Encode("path", labName),
212		"name":              autorest.Encode("path", name),
213		"resourceGroupName": autorest.Encode("path", resourceGroupName),
214		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
215	}
216
217	const APIVersion = "2015-05-21-preview"
218	queryParameters := map[string]interface{}{
219		"api-version": APIVersion,
220	}
221
222	preparer := autorest.CreatePreparer(
223		autorest.AsGet(),
224		autorest.WithBaseURL(client.BaseURI),
225		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}", pathParameters),
226		autorest.WithQueryParameters(queryParameters))
227	return preparer.Prepare((&http.Request{}).WithContext(ctx))
228}
229
230// GetResourceSender sends the GetResource request. The method will close the
231// http.Response Body if it receives an error.
232func (client ArtifactSourceClient) GetResourceSender(req *http.Request) (*http.Response, error) {
233	return autorest.SendWithSender(client, req,
234		azure.DoRetryWithRegistration(client.Client))
235}
236
237// GetResourceResponder handles the response to the GetResource request. The method always
238// closes the http.Response Body.
239func (client ArtifactSourceClient) GetResourceResponder(resp *http.Response) (result ArtifactSource, err error) {
240	err = autorest.Respond(
241		resp,
242		client.ByInspecting(),
243		azure.WithErrorUnlessStatusCode(http.StatusOK),
244		autorest.ByUnmarshallingJSON(&result),
245		autorest.ByClosing())
246	result.Response = autorest.Response{Response: resp}
247	return
248}
249
250// List list artifact sources.
251// Parameters:
252// resourceGroupName - the name of the resource group.
253// labName - the name of the lab.
254// filter - the filter to apply on the operation.
255func (client ArtifactSourceClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationArtifactSourcePage, err error) {
256	result.fn = client.listNextResults
257	req, err := client.ListPreparer(ctx, resourceGroupName, labName, filter, top, orderBy)
258	if err != nil {
259		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "List", nil, "Failure preparing request")
260		return
261	}
262
263	resp, err := client.ListSender(req)
264	if err != nil {
265		result.rwcas.Response = autorest.Response{Response: resp}
266		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "List", resp, "Failure sending request")
267		return
268	}
269
270	result.rwcas, err = client.ListResponder(resp)
271	if err != nil {
272		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "List", resp, "Failure responding to request")
273	}
274
275	return
276}
277
278// ListPreparer prepares the List request.
279func (client ArtifactSourceClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (*http.Request, error) {
280	pathParameters := map[string]interface{}{
281		"labName":           autorest.Encode("path", labName),
282		"resourceGroupName": autorest.Encode("path", resourceGroupName),
283		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
284	}
285
286	const APIVersion = "2015-05-21-preview"
287	queryParameters := map[string]interface{}{
288		"api-version": APIVersion,
289	}
290	if len(filter) > 0 {
291		queryParameters["$filter"] = autorest.Encode("query", filter)
292	}
293	if top != nil {
294		queryParameters["$top"] = autorest.Encode("query", *top)
295	}
296	if len(orderBy) > 0 {
297		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
298	}
299
300	preparer := autorest.CreatePreparer(
301		autorest.AsGet(),
302		autorest.WithBaseURL(client.BaseURI),
303		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources", pathParameters),
304		autorest.WithQueryParameters(queryParameters))
305	return preparer.Prepare((&http.Request{}).WithContext(ctx))
306}
307
308// ListSender sends the List request. The method will close the
309// http.Response Body if it receives an error.
310func (client ArtifactSourceClient) ListSender(req *http.Request) (*http.Response, error) {
311	return autorest.SendWithSender(client, req,
312		azure.DoRetryWithRegistration(client.Client))
313}
314
315// ListResponder handles the response to the List request. The method always
316// closes the http.Response Body.
317func (client ArtifactSourceClient) ListResponder(resp *http.Response) (result ResponseWithContinuationArtifactSource, err error) {
318	err = autorest.Respond(
319		resp,
320		client.ByInspecting(),
321		azure.WithErrorUnlessStatusCode(http.StatusOK),
322		autorest.ByUnmarshallingJSON(&result),
323		autorest.ByClosing())
324	result.Response = autorest.Response{Response: resp}
325	return
326}
327
328// listNextResults retrieves the next set of results, if any.
329func (client ArtifactSourceClient) listNextResults(lastResults ResponseWithContinuationArtifactSource) (result ResponseWithContinuationArtifactSource, err error) {
330	req, err := lastResults.responseWithContinuationArtifactSourcePreparer()
331	if err != nil {
332		return result, autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "listNextResults", nil, "Failure preparing next results request")
333	}
334	if req == nil {
335		return
336	}
337	resp, err := client.ListSender(req)
338	if err != nil {
339		result.Response = autorest.Response{Response: resp}
340		return result, autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "listNextResults", resp, "Failure sending next results request")
341	}
342	result, err = client.ListResponder(resp)
343	if err != nil {
344		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "listNextResults", resp, "Failure responding to next results request")
345	}
346	return
347}
348
349// ListComplete enumerates all values, automatically crossing page boundaries as required.
350func (client ArtifactSourceClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationArtifactSourceIterator, err error) {
351	result.page, err = client.List(ctx, resourceGroupName, labName, filter, top, orderBy)
352	return
353}
354
355// PatchResource modify properties of artifact sources.
356// Parameters:
357// resourceGroupName - the name of the resource group.
358// labName - the name of the lab.
359// name - the name of the artifact source.
360func (client ArtifactSourceClient) PatchResource(ctx context.Context, resourceGroupName string, labName string, name string, artifactSource ArtifactSource) (result ArtifactSource, err error) {
361	req, err := client.PatchResourcePreparer(ctx, resourceGroupName, labName, name, artifactSource)
362	if err != nil {
363		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "PatchResource", nil, "Failure preparing request")
364		return
365	}
366
367	resp, err := client.PatchResourceSender(req)
368	if err != nil {
369		result.Response = autorest.Response{Response: resp}
370		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "PatchResource", resp, "Failure sending request")
371		return
372	}
373
374	result, err = client.PatchResourceResponder(resp)
375	if err != nil {
376		err = autorest.NewErrorWithError(err, "dtl.ArtifactSourceClient", "PatchResource", resp, "Failure responding to request")
377	}
378
379	return
380}
381
382// PatchResourcePreparer prepares the PatchResource request.
383func (client ArtifactSourceClient) PatchResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, artifactSource ArtifactSource) (*http.Request, error) {
384	pathParameters := map[string]interface{}{
385		"labName":           autorest.Encode("path", labName),
386		"name":              autorest.Encode("path", name),
387		"resourceGroupName": autorest.Encode("path", resourceGroupName),
388		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
389	}
390
391	const APIVersion = "2015-05-21-preview"
392	queryParameters := map[string]interface{}{
393		"api-version": APIVersion,
394	}
395
396	preparer := autorest.CreatePreparer(
397		autorest.AsContentType("application/json; charset=utf-8"),
398		autorest.AsPatch(),
399		autorest.WithBaseURL(client.BaseURI),
400		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}", pathParameters),
401		autorest.WithJSON(artifactSource),
402		autorest.WithQueryParameters(queryParameters))
403	return preparer.Prepare((&http.Request{}).WithContext(ctx))
404}
405
406// PatchResourceSender sends the PatchResource request. The method will close the
407// http.Response Body if it receives an error.
408func (client ArtifactSourceClient) PatchResourceSender(req *http.Request) (*http.Response, error) {
409	return autorest.SendWithSender(client, req,
410		azure.DoRetryWithRegistration(client.Client))
411}
412
413// PatchResourceResponder handles the response to the PatchResource request. The method always
414// closes the http.Response Body.
415func (client ArtifactSourceClient) PatchResourceResponder(resp *http.Response) (result ArtifactSource, err error) {
416	err = autorest.Respond(
417		resp,
418		client.ByInspecting(),
419		azure.WithErrorUnlessStatusCode(http.StatusOK),
420		autorest.ByUnmarshallingJSON(&result),
421		autorest.ByClosing())
422	result.Response = autorest.Response{Response: resp}
423	return
424}
425