github.com/openshift-online/ocm-sdk-go@v0.1.473/addonsmgmt/v1/addon_installation_client.go (about) 1 /* 2 Copyright (c) 2020 Red Hat, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 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 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // IMPORTANT: This file has been generated automatically, refrain from modifying it manually as all 18 // your changes will be lost when the file is generated again. 19 20 package v1 // github.com/openshift-online/ocm-sdk-go/addonsmgmt/v1 21 22 import ( 23 "bufio" 24 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 "time" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // AddonInstallationClient is the client of the 'addon_installation' resource. 36 // 37 // Manages a specific addon installation. 38 type AddonInstallationClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewAddonInstallationClient creates a new client for the 'addon_installation' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewAddonInstallationClient(transport http.RoundTripper, path string) *AddonInstallationClient { 47 return &AddonInstallationClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Delete creates a request for the 'delete' method. 54 // 55 // Deletes the addon installation. 56 func (c *AddonInstallationClient) Delete() *AddonInstallationDeleteRequest { 57 return &AddonInstallationDeleteRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // Get creates a request for the 'get' method. 64 // 65 // Retrieves the details of the addon installation. 66 func (c *AddonInstallationClient) Get() *AddonInstallationGetRequest { 67 return &AddonInstallationGetRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Update creates a request for the 'update' method. 74 // 75 // Updates the addon installation. 76 func (c *AddonInstallationClient) Update() *AddonInstallationUpdateRequest { 77 return &AddonInstallationUpdateRequest{ 78 transport: c.transport, 79 path: c.path, 80 } 81 } 82 83 // AddonInstallationPollRequest is the request for the Poll method. 84 type AddonInstallationPollRequest struct { 85 request *AddonInstallationGetRequest 86 interval time.Duration 87 statuses []int 88 predicates []func(interface{}) bool 89 } 90 91 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 92 func (r *AddonInstallationPollRequest) Parameter(name string, value interface{}) *AddonInstallationPollRequest { 93 r.request.Parameter(name, value) 94 return r 95 } 96 97 // Header adds a request header to all the requests that will be used to retrieve the object. 98 func (r *AddonInstallationPollRequest) Header(name string, value interface{}) *AddonInstallationPollRequest { 99 r.request.Header(name, value) 100 return r 101 } 102 103 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 104 func (r *AddonInstallationPollRequest) Interval(value time.Duration) *AddonInstallationPollRequest { 105 r.interval = value 106 return r 107 } 108 109 // Status set the expected status of the response. Multiple values can be set calling this method 110 // multiple times. The response will be considered successful if the status is any of those values. 111 func (r *AddonInstallationPollRequest) Status(value int) *AddonInstallationPollRequest { 112 r.statuses = append(r.statuses, value) 113 return r 114 } 115 116 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 117 // predicates can be set calling this method multiple times. The response will be considered successful 118 // if all the predicates are satisfied. 119 func (r *AddonInstallationPollRequest) Predicate(value func(*AddonInstallationGetResponse) bool) *AddonInstallationPollRequest { 120 r.predicates = append(r.predicates, func(response interface{}) bool { 121 return value(response.(*AddonInstallationGetResponse)) 122 }) 123 return r 124 } 125 126 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 127 // the values specified with the Status method and if all the predicates specified with the Predicate 128 // method return nil. 129 // 130 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 131 func (r *AddonInstallationPollRequest) StartContext(ctx context.Context) (response *AddonInstallationPollResponse, err error) { 132 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 133 if result != nil { 134 response = &AddonInstallationPollResponse{ 135 response: result.(*AddonInstallationGetResponse), 136 } 137 } 138 return 139 } 140 141 // task adapts the types of the request/response types so that they can be used with the generic 142 // polling function from the helpers package. 143 func (r *AddonInstallationPollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 144 response, err := r.request.SendContext(ctx) 145 if response != nil { 146 status = response.Status() 147 result = response 148 } 149 return 150 } 151 152 // AddonInstallationPollResponse is the response for the Poll method. 153 type AddonInstallationPollResponse struct { 154 response *AddonInstallationGetResponse 155 } 156 157 // Status returns the response status code. 158 func (r *AddonInstallationPollResponse) Status() int { 159 if r == nil { 160 return 0 161 } 162 return r.response.Status() 163 } 164 165 // Header returns header of the response. 166 func (r *AddonInstallationPollResponse) Header() http.Header { 167 if r == nil { 168 return nil 169 } 170 return r.response.Header() 171 } 172 173 // Error returns the response error. 174 func (r *AddonInstallationPollResponse) Error() *errors.Error { 175 if r == nil { 176 return nil 177 } 178 return r.response.Error() 179 } 180 181 // Body returns the value of the 'body' parameter. 182 func (r *AddonInstallationPollResponse) Body() *AddonInstallation { 183 return r.response.Body() 184 } 185 186 // GetBody returns the value of the 'body' parameter and 187 // a flag indicating if the parameter has a value. 188 func (r *AddonInstallationPollResponse) GetBody() (value *AddonInstallation, ok bool) { 189 return r.response.GetBody() 190 } 191 192 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 193 // of states and satisfies a set of predicates. 194 func (c *AddonInstallationClient) Poll() *AddonInstallationPollRequest { 195 return &AddonInstallationPollRequest{ 196 request: c.Get(), 197 } 198 } 199 200 // AddonInstallationDeleteRequest is the request for the 'delete' method. 201 type AddonInstallationDeleteRequest struct { 202 transport http.RoundTripper 203 path string 204 query url.Values 205 header http.Header 206 } 207 208 // Parameter adds a query parameter. 209 func (r *AddonInstallationDeleteRequest) Parameter(name string, value interface{}) *AddonInstallationDeleteRequest { 210 helpers.AddValue(&r.query, name, value) 211 return r 212 } 213 214 // Header adds a request header. 215 func (r *AddonInstallationDeleteRequest) Header(name string, value interface{}) *AddonInstallationDeleteRequest { 216 helpers.AddHeader(&r.header, name, value) 217 return r 218 } 219 220 // Impersonate wraps requests on behalf of another user. 221 // Note: Services that do not support this feature may silently ignore this call. 222 func (r *AddonInstallationDeleteRequest) Impersonate(user string) *AddonInstallationDeleteRequest { 223 helpers.AddImpersonationHeader(&r.header, user) 224 return r 225 } 226 227 // Send sends this request, waits for the response, and returns it. 228 // 229 // This is a potentially lengthy operation, as it requires network communication. 230 // Consider using a context and the SendContext method. 231 func (r *AddonInstallationDeleteRequest) Send() (result *AddonInstallationDeleteResponse, err error) { 232 return r.SendContext(context.Background()) 233 } 234 235 // SendContext sends this request, waits for the response, and returns it. 236 func (r *AddonInstallationDeleteRequest) SendContext(ctx context.Context) (result *AddonInstallationDeleteResponse, err error) { 237 query := helpers.CopyQuery(r.query) 238 header := helpers.CopyHeader(r.header) 239 uri := &url.URL{ 240 Path: r.path, 241 RawQuery: query.Encode(), 242 } 243 request := &http.Request{ 244 Method: "DELETE", 245 URL: uri, 246 Header: header, 247 } 248 if ctx != nil { 249 request = request.WithContext(ctx) 250 } 251 response, err := r.transport.RoundTrip(request) 252 if err != nil { 253 return 254 } 255 defer response.Body.Close() 256 result = &AddonInstallationDeleteResponse{} 257 result.status = response.StatusCode 258 result.header = response.Header 259 reader := bufio.NewReader(response.Body) 260 _, err = reader.Peek(1) 261 if err == io.EOF { 262 err = nil 263 return 264 } 265 if result.status >= 400 { 266 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 267 if err != nil { 268 return 269 } 270 err = result.err 271 return 272 } 273 return 274 } 275 276 // AddonInstallationDeleteResponse is the response for the 'delete' method. 277 type AddonInstallationDeleteResponse struct { 278 status int 279 header http.Header 280 err *errors.Error 281 } 282 283 // Status returns the response status code. 284 func (r *AddonInstallationDeleteResponse) Status() int { 285 if r == nil { 286 return 0 287 } 288 return r.status 289 } 290 291 // Header returns header of the response. 292 func (r *AddonInstallationDeleteResponse) Header() http.Header { 293 if r == nil { 294 return nil 295 } 296 return r.header 297 } 298 299 // Error returns the response error. 300 func (r *AddonInstallationDeleteResponse) Error() *errors.Error { 301 if r == nil { 302 return nil 303 } 304 return r.err 305 } 306 307 // AddonInstallationGetRequest is the request for the 'get' method. 308 type AddonInstallationGetRequest struct { 309 transport http.RoundTripper 310 path string 311 query url.Values 312 header http.Header 313 } 314 315 // Parameter adds a query parameter. 316 func (r *AddonInstallationGetRequest) Parameter(name string, value interface{}) *AddonInstallationGetRequest { 317 helpers.AddValue(&r.query, name, value) 318 return r 319 } 320 321 // Header adds a request header. 322 func (r *AddonInstallationGetRequest) Header(name string, value interface{}) *AddonInstallationGetRequest { 323 helpers.AddHeader(&r.header, name, value) 324 return r 325 } 326 327 // Impersonate wraps requests on behalf of another user. 328 // Note: Services that do not support this feature may silently ignore this call. 329 func (r *AddonInstallationGetRequest) Impersonate(user string) *AddonInstallationGetRequest { 330 helpers.AddImpersonationHeader(&r.header, user) 331 return r 332 } 333 334 // Send sends this request, waits for the response, and returns it. 335 // 336 // This is a potentially lengthy operation, as it requires network communication. 337 // Consider using a context and the SendContext method. 338 func (r *AddonInstallationGetRequest) Send() (result *AddonInstallationGetResponse, err error) { 339 return r.SendContext(context.Background()) 340 } 341 342 // SendContext sends this request, waits for the response, and returns it. 343 func (r *AddonInstallationGetRequest) SendContext(ctx context.Context) (result *AddonInstallationGetResponse, err error) { 344 query := helpers.CopyQuery(r.query) 345 header := helpers.CopyHeader(r.header) 346 uri := &url.URL{ 347 Path: r.path, 348 RawQuery: query.Encode(), 349 } 350 request := &http.Request{ 351 Method: "GET", 352 URL: uri, 353 Header: header, 354 } 355 if ctx != nil { 356 request = request.WithContext(ctx) 357 } 358 response, err := r.transport.RoundTrip(request) 359 if err != nil { 360 return 361 } 362 defer response.Body.Close() 363 result = &AddonInstallationGetResponse{} 364 result.status = response.StatusCode 365 result.header = response.Header 366 reader := bufio.NewReader(response.Body) 367 _, err = reader.Peek(1) 368 if err == io.EOF { 369 err = nil 370 return 371 } 372 if result.status >= 400 { 373 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 374 if err != nil { 375 return 376 } 377 err = result.err 378 return 379 } 380 err = readAddonInstallationGetResponse(result, reader) 381 if err != nil { 382 return 383 } 384 return 385 } 386 387 // AddonInstallationGetResponse is the response for the 'get' method. 388 type AddonInstallationGetResponse struct { 389 status int 390 header http.Header 391 err *errors.Error 392 body *AddonInstallation 393 } 394 395 // Status returns the response status code. 396 func (r *AddonInstallationGetResponse) Status() int { 397 if r == nil { 398 return 0 399 } 400 return r.status 401 } 402 403 // Header returns header of the response. 404 func (r *AddonInstallationGetResponse) Header() http.Header { 405 if r == nil { 406 return nil 407 } 408 return r.header 409 } 410 411 // Error returns the response error. 412 func (r *AddonInstallationGetResponse) Error() *errors.Error { 413 if r == nil { 414 return nil 415 } 416 return r.err 417 } 418 419 // Body returns the value of the 'body' parameter. 420 func (r *AddonInstallationGetResponse) Body() *AddonInstallation { 421 if r == nil { 422 return nil 423 } 424 return r.body 425 } 426 427 // GetBody returns the value of the 'body' parameter and 428 // a flag indicating if the parameter has a value. 429 func (r *AddonInstallationGetResponse) GetBody() (value *AddonInstallation, ok bool) { 430 ok = r != nil && r.body != nil 431 if ok { 432 value = r.body 433 } 434 return 435 } 436 437 // AddonInstallationUpdateRequest is the request for the 'update' method. 438 type AddonInstallationUpdateRequest struct { 439 transport http.RoundTripper 440 path string 441 query url.Values 442 header http.Header 443 body *AddonInstallation 444 dryRun *bool 445 } 446 447 // Parameter adds a query parameter. 448 func (r *AddonInstallationUpdateRequest) Parameter(name string, value interface{}) *AddonInstallationUpdateRequest { 449 helpers.AddValue(&r.query, name, value) 450 return r 451 } 452 453 // Header adds a request header. 454 func (r *AddonInstallationUpdateRequest) Header(name string, value interface{}) *AddonInstallationUpdateRequest { 455 helpers.AddHeader(&r.header, name, value) 456 return r 457 } 458 459 // Impersonate wraps requests on behalf of another user. 460 // Note: Services that do not support this feature may silently ignore this call. 461 func (r *AddonInstallationUpdateRequest) Impersonate(user string) *AddonInstallationUpdateRequest { 462 helpers.AddImpersonationHeader(&r.header, user) 463 return r 464 } 465 466 // Body sets the value of the 'body' parameter. 467 func (r *AddonInstallationUpdateRequest) Body(value *AddonInstallation) *AddonInstallationUpdateRequest { 468 r.body = value 469 return r 470 } 471 472 // DryRun sets the value of the 'dry_run' parameter. 473 // 474 // DryRun indicates the request body will not be persisted when dryRun=true. 475 func (r *AddonInstallationUpdateRequest) DryRun(value bool) *AddonInstallationUpdateRequest { 476 r.dryRun = &value 477 return r 478 } 479 480 // Send sends this request, waits for the response, and returns it. 481 // 482 // This is a potentially lengthy operation, as it requires network communication. 483 // Consider using a context and the SendContext method. 484 func (r *AddonInstallationUpdateRequest) Send() (result *AddonInstallationUpdateResponse, err error) { 485 return r.SendContext(context.Background()) 486 } 487 488 // SendContext sends this request, waits for the response, and returns it. 489 func (r *AddonInstallationUpdateRequest) SendContext(ctx context.Context) (result *AddonInstallationUpdateResponse, err error) { 490 query := helpers.CopyQuery(r.query) 491 if r.dryRun != nil { 492 helpers.AddValue(&query, "dryRun", *r.dryRun) 493 } 494 header := helpers.CopyHeader(r.header) 495 buffer := &bytes.Buffer{} 496 err = writeAddonInstallationUpdateRequest(r, buffer) 497 if err != nil { 498 return 499 } 500 uri := &url.URL{ 501 Path: r.path, 502 RawQuery: query.Encode(), 503 } 504 request := &http.Request{ 505 Method: "PATCH", 506 URL: uri, 507 Header: header, 508 Body: io.NopCloser(buffer), 509 } 510 if ctx != nil { 511 request = request.WithContext(ctx) 512 } 513 response, err := r.transport.RoundTrip(request) 514 if err != nil { 515 return 516 } 517 defer response.Body.Close() 518 result = &AddonInstallationUpdateResponse{} 519 result.status = response.StatusCode 520 result.header = response.Header 521 reader := bufio.NewReader(response.Body) 522 _, err = reader.Peek(1) 523 if err == io.EOF { 524 err = nil 525 return 526 } 527 if result.status >= 400 { 528 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 529 if err != nil { 530 return 531 } 532 err = result.err 533 return 534 } 535 err = readAddonInstallationUpdateResponse(result, reader) 536 if err != nil { 537 return 538 } 539 return 540 } 541 542 // AddonInstallationUpdateResponse is the response for the 'update' method. 543 type AddonInstallationUpdateResponse struct { 544 status int 545 header http.Header 546 err *errors.Error 547 body *AddonInstallation 548 } 549 550 // Status returns the response status code. 551 func (r *AddonInstallationUpdateResponse) Status() int { 552 if r == nil { 553 return 0 554 } 555 return r.status 556 } 557 558 // Header returns header of the response. 559 func (r *AddonInstallationUpdateResponse) Header() http.Header { 560 if r == nil { 561 return nil 562 } 563 return r.header 564 } 565 566 // Error returns the response error. 567 func (r *AddonInstallationUpdateResponse) Error() *errors.Error { 568 if r == nil { 569 return nil 570 } 571 return r.err 572 } 573 574 // Body returns the value of the 'body' parameter. 575 func (r *AddonInstallationUpdateResponse) Body() *AddonInstallation { 576 if r == nil { 577 return nil 578 } 579 return r.body 580 } 581 582 // GetBody returns the value of the 'body' parameter and 583 // a flag indicating if the parameter has a value. 584 func (r *AddonInstallationUpdateResponse) GetBody() (value *AddonInstallation, ok bool) { 585 ok = r != nil && r.body != nil 586 if ok { 587 value = r.body 588 } 589 return 590 }