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