github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/oidc_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 "time" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // OidcConfigClient is the client of the 'oidc_config' resource. 36 // 37 // Manages an Oidc Config configuration. 38 type OidcConfigClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewOidcConfigClient creates a new client for the 'oidc_config' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewOidcConfigClient(transport http.RoundTripper, path string) *OidcConfigClient { 47 return &OidcConfigClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Delete creates a request for the 'delete' method. 54 // 55 // Deletes the OidcConfig. 56 func (c *OidcConfigClient) Delete() *OidcConfigDeleteRequest { 57 return &OidcConfigDeleteRequest{ 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 an OidcConfig. 66 func (c *OidcConfigClient) Get() *OidcConfigGetRequest { 67 return &OidcConfigGetRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Update creates a request for the 'update' method. 74 // 75 // Updates attributes of an OidcConfig. 76 func (c *OidcConfigClient) Update() *OidcConfigUpdateRequest { 77 return &OidcConfigUpdateRequest{ 78 transport: c.transport, 79 path: c.path, 80 } 81 } 82 83 // OidcConfigPollRequest is the request for the Poll method. 84 type OidcConfigPollRequest struct { 85 request *OidcConfigGetRequest 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 *OidcConfigPollRequest) Parameter(name string, value interface{}) *OidcConfigPollRequest { 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 *OidcConfigPollRequest) Header(name string, value interface{}) *OidcConfigPollRequest { 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 *OidcConfigPollRequest) Interval(value time.Duration) *OidcConfigPollRequest { 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 *OidcConfigPollRequest) Status(value int) *OidcConfigPollRequest { 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 *OidcConfigPollRequest) Predicate(value func(*OidcConfigGetResponse) bool) *OidcConfigPollRequest { 120 r.predicates = append(r.predicates, func(response interface{}) bool { 121 return value(response.(*OidcConfigGetResponse)) 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 *OidcConfigPollRequest) StartContext(ctx context.Context) (response *OidcConfigPollResponse, err error) { 132 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 133 if result != nil { 134 response = &OidcConfigPollResponse{ 135 response: result.(*OidcConfigGetResponse), 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 *OidcConfigPollRequest) 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 // OidcConfigPollResponse is the response for the Poll method. 153 type OidcConfigPollResponse struct { 154 response *OidcConfigGetResponse 155 } 156 157 // Status returns the response status code. 158 func (r *OidcConfigPollResponse) 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 *OidcConfigPollResponse) 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 *OidcConfigPollResponse) 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 *OidcConfigPollResponse) Body() *OidcConfig { 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 *OidcConfigPollResponse) GetBody() (value *OidcConfig, 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 *OidcConfigClient) Poll() *OidcConfigPollRequest { 195 return &OidcConfigPollRequest{ 196 request: c.Get(), 197 } 198 } 199 200 // OidcConfigDeleteRequest is the request for the 'delete' method. 201 type OidcConfigDeleteRequest 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 *OidcConfigDeleteRequest) Parameter(name string, value interface{}) *OidcConfigDeleteRequest { 210 helpers.AddValue(&r.query, name, value) 211 return r 212 } 213 214 // Header adds a request header. 215 func (r *OidcConfigDeleteRequest) Header(name string, value interface{}) *OidcConfigDeleteRequest { 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 *OidcConfigDeleteRequest) Impersonate(user string) *OidcConfigDeleteRequest { 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 *OidcConfigDeleteRequest) Send() (result *OidcConfigDeleteResponse, 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 *OidcConfigDeleteRequest) SendContext(ctx context.Context) (result *OidcConfigDeleteResponse, 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 = &OidcConfigDeleteResponse{} 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 // OidcConfigDeleteResponse is the response for the 'delete' method. 277 type OidcConfigDeleteResponse struct { 278 status int 279 header http.Header 280 err *errors.Error 281 } 282 283 // Status returns the response status code. 284 func (r *OidcConfigDeleteResponse) 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 *OidcConfigDeleteResponse) 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 *OidcConfigDeleteResponse) Error() *errors.Error { 301 if r == nil { 302 return nil 303 } 304 return r.err 305 } 306 307 // OidcConfigGetRequest is the request for the 'get' method. 308 type OidcConfigGetRequest 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 *OidcConfigGetRequest) Parameter(name string, value interface{}) *OidcConfigGetRequest { 317 helpers.AddValue(&r.query, name, value) 318 return r 319 } 320 321 // Header adds a request header. 322 func (r *OidcConfigGetRequest) Header(name string, value interface{}) *OidcConfigGetRequest { 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 *OidcConfigGetRequest) Impersonate(user string) *OidcConfigGetRequest { 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 *OidcConfigGetRequest) Send() (result *OidcConfigGetResponse, 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 *OidcConfigGetRequest) SendContext(ctx context.Context) (result *OidcConfigGetResponse, 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 = &OidcConfigGetResponse{} 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 = readOidcConfigGetResponse(result, reader) 381 if err != nil { 382 return 383 } 384 return 385 } 386 387 // OidcConfigGetResponse is the response for the 'get' method. 388 type OidcConfigGetResponse struct { 389 status int 390 header http.Header 391 err *errors.Error 392 body *OidcConfig 393 } 394 395 // Status returns the response status code. 396 func (r *OidcConfigGetResponse) 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 *OidcConfigGetResponse) 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 *OidcConfigGetResponse) 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 *OidcConfigGetResponse) Body() *OidcConfig { 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 *OidcConfigGetResponse) GetBody() (value *OidcConfig, ok bool) { 430 ok = r != nil && r.body != nil 431 if ok { 432 value = r.body 433 } 434 return 435 } 436 437 // OidcConfigUpdateRequest is the request for the 'update' method. 438 type OidcConfigUpdateRequest struct { 439 transport http.RoundTripper 440 path string 441 query url.Values 442 header http.Header 443 body *OidcConfig 444 } 445 446 // Parameter adds a query parameter. 447 func (r *OidcConfigUpdateRequest) Parameter(name string, value interface{}) *OidcConfigUpdateRequest { 448 helpers.AddValue(&r.query, name, value) 449 return r 450 } 451 452 // Header adds a request header. 453 func (r *OidcConfigUpdateRequest) Header(name string, value interface{}) *OidcConfigUpdateRequest { 454 helpers.AddHeader(&r.header, name, value) 455 return r 456 } 457 458 // Impersonate wraps requests on behalf of another user. 459 // Note: Services that do not support this feature may silently ignore this call. 460 func (r *OidcConfigUpdateRequest) Impersonate(user string) *OidcConfigUpdateRequest { 461 helpers.AddImpersonationHeader(&r.header, user) 462 return r 463 } 464 465 // Body sets the value of the 'body' parameter. 466 func (r *OidcConfigUpdateRequest) Body(value *OidcConfig) *OidcConfigUpdateRequest { 467 r.body = value 468 return r 469 } 470 471 // Send sends this request, waits for the response, and returns it. 472 // 473 // This is a potentially lengthy operation, as it requires network communication. 474 // Consider using a context and the SendContext method. 475 func (r *OidcConfigUpdateRequest) Send() (result *OidcConfigUpdateResponse, err error) { 476 return r.SendContext(context.Background()) 477 } 478 479 // SendContext sends this request, waits for the response, and returns it. 480 func (r *OidcConfigUpdateRequest) SendContext(ctx context.Context) (result *OidcConfigUpdateResponse, err error) { 481 query := helpers.CopyQuery(r.query) 482 header := helpers.CopyHeader(r.header) 483 buffer := &bytes.Buffer{} 484 err = writeOidcConfigUpdateRequest(r, buffer) 485 if err != nil { 486 return 487 } 488 uri := &url.URL{ 489 Path: r.path, 490 RawQuery: query.Encode(), 491 } 492 request := &http.Request{ 493 Method: "PATCH", 494 URL: uri, 495 Header: header, 496 Body: io.NopCloser(buffer), 497 } 498 if ctx != nil { 499 request = request.WithContext(ctx) 500 } 501 response, err := r.transport.RoundTrip(request) 502 if err != nil { 503 return 504 } 505 defer response.Body.Close() 506 result = &OidcConfigUpdateResponse{} 507 result.status = response.StatusCode 508 result.header = response.Header 509 reader := bufio.NewReader(response.Body) 510 _, err = reader.Peek(1) 511 if err == io.EOF { 512 err = nil 513 return 514 } 515 if result.status >= 400 { 516 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 517 if err != nil { 518 return 519 } 520 err = result.err 521 return 522 } 523 err = readOidcConfigUpdateResponse(result, reader) 524 if err != nil { 525 return 526 } 527 return 528 } 529 530 // OidcConfigUpdateResponse is the response for the 'update' method. 531 type OidcConfigUpdateResponse struct { 532 status int 533 header http.Header 534 err *errors.Error 535 body *OidcConfig 536 } 537 538 // Status returns the response status code. 539 func (r *OidcConfigUpdateResponse) Status() int { 540 if r == nil { 541 return 0 542 } 543 return r.status 544 } 545 546 // Header returns header of the response. 547 func (r *OidcConfigUpdateResponse) Header() http.Header { 548 if r == nil { 549 return nil 550 } 551 return r.header 552 } 553 554 // Error returns the response error. 555 func (r *OidcConfigUpdateResponse) Error() *errors.Error { 556 if r == nil { 557 return nil 558 } 559 return r.err 560 } 561 562 // Body returns the value of the 'body' parameter. 563 func (r *OidcConfigUpdateResponse) Body() *OidcConfig { 564 if r == nil { 565 return nil 566 } 567 return r.body 568 } 569 570 // GetBody returns the value of the 'body' parameter and 571 // a flag indicating if the parameter has a value. 572 func (r *OidcConfigUpdateResponse) GetBody() (value *OidcConfig, ok bool) { 573 ok = r != nil && r.body != nil 574 if ok { 575 value = r.body 576 } 577 return 578 }