github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/clusters_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 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // ClustersClient is the client of the 'clusters' resource. 36 // 37 // Manages the collection of aro_hcp clusters. 38 type ClustersClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewClustersClient creates a new client for the 'clusters' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewClustersClient(transport http.RoundTripper, path string) *ClustersClient { 47 return &ClustersClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'async_add' method. 54 // 55 // Provision a new cluster and add it to the collection of clusters. 56 // 57 // See the `register_cluster` method for adding an existing cluster. 58 func (c *ClustersClient) Add() *ClustersAddRequest { 59 return &ClustersAddRequest{ 60 transport: c.transport, 61 path: c.path, 62 } 63 } 64 65 // List creates a request for the 'list' method. 66 // 67 // Retrieves the list of clusters. 68 func (c *ClustersClient) List() *ClustersListRequest { 69 return &ClustersListRequest{ 70 transport: c.transport, 71 path: c.path, 72 } 73 } 74 75 // Cluster returns the target 'cluster' resource for the given identifier. 76 // 77 // Returns a reference to the service that manages an specific cluster. 78 func (c *ClustersClient) Cluster(id string) *ClusterClient { 79 return NewClusterClient( 80 c.transport, 81 path.Join(c.path, id), 82 ) 83 } 84 85 // ClustersAddRequest is the request for the 'async_add' method. 86 type ClustersAddRequest struct { 87 transport http.RoundTripper 88 path string 89 query url.Values 90 header http.Header 91 body *Cluster 92 } 93 94 // Parameter adds a query parameter. 95 func (r *ClustersAddRequest) Parameter(name string, value interface{}) *ClustersAddRequest { 96 helpers.AddValue(&r.query, name, value) 97 return r 98 } 99 100 // Header adds a request header. 101 func (r *ClustersAddRequest) Header(name string, value interface{}) *ClustersAddRequest { 102 helpers.AddHeader(&r.header, name, value) 103 return r 104 } 105 106 // Impersonate wraps requests on behalf of another user. 107 // Note: Services that do not support this feature may silently ignore this call. 108 func (r *ClustersAddRequest) Impersonate(user string) *ClustersAddRequest { 109 helpers.AddImpersonationHeader(&r.header, user) 110 return r 111 } 112 113 // Body sets the value of the 'body' parameter. 114 // 115 // Description of the cluster. 116 func (r *ClustersAddRequest) Body(value *Cluster) *ClustersAddRequest { 117 r.body = value 118 return r 119 } 120 121 // Send sends this request, waits for the response, and returns it. 122 // 123 // This is a potentially lengthy operation, as it requires network communication. 124 // Consider using a context and the SendContext method. 125 func (r *ClustersAddRequest) Send() (result *ClustersAddResponse, err error) { 126 return r.SendContext(context.Background()) 127 } 128 129 // SendContext sends this request, waits for the response, and returns it. 130 func (r *ClustersAddRequest) SendContext(ctx context.Context) (result *ClustersAddResponse, err error) { 131 query := helpers.CopyQuery(r.query) 132 header := helpers.CopyHeader(r.header) 133 buffer := &bytes.Buffer{} 134 err = writeClustersAsyncAddRequest(r, buffer) 135 if err != nil { 136 return 137 } 138 uri := &url.URL{ 139 Path: r.path, 140 RawQuery: query.Encode(), 141 } 142 request := &http.Request{ 143 Method: "POST", 144 URL: uri, 145 Header: header, 146 Body: io.NopCloser(buffer), 147 } 148 if ctx != nil { 149 request = request.WithContext(ctx) 150 } 151 response, err := r.transport.RoundTrip(request) 152 if err != nil { 153 return 154 } 155 defer response.Body.Close() 156 result = &ClustersAddResponse{} 157 result.status = response.StatusCode 158 result.header = response.Header 159 reader := bufio.NewReader(response.Body) 160 _, err = reader.Peek(1) 161 if err == io.EOF { 162 err = nil 163 return 164 } 165 if result.status >= 400 { 166 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 167 if err != nil { 168 return 169 } 170 err = result.err 171 return 172 } 173 err = readClustersAsyncAddResponse(result, reader) 174 if err != nil { 175 return 176 } 177 return 178 } 179 180 // ClustersAddResponse is the response for the 'async_add' method. 181 type ClustersAddResponse struct { 182 status int 183 header http.Header 184 err *errors.Error 185 body *Cluster 186 } 187 188 // Status returns the response status code. 189 func (r *ClustersAddResponse) Status() int { 190 if r == nil { 191 return 0 192 } 193 return r.status 194 } 195 196 // Header returns header of the response. 197 func (r *ClustersAddResponse) Header() http.Header { 198 if r == nil { 199 return nil 200 } 201 return r.header 202 } 203 204 // Error returns the response error. 205 func (r *ClustersAddResponse) Error() *errors.Error { 206 if r == nil { 207 return nil 208 } 209 return r.err 210 } 211 212 // Body returns the value of the 'body' parameter. 213 // 214 // Description of the cluster. 215 func (r *ClustersAddResponse) Body() *Cluster { 216 if r == nil { 217 return nil 218 } 219 return r.body 220 } 221 222 // GetBody returns the value of the 'body' parameter and 223 // a flag indicating if the parameter has a value. 224 // 225 // Description of the cluster. 226 func (r *ClustersAddResponse) GetBody() (value *Cluster, ok bool) { 227 ok = r != nil && r.body != nil 228 if ok { 229 value = r.body 230 } 231 return 232 } 233 234 // ClustersListRequest is the request for the 'list' method. 235 type ClustersListRequest struct { 236 transport http.RoundTripper 237 path string 238 query url.Values 239 header http.Header 240 order *string 241 page *int 242 search *string 243 size *int 244 } 245 246 // Parameter adds a query parameter. 247 func (r *ClustersListRequest) Parameter(name string, value interface{}) *ClustersListRequest { 248 helpers.AddValue(&r.query, name, value) 249 return r 250 } 251 252 // Header adds a request header. 253 func (r *ClustersListRequest) Header(name string, value interface{}) *ClustersListRequest { 254 helpers.AddHeader(&r.header, name, value) 255 return r 256 } 257 258 // Impersonate wraps requests on behalf of another user. 259 // Note: Services that do not support this feature may silently ignore this call. 260 func (r *ClustersListRequest) Impersonate(user string) *ClustersListRequest { 261 helpers.AddImpersonationHeader(&r.header, user) 262 return r 263 } 264 265 // Order sets the value of the 'order' parameter. 266 // 267 // Order criteria. 268 // 269 // The syntax of this parameter is similar to the syntax of the _order by_ clause of 270 // a SQL statement, but using the names of the attributes of the cluster instead of 271 // the names of the columns of a table. For example, in order to sort the clusters 272 // descending by region identifier the value should be: 273 // 274 // ```sql 275 // region.id desc 276 // ``` 277 // 278 // If the parameter isn't provided, or if the value is empty, then the order of the 279 // results is undefined. 280 func (r *ClustersListRequest) Order(value string) *ClustersListRequest { 281 r.order = &value 282 return r 283 } 284 285 // Page sets the value of the 'page' parameter. 286 // 287 // Index of the requested page, where one corresponds to the first page. 288 func (r *ClustersListRequest) Page(value int) *ClustersListRequest { 289 r.page = &value 290 return r 291 } 292 293 // Search sets the value of the 'search' parameter. 294 // 295 // Search criteria. 296 // 297 // The syntax of this parameter is similar to the syntax of the _where_ clause of a 298 // SQL statement, but using the names of the attributes of the cluster instead of 299 // the names of the columns of a table. For example, in order to retrieve all the 300 // clusters with a name starting with `my` in the `us-east-1` region the value 301 // should be: 302 // 303 // ```sql 304 // name like 'my%' and region.id = 'us-east-1' 305 // ``` 306 // 307 // If the parameter isn't provided, or if the value is empty, then all the 308 // clusters that the user has permission to see will be returned. 309 func (r *ClustersListRequest) Search(value string) *ClustersListRequest { 310 r.search = &value 311 return r 312 } 313 314 // Size sets the value of the 'size' parameter. 315 // 316 // Maximum number of items that will be contained in the returned page. 317 func (r *ClustersListRequest) Size(value int) *ClustersListRequest { 318 r.size = &value 319 return r 320 } 321 322 // Send sends this request, waits for the response, and returns it. 323 // 324 // This is a potentially lengthy operation, as it requires network communication. 325 // Consider using a context and the SendContext method. 326 func (r *ClustersListRequest) Send() (result *ClustersListResponse, err error) { 327 return r.SendContext(context.Background()) 328 } 329 330 // SendContext sends this request, waits for the response, and returns it. 331 func (r *ClustersListRequest) SendContext(ctx context.Context) (result *ClustersListResponse, err error) { 332 query := helpers.CopyQuery(r.query) 333 if r.order != nil { 334 helpers.AddValue(&query, "order", *r.order) 335 } 336 if r.page != nil { 337 helpers.AddValue(&query, "page", *r.page) 338 } 339 if r.search != nil { 340 helpers.AddValue(&query, "search", *r.search) 341 } 342 if r.size != nil { 343 helpers.AddValue(&query, "size", *r.size) 344 } 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 = &ClustersListResponse{} 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 = readClustersListResponse(result, reader) 381 if err != nil { 382 return 383 } 384 return 385 } 386 387 // ClustersListResponse is the response for the 'list' method. 388 type ClustersListResponse struct { 389 status int 390 header http.Header 391 err *errors.Error 392 items *ClusterList 393 page *int 394 size *int 395 total *int 396 } 397 398 // Status returns the response status code. 399 func (r *ClustersListResponse) Status() int { 400 if r == nil { 401 return 0 402 } 403 return r.status 404 } 405 406 // Header returns header of the response. 407 func (r *ClustersListResponse) Header() http.Header { 408 if r == nil { 409 return nil 410 } 411 return r.header 412 } 413 414 // Error returns the response error. 415 func (r *ClustersListResponse) Error() *errors.Error { 416 if r == nil { 417 return nil 418 } 419 return r.err 420 } 421 422 // Items returns the value of the 'items' parameter. 423 // 424 // Retrieved list of clusters. 425 func (r *ClustersListResponse) Items() *ClusterList { 426 if r == nil { 427 return nil 428 } 429 return r.items 430 } 431 432 // GetItems returns the value of the 'items' parameter and 433 // a flag indicating if the parameter has a value. 434 // 435 // Retrieved list of clusters. 436 func (r *ClustersListResponse) GetItems() (value *ClusterList, ok bool) { 437 ok = r != nil && r.items != nil 438 if ok { 439 value = r.items 440 } 441 return 442 } 443 444 // Page returns the value of the 'page' parameter. 445 // 446 // Index of the requested page, where one corresponds to the first page. 447 func (r *ClustersListResponse) Page() int { 448 if r != nil && r.page != nil { 449 return *r.page 450 } 451 return 0 452 } 453 454 // GetPage returns the value of the 'page' parameter and 455 // a flag indicating if the parameter has a value. 456 // 457 // Index of the requested page, where one corresponds to the first page. 458 func (r *ClustersListResponse) GetPage() (value int, ok bool) { 459 ok = r != nil && r.page != nil 460 if ok { 461 value = *r.page 462 } 463 return 464 } 465 466 // Size returns the value of the 'size' parameter. 467 // 468 // Maximum number of items that will be contained in the returned page. 469 func (r *ClustersListResponse) Size() int { 470 if r != nil && r.size != nil { 471 return *r.size 472 } 473 return 0 474 } 475 476 // GetSize returns the value of the 'size' parameter and 477 // a flag indicating if the parameter has a value. 478 // 479 // Maximum number of items that will be contained in the returned page. 480 func (r *ClustersListResponse) GetSize() (value int, ok bool) { 481 ok = r != nil && r.size != nil 482 if ok { 483 value = *r.size 484 } 485 return 486 } 487 488 // Total returns the value of the 'total' parameter. 489 // 490 // Total number of items of the collection that match the search criteria, 491 // regardless of the size of the page. 492 func (r *ClustersListResponse) Total() int { 493 if r != nil && r.total != nil { 494 return *r.total 495 } 496 return 0 497 } 498 499 // GetTotal returns the value of the 'total' parameter and 500 // a flag indicating if the parameter has a value. 501 // 502 // Total number of items of the collection that match the search criteria, 503 // regardless of the size of the page. 504 func (r *ClustersListResponse) GetTotal() (value int, ok bool) { 505 ok = r != nil && r.total != nil 506 if ok { 507 value = *r.total 508 } 509 return 510 }