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/tracing"
25	"net/http"
26)
27
28// OperationsClient is the automation Client
29type OperationsClient struct {
30	BaseClient
31}
32
33// NewOperationsClient creates an instance of the OperationsClient client.
34func NewOperationsClient(subscriptionID string) OperationsClient {
35	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
41	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// List lists all of the available Automation REST API operations.
45func (client OperationsClient) List(ctx context.Context) (result OperationListResult, err error) {
46	if tracing.IsEnabled() {
47		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
48		defer func() {
49			sc := -1
50			if result.Response.Response != nil {
51				sc = result.Response.Response.StatusCode
52			}
53			tracing.EndSpan(ctx, sc, err)
54		}()
55	}
56	req, err := client.ListPreparer(ctx)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "automation.OperationsClient", "List", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.ListSender(req)
63	if err != nil {
64		result.Response = autorest.Response{Response: resp}
65		err = autorest.NewErrorWithError(err, "automation.OperationsClient", "List", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.ListResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "automation.OperationsClient", "List", resp, "Failure responding to request")
72	}
73
74	return
75}
76
77// ListPreparer prepares the List request.
78func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
79	const APIVersion = "2015-10-31"
80	queryParameters := map[string]interface{}{
81		"api-version": APIVersion,
82	}
83
84	preparer := autorest.CreatePreparer(
85		autorest.AsGet(),
86		autorest.WithBaseURL(client.BaseURI),
87		autorest.WithPath("/providers/Microsoft.Automation/operations"),
88		autorest.WithQueryParameters(queryParameters))
89	return preparer.Prepare((&http.Request{}).WithContext(ctx))
90}
91
92// ListSender sends the List request. The method will close the
93// http.Response Body if it receives an error.
94func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
95	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
96}
97
98// ListResponder handles the response to the List request. The method always
99// closes the http.Response Body.
100func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
101	err = autorest.Respond(
102		resp,
103		client.ByInspecting(),
104		azure.WithErrorUnlessStatusCode(http.StatusOK),
105		autorest.ByUnmarshallingJSON(&result),
106		autorest.ByClosing())
107	result.Response = autorest.Response{Response: resp}
108	return
109}
110