github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/cloud_regions_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 // CloudRegionsClient is the client of the 'cloud_regions' resource. 36 // 37 // Manages the collection of regions of a cloud provider. 38 type CloudRegionsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewCloudRegionsClient creates a new client for the 'cloud_regions' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewCloudRegionsClient(transport http.RoundTripper, path string) *CloudRegionsClient { 47 return &CloudRegionsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Adds a cloud region to the database. 56 func (c *CloudRegionsClient) Add() *CloudRegionsAddRequest { 57 return &CloudRegionsAddRequest{ 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 regions of the cloud provider. 66 // 67 // IMPORTANT: This collection doesn't currently support paging or searching, so the returned 68 // `page` will always be 1 and `size` and `total` will always be the total number of regions 69 // of the provider. 70 func (c *CloudRegionsClient) List() *CloudRegionsListRequest { 71 return &CloudRegionsListRequest{ 72 transport: c.transport, 73 path: c.path, 74 } 75 } 76 77 // Region returns the target 'cloud_region' resource for the given identifier. 78 // 79 // Reference to the service that manages an specific region. 80 func (c *CloudRegionsClient) Region(id string) *CloudRegionClient { 81 return NewCloudRegionClient( 82 c.transport, 83 path.Join(c.path, id), 84 ) 85 } 86 87 // CloudRegionsAddRequest is the request for the 'add' method. 88 type CloudRegionsAddRequest struct { 89 transport http.RoundTripper 90 path string 91 query url.Values 92 header http.Header 93 body *CloudRegion 94 } 95 96 // Parameter adds a query parameter. 97 func (r *CloudRegionsAddRequest) Parameter(name string, value interface{}) *CloudRegionsAddRequest { 98 helpers.AddValue(&r.query, name, value) 99 return r 100 } 101 102 // Header adds a request header. 103 func (r *CloudRegionsAddRequest) Header(name string, value interface{}) *CloudRegionsAddRequest { 104 helpers.AddHeader(&r.header, name, value) 105 return r 106 } 107 108 // Impersonate wraps requests on behalf of another user. 109 // Note: Services that do not support this feature may silently ignore this call. 110 func (r *CloudRegionsAddRequest) Impersonate(user string) *CloudRegionsAddRequest { 111 helpers.AddImpersonationHeader(&r.header, user) 112 return r 113 } 114 115 // Body sets the value of the 'body' parameter. 116 func (r *CloudRegionsAddRequest) Body(value *CloudRegion) *CloudRegionsAddRequest { 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 *CloudRegionsAddRequest) Send() (result *CloudRegionsAddResponse, 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 *CloudRegionsAddRequest) SendContext(ctx context.Context) (result *CloudRegionsAddResponse, err error) { 131 query := helpers.CopyQuery(r.query) 132 header := helpers.CopyHeader(r.header) 133 buffer := &bytes.Buffer{} 134 err = writeCloudRegionsAddRequest(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 = &CloudRegionsAddResponse{} 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 = readCloudRegionsAddResponse(result, reader) 174 if err != nil { 175 return 176 } 177 return 178 } 179 180 // CloudRegionsAddResponse is the response for the 'add' method. 181 type CloudRegionsAddResponse struct { 182 status int 183 header http.Header 184 err *errors.Error 185 body *CloudRegion 186 } 187 188 // Status returns the response status code. 189 func (r *CloudRegionsAddResponse) 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 *CloudRegionsAddResponse) 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 *CloudRegionsAddResponse) 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 func (r *CloudRegionsAddResponse) Body() *CloudRegion { 214 if r == nil { 215 return nil 216 } 217 return r.body 218 } 219 220 // GetBody returns the value of the 'body' parameter and 221 // a flag indicating if the parameter has a value. 222 func (r *CloudRegionsAddResponse) GetBody() (value *CloudRegion, ok bool) { 223 ok = r != nil && r.body != nil 224 if ok { 225 value = r.body 226 } 227 return 228 } 229 230 // CloudRegionsListRequest is the request for the 'list' method. 231 type CloudRegionsListRequest struct { 232 transport http.RoundTripper 233 path string 234 query url.Values 235 header http.Header 236 page *int 237 size *int 238 } 239 240 // Parameter adds a query parameter. 241 func (r *CloudRegionsListRequest) Parameter(name string, value interface{}) *CloudRegionsListRequest { 242 helpers.AddValue(&r.query, name, value) 243 return r 244 } 245 246 // Header adds a request header. 247 func (r *CloudRegionsListRequest) Header(name string, value interface{}) *CloudRegionsListRequest { 248 helpers.AddHeader(&r.header, name, value) 249 return r 250 } 251 252 // Impersonate wraps requests on behalf of another user. 253 // Note: Services that do not support this feature may silently ignore this call. 254 func (r *CloudRegionsListRequest) Impersonate(user string) *CloudRegionsListRequest { 255 helpers.AddImpersonationHeader(&r.header, user) 256 return r 257 } 258 259 // Page sets the value of the 'page' parameter. 260 // 261 // Index of the returned page, where one corresponds to the first page. As this 262 // collection doesn't support paging the result will always be `1`. 263 func (r *CloudRegionsListRequest) Page(value int) *CloudRegionsListRequest { 264 r.page = &value 265 return r 266 } 267 268 // Size sets the value of the 'size' parameter. 269 // 270 // Number of items that will be contained in the returned page. As this collection 271 // doesn't support paging or searching the result will always be the total number of 272 // regions of the provider. 273 func (r *CloudRegionsListRequest) Size(value int) *CloudRegionsListRequest { 274 r.size = &value 275 return r 276 } 277 278 // Send sends this request, waits for the response, and returns it. 279 // 280 // This is a potentially lengthy operation, as it requires network communication. 281 // Consider using a context and the SendContext method. 282 func (r *CloudRegionsListRequest) Send() (result *CloudRegionsListResponse, err error) { 283 return r.SendContext(context.Background()) 284 } 285 286 // SendContext sends this request, waits for the response, and returns it. 287 func (r *CloudRegionsListRequest) SendContext(ctx context.Context) (result *CloudRegionsListResponse, err error) { 288 query := helpers.CopyQuery(r.query) 289 if r.page != nil { 290 helpers.AddValue(&query, "page", *r.page) 291 } 292 if r.size != nil { 293 helpers.AddValue(&query, "size", *r.size) 294 } 295 header := helpers.CopyHeader(r.header) 296 uri := &url.URL{ 297 Path: r.path, 298 RawQuery: query.Encode(), 299 } 300 request := &http.Request{ 301 Method: "GET", 302 URL: uri, 303 Header: header, 304 } 305 if ctx != nil { 306 request = request.WithContext(ctx) 307 } 308 response, err := r.transport.RoundTrip(request) 309 if err != nil { 310 return 311 } 312 defer response.Body.Close() 313 result = &CloudRegionsListResponse{} 314 result.status = response.StatusCode 315 result.header = response.Header 316 reader := bufio.NewReader(response.Body) 317 _, err = reader.Peek(1) 318 if err == io.EOF { 319 err = nil 320 return 321 } 322 if result.status >= 400 { 323 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 324 if err != nil { 325 return 326 } 327 err = result.err 328 return 329 } 330 err = readCloudRegionsListResponse(result, reader) 331 if err != nil { 332 return 333 } 334 return 335 } 336 337 // CloudRegionsListResponse is the response for the 'list' method. 338 type CloudRegionsListResponse struct { 339 status int 340 header http.Header 341 err *errors.Error 342 items *CloudRegionList 343 page *int 344 size *int 345 total *int 346 } 347 348 // Status returns the response status code. 349 func (r *CloudRegionsListResponse) Status() int { 350 if r == nil { 351 return 0 352 } 353 return r.status 354 } 355 356 // Header returns header of the response. 357 func (r *CloudRegionsListResponse) Header() http.Header { 358 if r == nil { 359 return nil 360 } 361 return r.header 362 } 363 364 // Error returns the response error. 365 func (r *CloudRegionsListResponse) Error() *errors.Error { 366 if r == nil { 367 return nil 368 } 369 return r.err 370 } 371 372 // Items returns the value of the 'items' parameter. 373 // 374 // Retrieved list of cloud providers. 375 func (r *CloudRegionsListResponse) Items() *CloudRegionList { 376 if r == nil { 377 return nil 378 } 379 return r.items 380 } 381 382 // GetItems returns the value of the 'items' parameter and 383 // a flag indicating if the parameter has a value. 384 // 385 // Retrieved list of cloud providers. 386 func (r *CloudRegionsListResponse) GetItems() (value *CloudRegionList, ok bool) { 387 ok = r != nil && r.items != nil 388 if ok { 389 value = r.items 390 } 391 return 392 } 393 394 // Page returns the value of the 'page' parameter. 395 // 396 // Index of the returned page, where one corresponds to the first page. As this 397 // collection doesn't support paging the result will always be `1`. 398 func (r *CloudRegionsListResponse) Page() int { 399 if r != nil && r.page != nil { 400 return *r.page 401 } 402 return 0 403 } 404 405 // GetPage returns the value of the 'page' parameter and 406 // a flag indicating if the parameter has a value. 407 // 408 // Index of the returned page, where one corresponds to the first page. As this 409 // collection doesn't support paging the result will always be `1`. 410 func (r *CloudRegionsListResponse) GetPage() (value int, ok bool) { 411 ok = r != nil && r.page != nil 412 if ok { 413 value = *r.page 414 } 415 return 416 } 417 418 // Size returns the value of the 'size' parameter. 419 // 420 // Number of items that will be contained in the returned page. As this collection 421 // doesn't support paging or searching the result will always be the total number of 422 // regions of the provider. 423 func (r *CloudRegionsListResponse) Size() int { 424 if r != nil && r.size != nil { 425 return *r.size 426 } 427 return 0 428 } 429 430 // GetSize returns the value of the 'size' parameter and 431 // a flag indicating if the parameter has a value. 432 // 433 // Number of items that will be contained in the returned page. As this collection 434 // doesn't support paging or searching the result will always be the total number of 435 // regions of the provider. 436 func (r *CloudRegionsListResponse) GetSize() (value int, ok bool) { 437 ok = r != nil && r.size != nil 438 if ok { 439 value = *r.size 440 } 441 return 442 } 443 444 // Total returns the value of the 'total' parameter. 445 // 446 // Total number of items of the collection that match the search criteria, 447 // regardless of the size of the page. As this collection doesn't support paging or 448 // searching the result will always be the total number of regions of the provider. 449 func (r *CloudRegionsListResponse) Total() int { 450 if r != nil && r.total != nil { 451 return *r.total 452 } 453 return 0 454 } 455 456 // GetTotal returns the value of the 'total' parameter and 457 // a flag indicating if the parameter has a value. 458 // 459 // Total number of items of the collection that match the search criteria, 460 // regardless of the size of the page. As this collection doesn't support paging or 461 // searching the result will always be the total number of regions of the provider. 462 func (r *CloudRegionsListResponse) GetTotal() (value int, ok bool) { 463 ok = r != nil && r.total != nil 464 if ok { 465 value = *r.total 466 } 467 return 468 }