github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/cloud_resources_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/accountsmgmt/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 // CloudResourcesClient is the client of the 'cloud_resources' resource. 36 // 37 // Manages the collection of cloud resources. 38 type CloudResourcesClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewCloudResourcesClient creates a new client for the 'cloud_resources' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewCloudResourcesClient(transport http.RoundTripper, path string) *CloudResourcesClient { 47 return &CloudResourcesClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Creates a new cloud resource 56 func (c *CloudResourcesClient) Add() *CloudResourcesAddRequest { 57 return &CloudResourcesAddRequest{ 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 cloud resources. 66 func (c *CloudResourcesClient) List() *CloudResourcesListRequest { 67 return &CloudResourcesListRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // CloudResource returns the target 'cloud_resource' resource for the given identifier. 74 // 75 // Reference to the service that manages a specific cloud resource. 76 func (c *CloudResourcesClient) CloudResource(id string) *CloudResourceClient { 77 return NewCloudResourceClient( 78 c.transport, 79 path.Join(c.path, id), 80 ) 81 } 82 83 // CloudResourcesAddRequest is the request for the 'add' method. 84 type CloudResourcesAddRequest struct { 85 transport http.RoundTripper 86 path string 87 query url.Values 88 header http.Header 89 body *CloudResource 90 } 91 92 // Parameter adds a query parameter. 93 func (r *CloudResourcesAddRequest) Parameter(name string, value interface{}) *CloudResourcesAddRequest { 94 helpers.AddValue(&r.query, name, value) 95 return r 96 } 97 98 // Header adds a request header. 99 func (r *CloudResourcesAddRequest) Header(name string, value interface{}) *CloudResourcesAddRequest { 100 helpers.AddHeader(&r.header, name, value) 101 return r 102 } 103 104 // Impersonate wraps requests on behalf of another user. 105 // Note: Services that do not support this feature may silently ignore this call. 106 func (r *CloudResourcesAddRequest) Impersonate(user string) *CloudResourcesAddRequest { 107 helpers.AddImpersonationHeader(&r.header, user) 108 return r 109 } 110 111 // Body sets the value of the 'body' parameter. 112 func (r *CloudResourcesAddRequest) Body(value *CloudResource) *CloudResourcesAddRequest { 113 r.body = value 114 return r 115 } 116 117 // Send sends this request, waits for the response, and returns it. 118 // 119 // This is a potentially lengthy operation, as it requires network communication. 120 // Consider using a context and the SendContext method. 121 func (r *CloudResourcesAddRequest) Send() (result *CloudResourcesAddResponse, err error) { 122 return r.SendContext(context.Background()) 123 } 124 125 // SendContext sends this request, waits for the response, and returns it. 126 func (r *CloudResourcesAddRequest) SendContext(ctx context.Context) (result *CloudResourcesAddResponse, err error) { 127 query := helpers.CopyQuery(r.query) 128 header := helpers.CopyHeader(r.header) 129 buffer := &bytes.Buffer{} 130 err = writeCloudResourcesAddRequest(r, buffer) 131 if err != nil { 132 return 133 } 134 uri := &url.URL{ 135 Path: r.path, 136 RawQuery: query.Encode(), 137 } 138 request := &http.Request{ 139 Method: "POST", 140 URL: uri, 141 Header: header, 142 Body: io.NopCloser(buffer), 143 } 144 if ctx != nil { 145 request = request.WithContext(ctx) 146 } 147 response, err := r.transport.RoundTrip(request) 148 if err != nil { 149 return 150 } 151 defer response.Body.Close() 152 result = &CloudResourcesAddResponse{} 153 result.status = response.StatusCode 154 result.header = response.Header 155 reader := bufio.NewReader(response.Body) 156 _, err = reader.Peek(1) 157 if err == io.EOF { 158 err = nil 159 return 160 } 161 if result.status >= 400 { 162 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 163 if err != nil { 164 return 165 } 166 err = result.err 167 return 168 } 169 err = readCloudResourcesAddResponse(result, reader) 170 if err != nil { 171 return 172 } 173 return 174 } 175 176 // CloudResourcesAddResponse is the response for the 'add' method. 177 type CloudResourcesAddResponse struct { 178 status int 179 header http.Header 180 err *errors.Error 181 body *CloudResource 182 } 183 184 // Status returns the response status code. 185 func (r *CloudResourcesAddResponse) Status() int { 186 if r == nil { 187 return 0 188 } 189 return r.status 190 } 191 192 // Header returns header of the response. 193 func (r *CloudResourcesAddResponse) Header() http.Header { 194 if r == nil { 195 return nil 196 } 197 return r.header 198 } 199 200 // Error returns the response error. 201 func (r *CloudResourcesAddResponse) Error() *errors.Error { 202 if r == nil { 203 return nil 204 } 205 return r.err 206 } 207 208 // Body returns the value of the 'body' parameter. 209 func (r *CloudResourcesAddResponse) Body() *CloudResource { 210 if r == nil { 211 return nil 212 } 213 return r.body 214 } 215 216 // GetBody returns the value of the 'body' parameter and 217 // a flag indicating if the parameter has a value. 218 func (r *CloudResourcesAddResponse) GetBody() (value *CloudResource, ok bool) { 219 ok = r != nil && r.body != nil 220 if ok { 221 value = r.body 222 } 223 return 224 } 225 226 // CloudResourcesListRequest is the request for the 'list' method. 227 type CloudResourcesListRequest struct { 228 transport http.RoundTripper 229 path string 230 query url.Values 231 header http.Header 232 page *int 233 search *string 234 size *int 235 } 236 237 // Parameter adds a query parameter. 238 func (r *CloudResourcesListRequest) Parameter(name string, value interface{}) *CloudResourcesListRequest { 239 helpers.AddValue(&r.query, name, value) 240 return r 241 } 242 243 // Header adds a request header. 244 func (r *CloudResourcesListRequest) Header(name string, value interface{}) *CloudResourcesListRequest { 245 helpers.AddHeader(&r.header, name, value) 246 return r 247 } 248 249 // Impersonate wraps requests on behalf of another user. 250 // Note: Services that do not support this feature may silently ignore this call. 251 func (r *CloudResourcesListRequest) Impersonate(user string) *CloudResourcesListRequest { 252 helpers.AddImpersonationHeader(&r.header, user) 253 return r 254 } 255 256 // Page sets the value of the 'page' parameter. 257 // 258 // Index of the requested page, where one corresponds to the first page. 259 func (r *CloudResourcesListRequest) Page(value int) *CloudResourcesListRequest { 260 r.page = &value 261 return r 262 } 263 264 // Search sets the value of the 'search' parameter. 265 // 266 // Search criteria. 267 // 268 // The syntax of this parameter is similar to the syntax of the _where_ clause 269 // of an SQL statement, but using the names of the attributes of the cloud resource 270 // instead of the names of the columns of a table. 271 // 272 // If the parameter isn't provided, or if the value is empty, then all the 273 // items that the user has permission to see will be returned. 274 func (r *CloudResourcesListRequest) Search(value string) *CloudResourcesListRequest { 275 r.search = &value 276 return r 277 } 278 279 // Size sets the value of the 'size' parameter. 280 // 281 // Maximum number of items that will be contained in the returned page. 282 func (r *CloudResourcesListRequest) Size(value int) *CloudResourcesListRequest { 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 *CloudResourcesListRequest) Send() (result *CloudResourcesListResponse, 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 *CloudResourcesListRequest) SendContext(ctx context.Context) (result *CloudResourcesListResponse, err error) { 297 query := helpers.CopyQuery(r.query) 298 if r.page != nil { 299 helpers.AddValue(&query, "page", *r.page) 300 } 301 if r.search != nil { 302 helpers.AddValue(&query, "search", *r.search) 303 } 304 if r.size != nil { 305 helpers.AddValue(&query, "size", *r.size) 306 } 307 header := helpers.CopyHeader(r.header) 308 uri := &url.URL{ 309 Path: r.path, 310 RawQuery: query.Encode(), 311 } 312 request := &http.Request{ 313 Method: "GET", 314 URL: uri, 315 Header: header, 316 } 317 if ctx != nil { 318 request = request.WithContext(ctx) 319 } 320 response, err := r.transport.RoundTrip(request) 321 if err != nil { 322 return 323 } 324 defer response.Body.Close() 325 result = &CloudResourcesListResponse{} 326 result.status = response.StatusCode 327 result.header = response.Header 328 reader := bufio.NewReader(response.Body) 329 _, err = reader.Peek(1) 330 if err == io.EOF { 331 err = nil 332 return 333 } 334 if result.status >= 400 { 335 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 336 if err != nil { 337 return 338 } 339 err = result.err 340 return 341 } 342 err = readCloudResourcesListResponse(result, reader) 343 if err != nil { 344 return 345 } 346 return 347 } 348 349 // CloudResourcesListResponse is the response for the 'list' method. 350 type CloudResourcesListResponse struct { 351 status int 352 header http.Header 353 err *errors.Error 354 items *CloudResourceList 355 page *int 356 size *int 357 total *int 358 } 359 360 // Status returns the response status code. 361 func (r *CloudResourcesListResponse) Status() int { 362 if r == nil { 363 return 0 364 } 365 return r.status 366 } 367 368 // Header returns header of the response. 369 func (r *CloudResourcesListResponse) Header() http.Header { 370 if r == nil { 371 return nil 372 } 373 return r.header 374 } 375 376 // Error returns the response error. 377 func (r *CloudResourcesListResponse) Error() *errors.Error { 378 if r == nil { 379 return nil 380 } 381 return r.err 382 } 383 384 // Items returns the value of the 'items' parameter. 385 // 386 // Retrieved list of cloud resources. 387 func (r *CloudResourcesListResponse) Items() *CloudResourceList { 388 if r == nil { 389 return nil 390 } 391 return r.items 392 } 393 394 // GetItems returns the value of the 'items' parameter and 395 // a flag indicating if the parameter has a value. 396 // 397 // Retrieved list of cloud resources. 398 func (r *CloudResourcesListResponse) GetItems() (value *CloudResourceList, ok bool) { 399 ok = r != nil && r.items != nil 400 if ok { 401 value = r.items 402 } 403 return 404 } 405 406 // Page returns the value of the 'page' parameter. 407 // 408 // Index of the requested page, where one corresponds to the first page. 409 func (r *CloudResourcesListResponse) Page() int { 410 if r != nil && r.page != nil { 411 return *r.page 412 } 413 return 0 414 } 415 416 // GetPage returns the value of the 'page' parameter and 417 // a flag indicating if the parameter has a value. 418 // 419 // Index of the requested page, where one corresponds to the first page. 420 func (r *CloudResourcesListResponse) GetPage() (value int, ok bool) { 421 ok = r != nil && r.page != nil 422 if ok { 423 value = *r.page 424 } 425 return 426 } 427 428 // Size returns the value of the 'size' parameter. 429 // 430 // Maximum number of items that will be contained in the returned page. 431 func (r *CloudResourcesListResponse) Size() int { 432 if r != nil && r.size != nil { 433 return *r.size 434 } 435 return 0 436 } 437 438 // GetSize returns the value of the 'size' parameter and 439 // a flag indicating if the parameter has a value. 440 // 441 // Maximum number of items that will be contained in the returned page. 442 func (r *CloudResourcesListResponse) GetSize() (value int, ok bool) { 443 ok = r != nil && r.size != nil 444 if ok { 445 value = *r.size 446 } 447 return 448 } 449 450 // Total returns the value of the 'total' parameter. 451 // 452 // Total number of items of the collection that match the search criteria, 453 // regardless of the size of the page. 454 func (r *CloudResourcesListResponse) Total() int { 455 if r != nil && r.total != nil { 456 return *r.total 457 } 458 return 0 459 } 460 461 // GetTotal returns the value of the 'total' parameter and 462 // a flag indicating if the parameter has a value. 463 // 464 // Total number of items of the collection that match the search criteria, 465 // regardless of the size of the page. 466 func (r *CloudResourcesListResponse) GetTotal() (value int, ok bool) { 467 ok = r != nil && r.total != nil 468 if ok { 469 value = *r.total 470 } 471 return 472 }