github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/subscriptions_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 // SubscriptionsClient is the client of the 'subscriptions' resource. 36 // 37 // Manages the collection of subscriptions. 38 type SubscriptionsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewSubscriptionsClient creates a new client for the 'subscriptions' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewSubscriptionsClient(transport http.RoundTripper, path string) *SubscriptionsClient { 47 return &SubscriptionsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // List creates a request for the 'list' method. 54 // 55 // Retrieves a list of subscriptions. 56 func (c *SubscriptionsClient) List() *SubscriptionsListRequest { 57 return &SubscriptionsListRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // Post creates a request for the 'post' method. 64 // 65 // Create a new subscription and register a cluster for it. 66 func (c *SubscriptionsClient) Post() *SubscriptionsPostRequest { 67 return &SubscriptionsPostRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Labels returns the target 'generic_labels' resource. 74 // 75 // Reference to the list of labels of a specific subscription. 76 func (c *SubscriptionsClient) Labels() *GenericLabelsClient { 77 return NewGenericLabelsClient( 78 c.transport, 79 path.Join(c.path, "labels"), 80 ) 81 } 82 83 // Subscription returns the target 'subscription' resource for the given identifier. 84 // 85 // Reference to the service that manages a specific subscription. 86 func (c *SubscriptionsClient) Subscription(id string) *SubscriptionClient { 87 return NewSubscriptionClient( 88 c.transport, 89 path.Join(c.path, id), 90 ) 91 } 92 93 // SubscriptionsListRequest is the request for the 'list' method. 94 type SubscriptionsListRequest struct { 95 transport http.RoundTripper 96 path string 97 query url.Values 98 header http.Header 99 fetchAccounts *bool 100 fetchLabels *bool 101 fields *string 102 labels *string 103 order *string 104 page *int 105 search *string 106 size *int 107 } 108 109 // Parameter adds a query parameter. 110 func (r *SubscriptionsListRequest) Parameter(name string, value interface{}) *SubscriptionsListRequest { 111 helpers.AddValue(&r.query, name, value) 112 return r 113 } 114 115 // Header adds a request header. 116 func (r *SubscriptionsListRequest) Header(name string, value interface{}) *SubscriptionsListRequest { 117 helpers.AddHeader(&r.header, name, value) 118 return r 119 } 120 121 // Impersonate wraps requests on behalf of another user. 122 // Note: Services that do not support this feature may silently ignore this call. 123 func (r *SubscriptionsListRequest) Impersonate(user string) *SubscriptionsListRequest { 124 helpers.AddImpersonationHeader(&r.header, user) 125 return r 126 } 127 128 // FetchAccounts sets the value of the 'fetch_accounts' parameter. 129 // 130 // If true, includes the account reference information in the output. Could slow request response time. 131 func (r *SubscriptionsListRequest) FetchAccounts(value bool) *SubscriptionsListRequest { 132 r.fetchAccounts = &value 133 return r 134 } 135 136 // FetchLabels sets the value of the 'fetch_labels' parameter. 137 // 138 // If true, includes the labels on a subscription in the output. Could slow request response time. 139 func (r *SubscriptionsListRequest) FetchLabels(value bool) *SubscriptionsListRequest { 140 r.fetchLabels = &value 141 return r 142 } 143 144 // Fields sets the value of the 'fields' parameter. 145 // 146 // Projection 147 // This field contains a comma-separated list of fields you'd like to get in 148 // a result. No new fields can be added, only existing ones can be filtered. 149 // To specify a field 'id' of a structure 'plan' use 'plan.id'. 150 // To specify all fields of a structure 'labels' use 'labels.*'. 151 func (r *SubscriptionsListRequest) Fields(value string) *SubscriptionsListRequest { 152 r.fields = &value 153 return r 154 } 155 156 // Labels sets the value of the 'labels' parameter. 157 // 158 // Filter subscriptions by a comma separated list of labels: 159 // 160 // [source] 161 // ---- 162 // env=staging,department=sales 163 // ---- 164 func (r *SubscriptionsListRequest) Labels(value string) *SubscriptionsListRequest { 165 r.labels = &value 166 return r 167 } 168 169 // Order sets the value of the 'order' parameter. 170 // 171 // Order criteria. 172 // 173 // The syntax of this parameter is similar to the syntax of the _order by_ clause of 174 // a SQL statement. For example, in order to sort the 175 // subscriptions descending by name identifier the value should be: 176 // 177 // ```sql 178 // name desc 179 // ``` 180 // 181 // If the parameter isn't provided, or if the value is empty, then the order of the 182 // results is undefined. 183 func (r *SubscriptionsListRequest) Order(value string) *SubscriptionsListRequest { 184 r.order = &value 185 return r 186 } 187 188 // Page sets the value of the 'page' parameter. 189 // 190 // Index of the requested page, where one corresponds to the first page. 191 func (r *SubscriptionsListRequest) Page(value int) *SubscriptionsListRequest { 192 r.page = &value 193 return r 194 } 195 196 // Search sets the value of the 'search' parameter. 197 // 198 // Search criteria. 199 // 200 // The syntax of this parameter is similar to the syntax of the _where_ clause of a 201 // SQL statement, but using the names of the attributes of the subscription instead 202 // of the names of the columns of a table. For example, in order to retrieve all the 203 // subscriptions for managed clusters the value should be: 204 // 205 // ```sql 206 // managed = 't' 207 // ``` 208 // 209 // If the parameter isn't provided, or if the value is empty, then all the 210 // clusters that the user has permission to see will be returned. 211 func (r *SubscriptionsListRequest) Search(value string) *SubscriptionsListRequest { 212 r.search = &value 213 return r 214 } 215 216 // Size sets the value of the 'size' parameter. 217 // 218 // Maximum number of items that will be contained in the returned page. 219 func (r *SubscriptionsListRequest) Size(value int) *SubscriptionsListRequest { 220 r.size = &value 221 return r 222 } 223 224 // Send sends this request, waits for the response, and returns it. 225 // 226 // This is a potentially lengthy operation, as it requires network communication. 227 // Consider using a context and the SendContext method. 228 func (r *SubscriptionsListRequest) Send() (result *SubscriptionsListResponse, err error) { 229 return r.SendContext(context.Background()) 230 } 231 232 // SendContext sends this request, waits for the response, and returns it. 233 func (r *SubscriptionsListRequest) SendContext(ctx context.Context) (result *SubscriptionsListResponse, err error) { 234 query := helpers.CopyQuery(r.query) 235 if r.fetchAccounts != nil { 236 helpers.AddValue(&query, "fetchAccounts", *r.fetchAccounts) 237 } 238 if r.fetchLabels != nil { 239 helpers.AddValue(&query, "fetchLabels", *r.fetchLabels) 240 } 241 if r.fields != nil { 242 helpers.AddValue(&query, "fields", *r.fields) 243 } 244 if r.labels != nil { 245 helpers.AddValue(&query, "labels", *r.labels) 246 } 247 if r.order != nil { 248 helpers.AddValue(&query, "order", *r.order) 249 } 250 if r.page != nil { 251 helpers.AddValue(&query, "page", *r.page) 252 } 253 if r.search != nil { 254 helpers.AddValue(&query, "search", *r.search) 255 } 256 if r.size != nil { 257 helpers.AddValue(&query, "size", *r.size) 258 } 259 header := helpers.CopyHeader(r.header) 260 uri := &url.URL{ 261 Path: r.path, 262 RawQuery: query.Encode(), 263 } 264 request := &http.Request{ 265 Method: "GET", 266 URL: uri, 267 Header: header, 268 } 269 if ctx != nil { 270 request = request.WithContext(ctx) 271 } 272 response, err := r.transport.RoundTrip(request) 273 if err != nil { 274 return 275 } 276 defer response.Body.Close() 277 result = &SubscriptionsListResponse{} 278 result.status = response.StatusCode 279 result.header = response.Header 280 reader := bufio.NewReader(response.Body) 281 _, err = reader.Peek(1) 282 if err == io.EOF { 283 err = nil 284 return 285 } 286 if result.status >= 400 { 287 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 288 if err != nil { 289 return 290 } 291 err = result.err 292 return 293 } 294 err = readSubscriptionsListResponse(result, reader) 295 if err != nil { 296 return 297 } 298 return 299 } 300 301 // SubscriptionsListResponse is the response for the 'list' method. 302 type SubscriptionsListResponse struct { 303 status int 304 header http.Header 305 err *errors.Error 306 items *SubscriptionList 307 page *int 308 size *int 309 total *int 310 } 311 312 // Status returns the response status code. 313 func (r *SubscriptionsListResponse) Status() int { 314 if r == nil { 315 return 0 316 } 317 return r.status 318 } 319 320 // Header returns header of the response. 321 func (r *SubscriptionsListResponse) Header() http.Header { 322 if r == nil { 323 return nil 324 } 325 return r.header 326 } 327 328 // Error returns the response error. 329 func (r *SubscriptionsListResponse) Error() *errors.Error { 330 if r == nil { 331 return nil 332 } 333 return r.err 334 } 335 336 // Items returns the value of the 'items' parameter. 337 // 338 // Retrieved list of subscriptions. 339 func (r *SubscriptionsListResponse) Items() *SubscriptionList { 340 if r == nil { 341 return nil 342 } 343 return r.items 344 } 345 346 // GetItems returns the value of the 'items' parameter and 347 // a flag indicating if the parameter has a value. 348 // 349 // Retrieved list of subscriptions. 350 func (r *SubscriptionsListResponse) GetItems() (value *SubscriptionList, ok bool) { 351 ok = r != nil && r.items != nil 352 if ok { 353 value = r.items 354 } 355 return 356 } 357 358 // Page returns the value of the 'page' parameter. 359 // 360 // Index of the requested page, where one corresponds to the first page. 361 func (r *SubscriptionsListResponse) Page() int { 362 if r != nil && r.page != nil { 363 return *r.page 364 } 365 return 0 366 } 367 368 // GetPage returns the value of the 'page' parameter and 369 // a flag indicating if the parameter has a value. 370 // 371 // Index of the requested page, where one corresponds to the first page. 372 func (r *SubscriptionsListResponse) GetPage() (value int, ok bool) { 373 ok = r != nil && r.page != nil 374 if ok { 375 value = *r.page 376 } 377 return 378 } 379 380 // Size returns the value of the 'size' parameter. 381 // 382 // Maximum number of items that will be contained in the returned page. 383 func (r *SubscriptionsListResponse) Size() int { 384 if r != nil && r.size != nil { 385 return *r.size 386 } 387 return 0 388 } 389 390 // GetSize returns the value of the 'size' parameter and 391 // a flag indicating if the parameter has a value. 392 // 393 // Maximum number of items that will be contained in the returned page. 394 func (r *SubscriptionsListResponse) GetSize() (value int, ok bool) { 395 ok = r != nil && r.size != nil 396 if ok { 397 value = *r.size 398 } 399 return 400 } 401 402 // Total returns the value of the 'total' parameter. 403 // 404 // Total number of items of the collection that match the search criteria, 405 // regardless of the size of the page. 406 func (r *SubscriptionsListResponse) Total() int { 407 if r != nil && r.total != nil { 408 return *r.total 409 } 410 return 0 411 } 412 413 // GetTotal returns the value of the 'total' parameter and 414 // a flag indicating if the parameter has a value. 415 // 416 // Total number of items of the collection that match the search criteria, 417 // regardless of the size of the page. 418 func (r *SubscriptionsListResponse) GetTotal() (value int, ok bool) { 419 ok = r != nil && r.total != nil 420 if ok { 421 value = *r.total 422 } 423 return 424 } 425 426 // SubscriptionsPostRequest is the request for the 'post' method. 427 type SubscriptionsPostRequest struct { 428 transport http.RoundTripper 429 path string 430 query url.Values 431 header http.Header 432 request *SubscriptionRegistration 433 } 434 435 // Parameter adds a query parameter. 436 func (r *SubscriptionsPostRequest) Parameter(name string, value interface{}) *SubscriptionsPostRequest { 437 helpers.AddValue(&r.query, name, value) 438 return r 439 } 440 441 // Header adds a request header. 442 func (r *SubscriptionsPostRequest) Header(name string, value interface{}) *SubscriptionsPostRequest { 443 helpers.AddHeader(&r.header, name, value) 444 return r 445 } 446 447 // Impersonate wraps requests on behalf of another user. 448 // Note: Services that do not support this feature may silently ignore this call. 449 func (r *SubscriptionsPostRequest) Impersonate(user string) *SubscriptionsPostRequest { 450 helpers.AddImpersonationHeader(&r.header, user) 451 return r 452 } 453 454 // Request sets the value of the 'request' parameter. 455 func (r *SubscriptionsPostRequest) Request(value *SubscriptionRegistration) *SubscriptionsPostRequest { 456 r.request = value 457 return r 458 } 459 460 // Send sends this request, waits for the response, and returns it. 461 // 462 // This is a potentially lengthy operation, as it requires network communication. 463 // Consider using a context and the SendContext method. 464 func (r *SubscriptionsPostRequest) Send() (result *SubscriptionsPostResponse, err error) { 465 return r.SendContext(context.Background()) 466 } 467 468 // SendContext sends this request, waits for the response, and returns it. 469 func (r *SubscriptionsPostRequest) SendContext(ctx context.Context) (result *SubscriptionsPostResponse, err error) { 470 query := helpers.CopyQuery(r.query) 471 header := helpers.CopyHeader(r.header) 472 buffer := &bytes.Buffer{} 473 err = writeSubscriptionsPostRequest(r, buffer) 474 if err != nil { 475 return 476 } 477 uri := &url.URL{ 478 Path: r.path, 479 RawQuery: query.Encode(), 480 } 481 request := &http.Request{ 482 Method: "POST", 483 URL: uri, 484 Header: header, 485 Body: io.NopCloser(buffer), 486 } 487 if ctx != nil { 488 request = request.WithContext(ctx) 489 } 490 response, err := r.transport.RoundTrip(request) 491 if err != nil { 492 return 493 } 494 defer response.Body.Close() 495 result = &SubscriptionsPostResponse{} 496 result.status = response.StatusCode 497 result.header = response.Header 498 reader := bufio.NewReader(response.Body) 499 _, err = reader.Peek(1) 500 if err == io.EOF { 501 err = nil 502 return 503 } 504 if result.status >= 400 { 505 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 506 if err != nil { 507 return 508 } 509 err = result.err 510 return 511 } 512 err = readSubscriptionsPostResponse(result, reader) 513 if err != nil { 514 return 515 } 516 return 517 } 518 519 // SubscriptionsPostResponse is the response for the 'post' method. 520 type SubscriptionsPostResponse struct { 521 status int 522 header http.Header 523 err *errors.Error 524 response *Subscription 525 } 526 527 // Status returns the response status code. 528 func (r *SubscriptionsPostResponse) Status() int { 529 if r == nil { 530 return 0 531 } 532 return r.status 533 } 534 535 // Header returns header of the response. 536 func (r *SubscriptionsPostResponse) Header() http.Header { 537 if r == nil { 538 return nil 539 } 540 return r.header 541 } 542 543 // Error returns the response error. 544 func (r *SubscriptionsPostResponse) Error() *errors.Error { 545 if r == nil { 546 return nil 547 } 548 return r.err 549 } 550 551 // Response returns the value of the 'response' parameter. 552 func (r *SubscriptionsPostResponse) Response() *Subscription { 553 if r == nil { 554 return nil 555 } 556 return r.response 557 } 558 559 // GetResponse returns the value of the 'response' parameter and 560 // a flag indicating if the parameter has a value. 561 func (r *SubscriptionsPostResponse) GetResponse() (value *Subscription, ok bool) { 562 ok = r != nil && r.response != nil 563 if ok { 564 value = r.response 565 } 566 return 567 }