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