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