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