github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/manifests_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/clustersmgmt/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 // ManifestsClient is the client of the 'manifests' resource. 36 // 37 // Manages the collection of Manifests of a cluster. 38 type ManifestsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewManifestsClient creates a new client for the 'manifests' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewManifestsClient(transport http.RoundTripper, path string) *ManifestsClient { 47 return &ManifestsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Adds a new manifest to a cluster. 56 func (c *ManifestsClient) Add() *ManifestsAddRequest { 57 return &ManifestsAddRequest{ 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 manifests. 66 func (c *ManifestsClient) List() *ManifestsListRequest { 67 return &ManifestsListRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Manifest returns the target 'manifest' resource for the given identifier. 74 // 75 // Reference to the service that manages a specific manifest. 76 func (c *ManifestsClient) Manifest(id string) *ManifestClient { 77 return NewManifestClient( 78 c.transport, 79 path.Join(c.path, id), 80 ) 81 } 82 83 // ManifestsAddRequest is the request for the 'add' method. 84 type ManifestsAddRequest struct { 85 transport http.RoundTripper 86 path string 87 query url.Values 88 header http.Header 89 body *Manifest 90 } 91 92 // Parameter adds a query parameter. 93 func (r *ManifestsAddRequest) Parameter(name string, value interface{}) *ManifestsAddRequest { 94 helpers.AddValue(&r.query, name, value) 95 return r 96 } 97 98 // Header adds a request header. 99 func (r *ManifestsAddRequest) Header(name string, value interface{}) *ManifestsAddRequest { 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 *ManifestsAddRequest) Impersonate(user string) *ManifestsAddRequest { 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 manifest. 114 func (r *ManifestsAddRequest) Body(value *Manifest) *ManifestsAddRequest { 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 *ManifestsAddRequest) Send() (result *ManifestsAddResponse, 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 *ManifestsAddRequest) SendContext(ctx context.Context) (result *ManifestsAddResponse, err error) { 129 query := helpers.CopyQuery(r.query) 130 header := helpers.CopyHeader(r.header) 131 buffer := &bytes.Buffer{} 132 err = writeManifestsAddRequest(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 = &ManifestsAddResponse{} 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 = readManifestsAddResponse(result, reader) 172 if err != nil { 173 return 174 } 175 return 176 } 177 178 // ManifestsAddResponse is the response for the 'add' method. 179 type ManifestsAddResponse struct { 180 status int 181 header http.Header 182 err *errors.Error 183 body *Manifest 184 } 185 186 // Status returns the response status code. 187 func (r *ManifestsAddResponse) 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 *ManifestsAddResponse) 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 *ManifestsAddResponse) 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 manifest. 213 func (r *ManifestsAddResponse) Body() *Manifest { 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 manifest. 224 func (r *ManifestsAddResponse) GetBody() (value *Manifest, ok bool) { 225 ok = r != nil && r.body != nil 226 if ok { 227 value = r.body 228 } 229 return 230 } 231 232 // ManifestsListRequest is the request for the 'list' method. 233 type ManifestsListRequest struct { 234 transport http.RoundTripper 235 path string 236 query url.Values 237 header http.Header 238 page *int 239 size *int 240 } 241 242 // Parameter adds a query parameter. 243 func (r *ManifestsListRequest) Parameter(name string, value interface{}) *ManifestsListRequest { 244 helpers.AddValue(&r.query, name, value) 245 return r 246 } 247 248 // Header adds a request header. 249 func (r *ManifestsListRequest) Header(name string, value interface{}) *ManifestsListRequest { 250 helpers.AddHeader(&r.header, name, value) 251 return r 252 } 253 254 // Impersonate wraps requests on behalf of another user. 255 // Note: Services that do not support this feature may silently ignore this call. 256 func (r *ManifestsListRequest) Impersonate(user string) *ManifestsListRequest { 257 helpers.AddImpersonationHeader(&r.header, user) 258 return r 259 } 260 261 // Page sets the value of the 'page' parameter. 262 // 263 // Index of the requested page, where one corresponds to the first page. 264 func (r *ManifestsListRequest) Page(value int) *ManifestsListRequest { 265 r.page = &value 266 return r 267 } 268 269 // Size sets the value of the 'size' parameter. 270 // 271 // Number of items contained in the returned page. 272 func (r *ManifestsListRequest) Size(value int) *ManifestsListRequest { 273 r.size = &value 274 return r 275 } 276 277 // Send sends this request, waits for the response, and returns it. 278 // 279 // This is a potentially lengthy operation, as it requires network communication. 280 // Consider using a context and the SendContext method. 281 func (r *ManifestsListRequest) Send() (result *ManifestsListResponse, err error) { 282 return r.SendContext(context.Background()) 283 } 284 285 // SendContext sends this request, waits for the response, and returns it. 286 func (r *ManifestsListRequest) SendContext(ctx context.Context) (result *ManifestsListResponse, err error) { 287 query := helpers.CopyQuery(r.query) 288 if r.page != nil { 289 helpers.AddValue(&query, "page", *r.page) 290 } 291 if r.size != nil { 292 helpers.AddValue(&query, "size", *r.size) 293 } 294 header := helpers.CopyHeader(r.header) 295 uri := &url.URL{ 296 Path: r.path, 297 RawQuery: query.Encode(), 298 } 299 request := &http.Request{ 300 Method: "GET", 301 URL: uri, 302 Header: header, 303 } 304 if ctx != nil { 305 request = request.WithContext(ctx) 306 } 307 response, err := r.transport.RoundTrip(request) 308 if err != nil { 309 return 310 } 311 defer response.Body.Close() 312 result = &ManifestsListResponse{} 313 result.status = response.StatusCode 314 result.header = response.Header 315 reader := bufio.NewReader(response.Body) 316 _, err = reader.Peek(1) 317 if err == io.EOF { 318 err = nil 319 return 320 } 321 if result.status >= 400 { 322 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 323 if err != nil { 324 return 325 } 326 err = result.err 327 return 328 } 329 err = readManifestsListResponse(result, reader) 330 if err != nil { 331 return 332 } 333 return 334 } 335 336 // ManifestsListResponse is the response for the 'list' method. 337 type ManifestsListResponse struct { 338 status int 339 header http.Header 340 err *errors.Error 341 items *ManifestList 342 page *int 343 size *int 344 total *int 345 } 346 347 // Status returns the response status code. 348 func (r *ManifestsListResponse) Status() int { 349 if r == nil { 350 return 0 351 } 352 return r.status 353 } 354 355 // Header returns header of the response. 356 func (r *ManifestsListResponse) Header() http.Header { 357 if r == nil { 358 return nil 359 } 360 return r.header 361 } 362 363 // Error returns the response error. 364 func (r *ManifestsListResponse) Error() *errors.Error { 365 if r == nil { 366 return nil 367 } 368 return r.err 369 } 370 371 // Items returns the value of the 'items' parameter. 372 // 373 // Retrieved list of Manifests. 374 func (r *ManifestsListResponse) Items() *ManifestList { 375 if r == nil { 376 return nil 377 } 378 return r.items 379 } 380 381 // GetItems returns the value of the 'items' parameter and 382 // a flag indicating if the parameter has a value. 383 // 384 // Retrieved list of Manifests. 385 func (r *ManifestsListResponse) GetItems() (value *ManifestList, ok bool) { 386 ok = r != nil && r.items != nil 387 if ok { 388 value = r.items 389 } 390 return 391 } 392 393 // Page returns the value of the 'page' parameter. 394 // 395 // Index of the requested page, where one corresponds to the first page. 396 func (r *ManifestsListResponse) Page() int { 397 if r != nil && r.page != nil { 398 return *r.page 399 } 400 return 0 401 } 402 403 // GetPage returns the value of the 'page' parameter and 404 // a flag indicating if the parameter has a value. 405 // 406 // Index of the requested page, where one corresponds to the first page. 407 func (r *ManifestsListResponse) GetPage() (value int, ok bool) { 408 ok = r != nil && r.page != nil 409 if ok { 410 value = *r.page 411 } 412 return 413 } 414 415 // Size returns the value of the 'size' parameter. 416 // 417 // Number of items contained in the returned page. 418 func (r *ManifestsListResponse) Size() int { 419 if r != nil && r.size != nil { 420 return *r.size 421 } 422 return 0 423 } 424 425 // GetSize returns the value of the 'size' parameter and 426 // a flag indicating if the parameter has a value. 427 // 428 // Number of items contained in the returned page. 429 func (r *ManifestsListResponse) GetSize() (value int, ok bool) { 430 ok = r != nil && r.size != nil 431 if ok { 432 value = *r.size 433 } 434 return 435 } 436 437 // Total returns the value of the 'total' parameter. 438 // 439 // Total number of items of the collection. 440 func (r *ManifestsListResponse) Total() int { 441 if r != nil && r.total != nil { 442 return *r.total 443 } 444 return 0 445 } 446 447 // GetTotal returns the value of the 'total' parameter and 448 // a flag indicating if the parameter has a value. 449 // 450 // Total number of items of the collection. 451 func (r *ManifestsListResponse) GetTotal() (value int, ok bool) { 452 ok = r != nil && r.total != nil 453 if ok { 454 value = *r.total 455 } 456 return 457 }