github.com/openshift-online/ocm-sdk-go@v0.1.473/addonsmgmt/v1/addon_statuses_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 // AddonStatusesClient is the client of the 'addon_statuses' resource. 36 // 37 // Manages the collection of addon statuses for a cluster. 38 type AddonStatusesClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewAddonStatusesClient creates a new client for the 'addon_statuses' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewAddonStatusesClient(transport http.RoundTripper, path string) *AddonStatusesClient { 47 return &AddonStatusesClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Create a new addon status and add it to the collection of addons statuses. 56 func (c *AddonStatusesClient) Add() *AddonStatusesAddRequest { 57 return &AddonStatusesAddRequest{ 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 addon statuses for a cluster. 66 func (c *AddonStatusesClient) List() *AddonStatusesListRequest { 67 return &AddonStatusesListRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Addon returns the target 'addon_status' resource for the given identifier. 74 // 75 // Returns a reference to a specific addon status. 76 func (c *AddonStatusesClient) Addon(id string) *AddonStatusClient { 77 return NewAddonStatusClient( 78 c.transport, 79 path.Join(c.path, id), 80 ) 81 } 82 83 // AddonStatusesAddRequest is the request for the 'add' method. 84 type AddonStatusesAddRequest struct { 85 transport http.RoundTripper 86 path string 87 query url.Values 88 header http.Header 89 body *AddonStatus 90 } 91 92 // Parameter adds a query parameter. 93 func (r *AddonStatusesAddRequest) Parameter(name string, value interface{}) *AddonStatusesAddRequest { 94 helpers.AddValue(&r.query, name, value) 95 return r 96 } 97 98 // Header adds a request header. 99 func (r *AddonStatusesAddRequest) Header(name string, value interface{}) *AddonStatusesAddRequest { 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 *AddonStatusesAddRequest) Impersonate(user string) *AddonStatusesAddRequest { 107 helpers.AddImpersonationHeader(&r.header, user) 108 return r 109 } 110 111 // Body sets the value of the 'body' parameter. 112 // 113 // Description of the addon status. 114 func (r *AddonStatusesAddRequest) Body(value *AddonStatus) *AddonStatusesAddRequest { 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 *AddonStatusesAddRequest) Send() (result *AddonStatusesAddResponse, 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 *AddonStatusesAddRequest) SendContext(ctx context.Context) (result *AddonStatusesAddResponse, err error) { 129 query := helpers.CopyQuery(r.query) 130 header := helpers.CopyHeader(r.header) 131 buffer := &bytes.Buffer{} 132 err = writeAddonStatusesAddRequest(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 = &AddonStatusesAddResponse{} 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 = readAddonStatusesAddResponse(result, reader) 172 if err != nil { 173 return 174 } 175 return 176 } 177 178 // AddonStatusesAddResponse is the response for the 'add' method. 179 type AddonStatusesAddResponse struct { 180 status int 181 header http.Header 182 err *errors.Error 183 body *AddonStatus 184 } 185 186 // Status returns the response status code. 187 func (r *AddonStatusesAddResponse) 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 *AddonStatusesAddResponse) 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 *AddonStatusesAddResponse) 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 // Description of the addon status. 213 func (r *AddonStatusesAddResponse) Body() *AddonStatus { 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 // Description of the addon status. 224 func (r *AddonStatusesAddResponse) GetBody() (value *AddonStatus, ok bool) { 225 ok = r != nil && r.body != nil 226 if ok { 227 value = r.body 228 } 229 return 230 } 231 232 // AddonStatusesListRequest is the request for the 'list' method. 233 type AddonStatusesListRequest struct { 234 transport http.RoundTripper 235 path string 236 query url.Values 237 header http.Header 238 order *string 239 page *int 240 size *int 241 } 242 243 // Parameter adds a query parameter. 244 func (r *AddonStatusesListRequest) Parameter(name string, value interface{}) *AddonStatusesListRequest { 245 helpers.AddValue(&r.query, name, value) 246 return r 247 } 248 249 // Header adds a request header. 250 func (r *AddonStatusesListRequest) Header(name string, value interface{}) *AddonStatusesListRequest { 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 *AddonStatusesListRequest) Impersonate(user string) *AddonStatusesListRequest { 258 helpers.AddImpersonationHeader(&r.header, user) 259 return r 260 } 261 262 // Order sets the value of the 'order' parameter. 263 // 264 // If the parameter isn't provided, or if the value is empty, then the order of the 265 // results is undefined. 266 func (r *AddonStatusesListRequest) Order(value string) *AddonStatusesListRequest { 267 r.order = &value 268 return r 269 } 270 271 // Page sets the value of the 'page' parameter. 272 // 273 // Index of the requested page, where one corresponds to the first page. 274 func (r *AddonStatusesListRequest) Page(value int) *AddonStatusesListRequest { 275 r.page = &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 *AddonStatusesListRequest) Size(value int) *AddonStatusesListRequest { 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 *AddonStatusesListRequest) Send() (result *AddonStatusesListResponse, 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 *AddonStatusesListRequest) SendContext(ctx context.Context) (result *AddonStatusesListResponse, err error) { 297 query := helpers.CopyQuery(r.query) 298 if r.order != nil { 299 helpers.AddValue(&query, "order", *r.order) 300 } 301 if r.page != nil { 302 helpers.AddValue(&query, "page", *r.page) 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 = &AddonStatusesListResponse{} 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 = readAddonStatusesListResponse(result, reader) 343 if err != nil { 344 return 345 } 346 return 347 } 348 349 // AddonStatusesListResponse is the response for the 'list' method. 350 type AddonStatusesListResponse struct { 351 status int 352 header http.Header 353 err *errors.Error 354 items *AddonStatusList 355 page *int 356 size *int 357 total *int 358 } 359 360 // Status returns the response status code. 361 func (r *AddonStatusesListResponse) 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 *AddonStatusesListResponse) 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 *AddonStatusesListResponse) 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 addon status conditions 387 func (r *AddonStatusesListResponse) Items() *AddonStatusList { 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 addon status conditions 398 func (r *AddonStatusesListResponse) GetItems() (value *AddonStatusList, 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 *AddonStatusesListResponse) 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 *AddonStatusesListResponse) 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 *AddonStatusesListResponse) 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 *AddonStatusesListResponse) 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 regardless of the size of the page. 453 func (r *AddonStatusesListResponse) Total() int { 454 if r != nil && r.total != nil { 455 return *r.total 456 } 457 return 0 458 } 459 460 // GetTotal returns the value of the 'total' parameter and 461 // a flag indicating if the parameter has a value. 462 // 463 // Total number of items of the collection regardless of the size of the page. 464 func (r *AddonStatusesListResponse) GetTotal() (value int, ok bool) { 465 ok = r != nil && r.total != nil 466 if ok { 467 value = *r.total 468 } 469 return 470 }