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