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/satori/go.uuid" 26 "net/http" 27) 28 29// DscCompilationJobClient is the automation Client 30type DscCompilationJobClient struct { 31 BaseClient 32} 33 34// NewDscCompilationJobClient creates an instance of the DscCompilationJobClient client. 35func NewDscCompilationJobClient(subscriptionID string) DscCompilationJobClient { 36 return NewDscCompilationJobClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewDscCompilationJobClientWithBaseURI creates an instance of the DscCompilationJobClient client. 40func NewDscCompilationJobClientWithBaseURI(baseURI string, subscriptionID string) DscCompilationJobClient { 41 return DscCompilationJobClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// Create creates the Dsc compilation job of the configuration. 45// Parameters: 46// resourceGroupName - name of an Azure Resource group. 47// automationAccountName - the name of the automation account. 48// compilationJobID - the the DSC configuration Id. 49// parameters - the parameters supplied to the create compilation job operation. 50func (client DscCompilationJobClient) Create(ctx context.Context, resourceGroupName string, automationAccountName string, compilationJobID uuid.UUID, parameters DscCompilationJobCreateParameters) (result DscCompilationJob, err error) { 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: resourceGroupName, 53 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 54 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 55 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 56 {TargetValue: parameters, 57 Constraints: []validation.Constraint{{Target: "parameters.DscCompilationJobCreateProperties", Name: validation.Null, Rule: true, 58 Chain: []validation.Constraint{{Target: "parameters.DscCompilationJobCreateProperties.Configuration", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 59 return result, validation.NewError("automation.DscCompilationJobClient", "Create", err.Error()) 60 } 61 62 req, err := client.CreatePreparer(ctx, resourceGroupName, automationAccountName, compilationJobID, parameters) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "Create", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.CreateSender(req) 69 if err != nil { 70 result.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "Create", resp, "Failure sending request") 72 return 73 } 74 75 result, err = client.CreateResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "Create", resp, "Failure responding to request") 78 } 79 80 return 81} 82 83// CreatePreparer prepares the Create request. 84func (client DscCompilationJobClient) CreatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, compilationJobID uuid.UUID, parameters DscCompilationJobCreateParameters) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "automationAccountName": autorest.Encode("path", automationAccountName), 87 "compilationJobId": autorest.Encode("path", compilationJobID), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 } 91 92 const APIVersion = "2015-10-31" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 } 96 97 preparer := autorest.CreatePreparer( 98 autorest.AsContentType("application/json; charset=utf-8"), 99 autorest.AsPut(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/compilationjobs/{compilationJobId}", pathParameters), 102 autorest.WithJSON(parameters), 103 autorest.WithQueryParameters(queryParameters)) 104 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 105} 106 107// CreateSender sends the Create request. The method will close the 108// http.Response Body if it receives an error. 109func (client DscCompilationJobClient) CreateSender(req *http.Request) (*http.Response, error) { 110 return autorest.SendWithSender(client, req, 111 azure.DoRetryWithRegistration(client.Client)) 112} 113 114// CreateResponder handles the response to the Create request. The method always 115// closes the http.Response Body. 116func (client DscCompilationJobClient) CreateResponder(resp *http.Response) (result DscCompilationJob, err error) { 117 err = autorest.Respond( 118 resp, 119 client.ByInspecting(), 120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// Get retrieve the Dsc configuration compilation job identified by job id. 128// Parameters: 129// resourceGroupName - name of an Azure Resource group. 130// automationAccountName - the name of the automation account. 131// compilationJobID - the Dsc configuration compilation job id. 132func (client DscCompilationJobClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, compilationJobID uuid.UUID) (result DscCompilationJob, err error) { 133 if err := validation.Validate([]validation.Validation{ 134 {TargetValue: resourceGroupName, 135 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 136 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 137 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 138 return result, validation.NewError("automation.DscCompilationJobClient", "Get", err.Error()) 139 } 140 141 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, compilationJobID) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "Get", nil, "Failure preparing request") 144 return 145 } 146 147 resp, err := client.GetSender(req) 148 if err != nil { 149 result.Response = autorest.Response{Response: resp} 150 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "Get", resp, "Failure sending request") 151 return 152 } 153 154 result, err = client.GetResponder(resp) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "Get", resp, "Failure responding to request") 157 } 158 159 return 160} 161 162// GetPreparer prepares the Get request. 163func (client DscCompilationJobClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, compilationJobID uuid.UUID) (*http.Request, error) { 164 pathParameters := map[string]interface{}{ 165 "automationAccountName": autorest.Encode("path", automationAccountName), 166 "compilationJobId": autorest.Encode("path", compilationJobID), 167 "resourceGroupName": autorest.Encode("path", resourceGroupName), 168 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 169 } 170 171 const APIVersion = "2015-10-31" 172 queryParameters := map[string]interface{}{ 173 "api-version": APIVersion, 174 } 175 176 preparer := autorest.CreatePreparer( 177 autorest.AsGet(), 178 autorest.WithBaseURL(client.BaseURI), 179 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/compilationjobs/{compilationJobId}", pathParameters), 180 autorest.WithQueryParameters(queryParameters)) 181 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 182} 183 184// GetSender sends the Get request. The method will close the 185// http.Response Body if it receives an error. 186func (client DscCompilationJobClient) GetSender(req *http.Request) (*http.Response, error) { 187 return autorest.SendWithSender(client, req, 188 azure.DoRetryWithRegistration(client.Client)) 189} 190 191// GetResponder handles the response to the Get request. The method always 192// closes the http.Response Body. 193func (client DscCompilationJobClient) GetResponder(resp *http.Response) (result DscCompilationJob, err error) { 194 err = autorest.Respond( 195 resp, 196 client.ByInspecting(), 197 azure.WithErrorUnlessStatusCode(http.StatusOK), 198 autorest.ByUnmarshallingJSON(&result), 199 autorest.ByClosing()) 200 result.Response = autorest.Response{Response: resp} 201 return 202} 203 204// GetStream retrieve the job stream identified by job stream id. 205// Parameters: 206// resourceGroupName - name of an Azure Resource group. 207// automationAccountName - the name of the automation account. 208// jobID - the job id. 209// jobStreamID - the job stream id. 210func (client DscCompilationJobClient) GetStream(ctx context.Context, resourceGroupName string, automationAccountName string, jobID uuid.UUID, jobStreamID string) (result JobStream, err error) { 211 if err := validation.Validate([]validation.Validation{ 212 {TargetValue: resourceGroupName, 213 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 214 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 215 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 216 return result, validation.NewError("automation.DscCompilationJobClient", "GetStream", err.Error()) 217 } 218 219 req, err := client.GetStreamPreparer(ctx, resourceGroupName, automationAccountName, jobID, jobStreamID) 220 if err != nil { 221 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "GetStream", nil, "Failure preparing request") 222 return 223 } 224 225 resp, err := client.GetStreamSender(req) 226 if err != nil { 227 result.Response = autorest.Response{Response: resp} 228 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "GetStream", resp, "Failure sending request") 229 return 230 } 231 232 result, err = client.GetStreamResponder(resp) 233 if err != nil { 234 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "GetStream", resp, "Failure responding to request") 235 } 236 237 return 238} 239 240// GetStreamPreparer prepares the GetStream request. 241func (client DscCompilationJobClient) GetStreamPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobID uuid.UUID, jobStreamID string) (*http.Request, error) { 242 pathParameters := map[string]interface{}{ 243 "automationAccountName": autorest.Encode("path", automationAccountName), 244 "jobId": autorest.Encode("path", jobID), 245 "jobStreamId": autorest.Encode("path", jobStreamID), 246 "resourceGroupName": autorest.Encode("path", resourceGroupName), 247 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 248 } 249 250 const APIVersion = "2015-10-31" 251 queryParameters := map[string]interface{}{ 252 "api-version": APIVersion, 253 } 254 255 preparer := autorest.CreatePreparer( 256 autorest.AsGet(), 257 autorest.WithBaseURL(client.BaseURI), 258 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/compilationjobs/{jobId}/streams/{jobStreamId}", pathParameters), 259 autorest.WithQueryParameters(queryParameters)) 260 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 261} 262 263// GetStreamSender sends the GetStream request. The method will close the 264// http.Response Body if it receives an error. 265func (client DscCompilationJobClient) GetStreamSender(req *http.Request) (*http.Response, error) { 266 return autorest.SendWithSender(client, req, 267 azure.DoRetryWithRegistration(client.Client)) 268} 269 270// GetStreamResponder handles the response to the GetStream request. The method always 271// closes the http.Response Body. 272func (client DscCompilationJobClient) GetStreamResponder(resp *http.Response) (result JobStream, err error) { 273 err = autorest.Respond( 274 resp, 275 client.ByInspecting(), 276 azure.WithErrorUnlessStatusCode(http.StatusOK), 277 autorest.ByUnmarshallingJSON(&result), 278 autorest.ByClosing()) 279 result.Response = autorest.Response{Response: resp} 280 return 281} 282 283// ListByAutomationAccount retrieve a list of dsc compilation jobs. 284// Parameters: 285// resourceGroupName - name of an Azure Resource group. 286// automationAccountName - the name of the automation account. 287// filter - the filter to apply on the operation. 288func (client DscCompilationJobClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result DscCompilationJobListResultPage, err error) { 289 if err := validation.Validate([]validation.Validation{ 290 {TargetValue: resourceGroupName, 291 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 292 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 293 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 294 return result, validation.NewError("automation.DscCompilationJobClient", "ListByAutomationAccount", err.Error()) 295 } 296 297 result.fn = client.listByAutomationAccountNextResults 298 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName, filter) 299 if err != nil { 300 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "ListByAutomationAccount", nil, "Failure preparing request") 301 return 302 } 303 304 resp, err := client.ListByAutomationAccountSender(req) 305 if err != nil { 306 result.dcjlr.Response = autorest.Response{Response: resp} 307 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "ListByAutomationAccount", resp, "Failure sending request") 308 return 309 } 310 311 result.dcjlr, err = client.ListByAutomationAccountResponder(resp) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "ListByAutomationAccount", resp, "Failure responding to request") 314 } 315 316 return 317} 318 319// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 320func (client DscCompilationJobClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (*http.Request, error) { 321 pathParameters := map[string]interface{}{ 322 "automationAccountName": autorest.Encode("path", automationAccountName), 323 "resourceGroupName": autorest.Encode("path", resourceGroupName), 324 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 325 } 326 327 const APIVersion = "2015-10-31" 328 queryParameters := map[string]interface{}{ 329 "api-version": APIVersion, 330 } 331 if len(filter) > 0 { 332 queryParameters["$filter"] = autorest.Encode("query", filter) 333 } 334 335 preparer := autorest.CreatePreparer( 336 autorest.AsGet(), 337 autorest.WithBaseURL(client.BaseURI), 338 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/compilationjobs", pathParameters), 339 autorest.WithQueryParameters(queryParameters)) 340 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 341} 342 343// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 344// http.Response Body if it receives an error. 345func (client DscCompilationJobClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 346 return autorest.SendWithSender(client, req, 347 azure.DoRetryWithRegistration(client.Client)) 348} 349 350// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 351// closes the http.Response Body. 352func (client DscCompilationJobClient) ListByAutomationAccountResponder(resp *http.Response) (result DscCompilationJobListResult, err error) { 353 err = autorest.Respond( 354 resp, 355 client.ByInspecting(), 356 azure.WithErrorUnlessStatusCode(http.StatusOK), 357 autorest.ByUnmarshallingJSON(&result), 358 autorest.ByClosing()) 359 result.Response = autorest.Response{Response: resp} 360 return 361} 362 363// listByAutomationAccountNextResults retrieves the next set of results, if any. 364func (client DscCompilationJobClient) listByAutomationAccountNextResults(lastResults DscCompilationJobListResult) (result DscCompilationJobListResult, err error) { 365 req, err := lastResults.dscCompilationJobListResultPreparer() 366 if err != nil { 367 return result, autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request") 368 } 369 if req == nil { 370 return 371 } 372 resp, err := client.ListByAutomationAccountSender(req) 373 if err != nil { 374 result.Response = autorest.Response{Response: resp} 375 return result, autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request") 376 } 377 result, err = client.ListByAutomationAccountResponder(resp) 378 if err != nil { 379 err = autorest.NewErrorWithError(err, "automation.DscCompilationJobClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request") 380 } 381 return 382} 383 384// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required. 385func (client DscCompilationJobClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result DscCompilationJobListResultIterator, err error) { 386 result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter) 387 return 388} 389