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