github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/registry_credentials_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 // RegistryCredentialsClient is the client of the 'registry_credentials' resource. 36 // 37 // Manages the collection of registry credentials. 38 type RegistryCredentialsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewRegistryCredentialsClient creates a new client for the 'registry_credentials' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewRegistryCredentialsClient(transport http.RoundTripper, path string) *RegistryCredentialsClient { 47 return &RegistryCredentialsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Creates a new registry credential. 56 func (c *RegistryCredentialsClient) Add() *RegistryCredentialsAddRequest { 57 return &RegistryCredentialsAddRequest{ 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 accounts. 66 func (c *RegistryCredentialsClient) List() *RegistryCredentialsListRequest { 67 return &RegistryCredentialsListRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // RegistryCredential returns the target 'registry_credential' resource for the given identifier. 74 // 75 // Reference to the service that manages an specific registry credential. 76 func (c *RegistryCredentialsClient) RegistryCredential(id string) *RegistryCredentialClient { 77 return NewRegistryCredentialClient( 78 c.transport, 79 path.Join(c.path, id), 80 ) 81 } 82 83 // RegistryCredentialsAddRequest is the request for the 'add' method. 84 type RegistryCredentialsAddRequest struct { 85 transport http.RoundTripper 86 path string 87 query url.Values 88 header http.Header 89 body *RegistryCredential 90 } 91 92 // Parameter adds a query parameter. 93 func (r *RegistryCredentialsAddRequest) Parameter(name string, value interface{}) *RegistryCredentialsAddRequest { 94 helpers.AddValue(&r.query, name, value) 95 return r 96 } 97 98 // Header adds a request header. 99 func (r *RegistryCredentialsAddRequest) Header(name string, value interface{}) *RegistryCredentialsAddRequest { 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 *RegistryCredentialsAddRequest) Impersonate(user string) *RegistryCredentialsAddRequest { 107 helpers.AddImpersonationHeader(&r.header, user) 108 return r 109 } 110 111 // Body sets the value of the 'body' parameter. 112 // 113 // Registry credential data. 114 func (r *RegistryCredentialsAddRequest) Body(value *RegistryCredential) *RegistryCredentialsAddRequest { 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 *RegistryCredentialsAddRequest) Send() (result *RegistryCredentialsAddResponse, 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 *RegistryCredentialsAddRequest) SendContext(ctx context.Context) (result *RegistryCredentialsAddResponse, err error) { 129 query := helpers.CopyQuery(r.query) 130 header := helpers.CopyHeader(r.header) 131 buffer := &bytes.Buffer{} 132 err = writeRegistryCredentialsAddRequest(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 = &RegistryCredentialsAddResponse{} 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 = readRegistryCredentialsAddResponse(result, reader) 172 if err != nil { 173 return 174 } 175 return 176 } 177 178 // RegistryCredentialsAddResponse is the response for the 'add' method. 179 type RegistryCredentialsAddResponse struct { 180 status int 181 header http.Header 182 err *errors.Error 183 body *RegistryCredential 184 } 185 186 // Status returns the response status code. 187 func (r *RegistryCredentialsAddResponse) 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 *RegistryCredentialsAddResponse) 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 *RegistryCredentialsAddResponse) 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 // Registry credential data. 213 func (r *RegistryCredentialsAddResponse) Body() *RegistryCredential { 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 // Registry credential data. 224 func (r *RegistryCredentialsAddResponse) GetBody() (value *RegistryCredential, ok bool) { 225 ok = r != nil && r.body != nil 226 if ok { 227 value = r.body 228 } 229 return 230 } 231 232 // RegistryCredentialsListRequest is the request for the 'list' method. 233 type RegistryCredentialsListRequest struct { 234 transport http.RoundTripper 235 path string 236 query url.Values 237 header http.Header 238 order *string 239 page *int 240 search *string 241 size *int 242 } 243 244 // Parameter adds a query parameter. 245 func (r *RegistryCredentialsListRequest) Parameter(name string, value interface{}) *RegistryCredentialsListRequest { 246 helpers.AddValue(&r.query, name, value) 247 return r 248 } 249 250 // Header adds a request header. 251 func (r *RegistryCredentialsListRequest) Header(name string, value interface{}) *RegistryCredentialsListRequest { 252 helpers.AddHeader(&r.header, name, value) 253 return r 254 } 255 256 // Impersonate wraps requests on behalf of another user. 257 // Note: Services that do not support this feature may silently ignore this call. 258 func (r *RegistryCredentialsListRequest) Impersonate(user string) *RegistryCredentialsListRequest { 259 helpers.AddImpersonationHeader(&r.header, user) 260 return r 261 } 262 263 // Order sets the value of the 'order' parameter. 264 // 265 // Order criteria. 266 // 267 // The syntax of this parameter is similar to the syntax of the _order by_ clause of 268 // a SQL statement. For example, in order to sort the 269 // RegistryCredentials descending by username the value should be: 270 // 271 // ```sql 272 // username desc 273 // ``` 274 // 275 // If the parameter isn't provided, or if the value is empty, then the order of the 276 // results is undefined. 277 func (r *RegistryCredentialsListRequest) Order(value string) *RegistryCredentialsListRequest { 278 r.order = &value 279 return r 280 } 281 282 // Page sets the value of the 'page' parameter. 283 // 284 // Index of the requested page, where one corresponds to the first page. 285 func (r *RegistryCredentialsListRequest) Page(value int) *RegistryCredentialsListRequest { 286 r.page = &value 287 return r 288 } 289 290 // Search sets the value of the 'search' parameter. 291 // 292 // Search criteria. 293 // 294 // The syntax of this parameter is similar to the syntax of the _where_ clause of a 295 // SQL statement, but using the names of the attributes of the RegistryCredentials instead 296 // of the names of the columns of a table. For example, in order to retrieve all the 297 // RegistryCredentials for a user the value should be: 298 // 299 // ```sql 300 // username = 'abcxyz...' 301 // ``` 302 // 303 // If the parameter isn't provided, or if the value is empty, then all the 304 // RegistryCredentials that the user has permission to see will be returned. 305 func (r *RegistryCredentialsListRequest) Search(value string) *RegistryCredentialsListRequest { 306 r.search = &value 307 return r 308 } 309 310 // Size sets the value of the 'size' parameter. 311 // 312 // Maximum number of items that will be contained in the returned page. 313 func (r *RegistryCredentialsListRequest) Size(value int) *RegistryCredentialsListRequest { 314 r.size = &value 315 return r 316 } 317 318 // Send sends this request, waits for the response, and returns it. 319 // 320 // This is a potentially lengthy operation, as it requires network communication. 321 // Consider using a context and the SendContext method. 322 func (r *RegistryCredentialsListRequest) Send() (result *RegistryCredentialsListResponse, err error) { 323 return r.SendContext(context.Background()) 324 } 325 326 // SendContext sends this request, waits for the response, and returns it. 327 func (r *RegistryCredentialsListRequest) SendContext(ctx context.Context) (result *RegistryCredentialsListResponse, err error) { 328 query := helpers.CopyQuery(r.query) 329 if r.order != nil { 330 helpers.AddValue(&query, "order", *r.order) 331 } 332 if r.page != nil { 333 helpers.AddValue(&query, "page", *r.page) 334 } 335 if r.search != nil { 336 helpers.AddValue(&query, "search", *r.search) 337 } 338 if r.size != nil { 339 helpers.AddValue(&query, "size", *r.size) 340 } 341 header := helpers.CopyHeader(r.header) 342 uri := &url.URL{ 343 Path: r.path, 344 RawQuery: query.Encode(), 345 } 346 request := &http.Request{ 347 Method: "GET", 348 URL: uri, 349 Header: header, 350 } 351 if ctx != nil { 352 request = request.WithContext(ctx) 353 } 354 response, err := r.transport.RoundTrip(request) 355 if err != nil { 356 return 357 } 358 defer response.Body.Close() 359 result = &RegistryCredentialsListResponse{} 360 result.status = response.StatusCode 361 result.header = response.Header 362 reader := bufio.NewReader(response.Body) 363 _, err = reader.Peek(1) 364 if err == io.EOF { 365 err = nil 366 return 367 } 368 if result.status >= 400 { 369 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 370 if err != nil { 371 return 372 } 373 err = result.err 374 return 375 } 376 err = readRegistryCredentialsListResponse(result, reader) 377 if err != nil { 378 return 379 } 380 return 381 } 382 383 // RegistryCredentialsListResponse is the response for the 'list' method. 384 type RegistryCredentialsListResponse struct { 385 status int 386 header http.Header 387 err *errors.Error 388 items *RegistryCredentialList 389 page *int 390 size *int 391 total *int 392 } 393 394 // Status returns the response status code. 395 func (r *RegistryCredentialsListResponse) Status() int { 396 if r == nil { 397 return 0 398 } 399 return r.status 400 } 401 402 // Header returns header of the response. 403 func (r *RegistryCredentialsListResponse) Header() http.Header { 404 if r == nil { 405 return nil 406 } 407 return r.header 408 } 409 410 // Error returns the response error. 411 func (r *RegistryCredentialsListResponse) Error() *errors.Error { 412 if r == nil { 413 return nil 414 } 415 return r.err 416 } 417 418 // Items returns the value of the 'items' parameter. 419 // 420 // Retrieved list of registry credentials. 421 func (r *RegistryCredentialsListResponse) Items() *RegistryCredentialList { 422 if r == nil { 423 return nil 424 } 425 return r.items 426 } 427 428 // GetItems returns the value of the 'items' parameter and 429 // a flag indicating if the parameter has a value. 430 // 431 // Retrieved list of registry credentials. 432 func (r *RegistryCredentialsListResponse) GetItems() (value *RegistryCredentialList, ok bool) { 433 ok = r != nil && r.items != nil 434 if ok { 435 value = r.items 436 } 437 return 438 } 439 440 // Page returns the value of the 'page' parameter. 441 // 442 // Index of the requested page, where one corresponds to the first page. 443 func (r *RegistryCredentialsListResponse) Page() int { 444 if r != nil && r.page != nil { 445 return *r.page 446 } 447 return 0 448 } 449 450 // GetPage returns the value of the 'page' parameter and 451 // a flag indicating if the parameter has a value. 452 // 453 // Index of the requested page, where one corresponds to the first page. 454 func (r *RegistryCredentialsListResponse) GetPage() (value int, ok bool) { 455 ok = r != nil && r.page != nil 456 if ok { 457 value = *r.page 458 } 459 return 460 } 461 462 // Size returns the value of the 'size' parameter. 463 // 464 // Maximum number of items that will be contained in the returned page. 465 func (r *RegistryCredentialsListResponse) Size() int { 466 if r != nil && r.size != nil { 467 return *r.size 468 } 469 return 0 470 } 471 472 // GetSize returns the value of the 'size' parameter and 473 // a flag indicating if the parameter has a value. 474 // 475 // Maximum number of items that will be contained in the returned page. 476 func (r *RegistryCredentialsListResponse) GetSize() (value int, ok bool) { 477 ok = r != nil && r.size != nil 478 if ok { 479 value = *r.size 480 } 481 return 482 } 483 484 // Total returns the value of the 'total' parameter. 485 // 486 // Total number of items of the collection that match the search criteria, 487 // regardless of the size of the page. 488 func (r *RegistryCredentialsListResponse) Total() int { 489 if r != nil && r.total != nil { 490 return *r.total 491 } 492 return 0 493 } 494 495 // GetTotal returns the value of the 'total' parameter and 496 // a flag indicating if the parameter has a value. 497 // 498 // Total number of items of the collection that match the search criteria, 499 // regardless of the size of the page. 500 func (r *RegistryCredentialsListResponse) GetTotal() (value int, ok bool) { 501 ok = r != nil && r.total != nil 502 if ok { 503 value = *r.total 504 } 505 return 506 }