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 "net/http" 27) 28 29// JobStreamClient is the automation Client 30type JobStreamClient struct { 31 BaseClient 32} 33 34// NewJobStreamClient creates an instance of the JobStreamClient client. 35func NewJobStreamClient(subscriptionID string) JobStreamClient { 36 return NewJobStreamClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewJobStreamClientWithBaseURI creates an instance of the JobStreamClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewJobStreamClientWithBaseURI(baseURI string, subscriptionID string) JobStreamClient { 42 return JobStreamClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Get retrieve the job stream identified by job stream id. 46// Parameters: 47// resourceGroupName - name of an Azure Resource group. 48// automationAccountName - the name of the automation account. 49// jobName - the job name. 50// jobStreamID - the job stream id. 51// clientRequestID - identifies this specific client request. 52func (client JobStreamClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, jobStreamID string, clientRequestID string) (result JobStream, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/JobStreamClient.Get") 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.JobStreamClient", "Get", err.Error()) 69 } 70 71 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, jobName, jobStreamID, clientRequestID) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "Get", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.GetSender(req) 78 if err != nil { 79 result.Response = autorest.Response{Response: resp} 80 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "Get", resp, "Failure sending request") 81 return 82 } 83 84 result, err = client.GetResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "Get", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// GetPreparer prepares the Get request. 93func (client JobStreamClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, jobStreamID string, clientRequestID string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "automationAccountName": autorest.Encode("path", automationAccountName), 96 "jobName": autorest.Encode("path", jobName), 97 "jobStreamId": autorest.Encode("path", jobStreamID), 98 "resourceGroupName": autorest.Encode("path", resourceGroupName), 99 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 100 } 101 102 const APIVersion = "2017-05-15-preview" 103 queryParameters := map[string]interface{}{ 104 "api-version": APIVersion, 105 } 106 107 preparer := autorest.CreatePreparer( 108 autorest.AsGet(), 109 autorest.WithBaseURL(client.BaseURI), 110 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/streams/{jobStreamId}", pathParameters), 111 autorest.WithQueryParameters(queryParameters)) 112 if len(clientRequestID) > 0 { 113 preparer = autorest.DecoratePreparer(preparer, 114 autorest.WithHeader("clientRequestId", autorest.String(clientRequestID))) 115 } 116 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 117} 118 119// GetSender sends the Get request. The method will close the 120// http.Response Body if it receives an error. 121func (client JobStreamClient) GetSender(req *http.Request) (*http.Response, error) { 122 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 123} 124 125// GetResponder handles the response to the Get request. The method always 126// closes the http.Response Body. 127func (client JobStreamClient) GetResponder(resp *http.Response) (result JobStream, 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// ListByJob retrieve a list of jobs streams identified by job name. 139// Parameters: 140// resourceGroupName - name of an Azure Resource group. 141// automationAccountName - the name of the automation account. 142// jobName - the job name. 143// filter - the filter to apply on the operation. 144// clientRequestID - identifies this specific client request. 145func (client JobStreamClient) ListByJob(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, filter string, clientRequestID string) (result JobStreamListResultPage, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/JobStreamClient.ListByJob") 148 defer func() { 149 sc := -1 150 if result.jslr.Response.Response != nil { 151 sc = result.jslr.Response.Response.StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 if err := validation.Validate([]validation.Validation{ 157 {TargetValue: resourceGroupName, 158 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 159 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 160 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 161 return result, validation.NewError("automation.JobStreamClient", "ListByJob", err.Error()) 162 } 163 164 result.fn = client.listByJobNextResults 165 req, err := client.ListByJobPreparer(ctx, resourceGroupName, automationAccountName, jobName, filter, clientRequestID) 166 if err != nil { 167 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "ListByJob", nil, "Failure preparing request") 168 return 169 } 170 171 resp, err := client.ListByJobSender(req) 172 if err != nil { 173 result.jslr.Response = autorest.Response{Response: resp} 174 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "ListByJob", resp, "Failure sending request") 175 return 176 } 177 178 result.jslr, err = client.ListByJobResponder(resp) 179 if err != nil { 180 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "ListByJob", resp, "Failure responding to request") 181 } 182 183 return 184} 185 186// ListByJobPreparer prepares the ListByJob request. 187func (client JobStreamClient) ListByJobPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, filter string, clientRequestID string) (*http.Request, error) { 188 pathParameters := map[string]interface{}{ 189 "automationAccountName": autorest.Encode("path", automationAccountName), 190 "jobName": autorest.Encode("path", jobName), 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 203 preparer := autorest.CreatePreparer( 204 autorest.AsGet(), 205 autorest.WithBaseURL(client.BaseURI), 206 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/streams", pathParameters), 207 autorest.WithQueryParameters(queryParameters)) 208 if len(clientRequestID) > 0 { 209 preparer = autorest.DecoratePreparer(preparer, 210 autorest.WithHeader("clientRequestId", autorest.String(clientRequestID))) 211 } 212 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 213} 214 215// ListByJobSender sends the ListByJob request. The method will close the 216// http.Response Body if it receives an error. 217func (client JobStreamClient) ListByJobSender(req *http.Request) (*http.Response, error) { 218 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 219} 220 221// ListByJobResponder handles the response to the ListByJob request. The method always 222// closes the http.Response Body. 223func (client JobStreamClient) ListByJobResponder(resp *http.Response) (result JobStreamListResult, err error) { 224 err = autorest.Respond( 225 resp, 226 client.ByInspecting(), 227 azure.WithErrorUnlessStatusCode(http.StatusOK), 228 autorest.ByUnmarshallingJSON(&result), 229 autorest.ByClosing()) 230 result.Response = autorest.Response{Response: resp} 231 return 232} 233 234// listByJobNextResults retrieves the next set of results, if any. 235func (client JobStreamClient) listByJobNextResults(ctx context.Context, lastResults JobStreamListResult) (result JobStreamListResult, err error) { 236 req, err := lastResults.jobStreamListResultPreparer(ctx) 237 if err != nil { 238 return result, autorest.NewErrorWithError(err, "automation.JobStreamClient", "listByJobNextResults", nil, "Failure preparing next results request") 239 } 240 if req == nil { 241 return 242 } 243 resp, err := client.ListByJobSender(req) 244 if err != nil { 245 result.Response = autorest.Response{Response: resp} 246 return result, autorest.NewErrorWithError(err, "automation.JobStreamClient", "listByJobNextResults", resp, "Failure sending next results request") 247 } 248 result, err = client.ListByJobResponder(resp) 249 if err != nil { 250 err = autorest.NewErrorWithError(err, "automation.JobStreamClient", "listByJobNextResults", resp, "Failure responding to next results request") 251 } 252 return 253} 254 255// ListByJobComplete enumerates all values, automatically crossing page boundaries as required. 256func (client JobStreamClient) ListByJobComplete(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, filter string, clientRequestID string) (result JobStreamListResultIterator, err error) { 257 if tracing.IsEnabled() { 258 ctx = tracing.StartSpan(ctx, fqdn+"/JobStreamClient.ListByJob") 259 defer func() { 260 sc := -1 261 if result.Response().Response.Response != nil { 262 sc = result.page.Response().Response.Response.StatusCode 263 } 264 tracing.EndSpan(ctx, sc, err) 265 }() 266 } 267 result.page, err = client.ListByJob(ctx, resourceGroupName, automationAccountName, jobName, filter, clientRequestID) 268 return 269} 270