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// DscCompilationJobStreamClient is the automation Client
31type DscCompilationJobStreamClient struct {
32	BaseClient
33}
34
35// NewDscCompilationJobStreamClient creates an instance of the DscCompilationJobStreamClient client.
36func NewDscCompilationJobStreamClient(subscriptionID string) DscCompilationJobStreamClient {
37	return NewDscCompilationJobStreamClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewDscCompilationJobStreamClientWithBaseURI creates an instance of the DscCompilationJobStreamClient client using a
41// custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
42// Azure stack).
43func NewDscCompilationJobStreamClientWithBaseURI(baseURI string, subscriptionID string) DscCompilationJobStreamClient {
44	return DscCompilationJobStreamClient{NewWithBaseURI(baseURI, subscriptionID)}
45}
46
47// ListByJob retrieve all the job streams for the compilation Job.
48// Parameters:
49// resourceGroupName - name of an Azure Resource group.
50// automationAccountName - the name of the automation account.
51// jobID - the job id.
52func (client DscCompilationJobStreamClient) ListByJob(ctx context.Context, resourceGroupName string, automationAccountName string, jobID uuid.UUID) (result JobStreamListResult, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/DscCompilationJobStreamClient.ListByJob")
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.DscCompilationJobStreamClient", "ListByJob", err.Error())
69	}
70
71	req, err := client.ListByJobPreparer(ctx, resourceGroupName, automationAccountName, jobID)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "automation.DscCompilationJobStreamClient", "ListByJob", nil, "Failure preparing request")
74		return
75	}
76
77	resp, err := client.ListByJobSender(req)
78	if err != nil {
79		result.Response = autorest.Response{Response: resp}
80		err = autorest.NewErrorWithError(err, "automation.DscCompilationJobStreamClient", "ListByJob", resp, "Failure sending request")
81		return
82	}
83
84	result, err = client.ListByJobResponder(resp)
85	if err != nil {
86		err = autorest.NewErrorWithError(err, "automation.DscCompilationJobStreamClient", "ListByJob", resp, "Failure responding to request")
87	}
88
89	return
90}
91
92// ListByJobPreparer prepares the ListByJob request.
93func (client DscCompilationJobStreamClient) ListByJobPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobID uuid.UUID) (*http.Request, error) {
94	pathParameters := map[string]interface{}{
95		"automationAccountName": autorest.Encode("path", automationAccountName),
96		"jobId":                 autorest.Encode("path", jobID),
97		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
98		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
99	}
100
101	const APIVersion = "2015-10-31"
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}/compilationjobs/{jobId}/streams/", pathParameters),
110		autorest.WithQueryParameters(queryParameters))
111	return preparer.Prepare((&http.Request{}).WithContext(ctx))
112}
113
114// ListByJobSender sends the ListByJob request. The method will close the
115// http.Response Body if it receives an error.
116func (client DscCompilationJobStreamClient) ListByJobSender(req *http.Request) (*http.Response, error) {
117	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
118}
119
120// ListByJobResponder handles the response to the ListByJob request. The method always
121// closes the http.Response Body.
122func (client DscCompilationJobStreamClient) ListByJobResponder(resp *http.Response) (result JobStreamListResult, err error) {
123	err = autorest.Respond(
124		resp,
125		client.ByInspecting(),
126		azure.WithErrorUnlessStatusCode(http.StatusOK),
127		autorest.ByUnmarshallingJSON(&result),
128		autorest.ByClosing())
129	result.Response = autorest.Response{Response: resp}
130	return
131}
132