github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/external_auths_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 v1alpha1 // github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1 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 // ExternalAuthsClient is the client of the 'external_auths' resource. 36 // 37 // Manages the collection of external authentication providers defined for an ARO HCP cluster. 38 type ExternalAuthsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewExternalAuthsClient creates a new client for the 'external_auths' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewExternalAuthsClient(transport http.RoundTripper, path string) *ExternalAuthsClient { 47 return &ExternalAuthsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'async_add' method. 54 // 55 // Adds a new external authentication provider to the cluster. 56 func (c *ExternalAuthsClient) Add() *ExternalAuthsAddRequest { 57 return &ExternalAuthsAddRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // List creates a request for the 'list' method. 64 func (c *ExternalAuthsClient) List() *ExternalAuthsListRequest { 65 return &ExternalAuthsListRequest{ 66 transport: c.transport, 67 path: c.path, 68 } 69 } 70 71 // ExternalAuth returns the target 'external_auth' resource for the given identifier. 72 // 73 // Reference to the resource that manages a specific external authentication provider. 74 func (c *ExternalAuthsClient) ExternalAuth(id string) *ExternalAuthClient { 75 return NewExternalAuthClient( 76 c.transport, 77 path.Join(c.path, id), 78 ) 79 } 80 81 // ExternalAuthsAddRequest is the request for the 'async_add' method. 82 type ExternalAuthsAddRequest struct { 83 transport http.RoundTripper 84 path string 85 query url.Values 86 header http.Header 87 body *ExternalAuth 88 } 89 90 // Parameter adds a query parameter. 91 func (r *ExternalAuthsAddRequest) Parameter(name string, value interface{}) *ExternalAuthsAddRequest { 92 helpers.AddValue(&r.query, name, value) 93 return r 94 } 95 96 // Header adds a request header. 97 func (r *ExternalAuthsAddRequest) Header(name string, value interface{}) *ExternalAuthsAddRequest { 98 helpers.AddHeader(&r.header, name, value) 99 return r 100 } 101 102 // Impersonate wraps requests on behalf of another user. 103 // Note: Services that do not support this feature may silently ignore this call. 104 func (r *ExternalAuthsAddRequest) Impersonate(user string) *ExternalAuthsAddRequest { 105 helpers.AddImpersonationHeader(&r.header, user) 106 return r 107 } 108 109 // Body sets the value of the 'body' parameter. 110 // 111 // Description of the external authentication provider. 112 func (r *ExternalAuthsAddRequest) Body(value *ExternalAuth) *ExternalAuthsAddRequest { 113 r.body = value 114 return r 115 } 116 117 // Send sends this request, waits for the response, and returns it. 118 // 119 // This is a potentially lengthy operation, as it requires network communication. 120 // Consider using a context and the SendContext method. 121 func (r *ExternalAuthsAddRequest) Send() (result *ExternalAuthsAddResponse, err error) { 122 return r.SendContext(context.Background()) 123 } 124 125 // SendContext sends this request, waits for the response, and returns it. 126 func (r *ExternalAuthsAddRequest) SendContext(ctx context.Context) (result *ExternalAuthsAddResponse, err error) { 127 query := helpers.CopyQuery(r.query) 128 header := helpers.CopyHeader(r.header) 129 buffer := &bytes.Buffer{} 130 err = writeExternalAuthsAsyncAddRequest(r, buffer) 131 if err != nil { 132 return 133 } 134 uri := &url.URL{ 135 Path: r.path, 136 RawQuery: query.Encode(), 137 } 138 request := &http.Request{ 139 Method: "POST", 140 URL: uri, 141 Header: header, 142 Body: io.NopCloser(buffer), 143 } 144 if ctx != nil { 145 request = request.WithContext(ctx) 146 } 147 response, err := r.transport.RoundTrip(request) 148 if err != nil { 149 return 150 } 151 defer response.Body.Close() 152 result = &ExternalAuthsAddResponse{} 153 result.status = response.StatusCode 154 result.header = response.Header 155 reader := bufio.NewReader(response.Body) 156 _, err = reader.Peek(1) 157 if err == io.EOF { 158 err = nil 159 return 160 } 161 if result.status >= 400 { 162 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 163 if err != nil { 164 return 165 } 166 err = result.err 167 return 168 } 169 err = readExternalAuthsAsyncAddResponse(result, reader) 170 if err != nil { 171 return 172 } 173 return 174 } 175 176 // ExternalAuthsAddResponse is the response for the 'async_add' method. 177 type ExternalAuthsAddResponse struct { 178 status int 179 header http.Header 180 err *errors.Error 181 body *ExternalAuth 182 } 183 184 // Status returns the response status code. 185 func (r *ExternalAuthsAddResponse) Status() int { 186 if r == nil { 187 return 0 188 } 189 return r.status 190 } 191 192 // Header returns header of the response. 193 func (r *ExternalAuthsAddResponse) Header() http.Header { 194 if r == nil { 195 return nil 196 } 197 return r.header 198 } 199 200 // Error returns the response error. 201 func (r *ExternalAuthsAddResponse) Error() *errors.Error { 202 if r == nil { 203 return nil 204 } 205 return r.err 206 } 207 208 // Body returns the value of the 'body' parameter. 209 // 210 // Description of the external authentication provider. 211 func (r *ExternalAuthsAddResponse) Body() *ExternalAuth { 212 if r == nil { 213 return nil 214 } 215 return r.body 216 } 217 218 // GetBody returns the value of the 'body' parameter and 219 // a flag indicating if the parameter has a value. 220 // 221 // Description of the external authentication provider. 222 func (r *ExternalAuthsAddResponse) GetBody() (value *ExternalAuth, ok bool) { 223 ok = r != nil && r.body != nil 224 if ok { 225 value = r.body 226 } 227 return 228 } 229 230 // ExternalAuthsListRequest is the request for the 'list' method. 231 type ExternalAuthsListRequest struct { 232 transport http.RoundTripper 233 path string 234 query url.Values 235 header http.Header 236 page *int 237 size *int 238 } 239 240 // Parameter adds a query parameter. 241 func (r *ExternalAuthsListRequest) Parameter(name string, value interface{}) *ExternalAuthsListRequest { 242 helpers.AddValue(&r.query, name, value) 243 return r 244 } 245 246 // Header adds a request header. 247 func (r *ExternalAuthsListRequest) Header(name string, value interface{}) *ExternalAuthsListRequest { 248 helpers.AddHeader(&r.header, name, value) 249 return r 250 } 251 252 // Impersonate wraps requests on behalf of another user. 253 // Note: Services that do not support this feature may silently ignore this call. 254 func (r *ExternalAuthsListRequest) Impersonate(user string) *ExternalAuthsListRequest { 255 helpers.AddImpersonationHeader(&r.header, user) 256 return r 257 } 258 259 // Page sets the value of the 'page' parameter. 260 // 261 // Index of the requested page, where one corresponds to the first page. 262 func (r *ExternalAuthsListRequest) Page(value int) *ExternalAuthsListRequest { 263 r.page = &value 264 return r 265 } 266 267 // Size sets the value of the 'size' parameter. 268 // 269 // Number of items contained in the returned page. 270 func (r *ExternalAuthsListRequest) Size(value int) *ExternalAuthsListRequest { 271 r.size = &value 272 return r 273 } 274 275 // Send sends this request, waits for the response, and returns it. 276 // 277 // This is a potentially lengthy operation, as it requires network communication. 278 // Consider using a context and the SendContext method. 279 func (r *ExternalAuthsListRequest) Send() (result *ExternalAuthsListResponse, err error) { 280 return r.SendContext(context.Background()) 281 } 282 283 // SendContext sends this request, waits for the response, and returns it. 284 func (r *ExternalAuthsListRequest) SendContext(ctx context.Context) (result *ExternalAuthsListResponse, err error) { 285 query := helpers.CopyQuery(r.query) 286 if r.page != nil { 287 helpers.AddValue(&query, "page", *r.page) 288 } 289 if r.size != nil { 290 helpers.AddValue(&query, "size", *r.size) 291 } 292 header := helpers.CopyHeader(r.header) 293 uri := &url.URL{ 294 Path: r.path, 295 RawQuery: query.Encode(), 296 } 297 request := &http.Request{ 298 Method: "GET", 299 URL: uri, 300 Header: header, 301 } 302 if ctx != nil { 303 request = request.WithContext(ctx) 304 } 305 response, err := r.transport.RoundTrip(request) 306 if err != nil { 307 return 308 } 309 defer response.Body.Close() 310 result = &ExternalAuthsListResponse{} 311 result.status = response.StatusCode 312 result.header = response.Header 313 reader := bufio.NewReader(response.Body) 314 _, err = reader.Peek(1) 315 if err == io.EOF { 316 err = nil 317 return 318 } 319 if result.status >= 400 { 320 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 321 if err != nil { 322 return 323 } 324 err = result.err 325 return 326 } 327 err = readExternalAuthsListResponse(result, reader) 328 if err != nil { 329 return 330 } 331 return 332 } 333 334 // ExternalAuthsListResponse is the response for the 'list' method. 335 type ExternalAuthsListResponse struct { 336 status int 337 header http.Header 338 err *errors.Error 339 items *ExternalAuthList 340 page *int 341 size *int 342 total *int 343 } 344 345 // Status returns the response status code. 346 func (r *ExternalAuthsListResponse) Status() int { 347 if r == nil { 348 return 0 349 } 350 return r.status 351 } 352 353 // Header returns header of the response. 354 func (r *ExternalAuthsListResponse) Header() http.Header { 355 if r == nil { 356 return nil 357 } 358 return r.header 359 } 360 361 // Error returns the response error. 362 func (r *ExternalAuthsListResponse) Error() *errors.Error { 363 if r == nil { 364 return nil 365 } 366 return r.err 367 } 368 369 // Items returns the value of the 'items' parameter. 370 // 371 // Retrieved list of external authentication providers. 372 func (r *ExternalAuthsListResponse) Items() *ExternalAuthList { 373 if r == nil { 374 return nil 375 } 376 return r.items 377 } 378 379 // GetItems returns the value of the 'items' parameter and 380 // a flag indicating if the parameter has a value. 381 // 382 // Retrieved list of external authentication providers. 383 func (r *ExternalAuthsListResponse) GetItems() (value *ExternalAuthList, ok bool) { 384 ok = r != nil && r.items != nil 385 if ok { 386 value = r.items 387 } 388 return 389 } 390 391 // Page returns the value of the 'page' parameter. 392 // 393 // Index of the requested page, where one corresponds to the first page. 394 func (r *ExternalAuthsListResponse) Page() int { 395 if r != nil && r.page != nil { 396 return *r.page 397 } 398 return 0 399 } 400 401 // GetPage returns the value of the 'page' parameter and 402 // a flag indicating if the parameter has a value. 403 // 404 // Index of the requested page, where one corresponds to the first page. 405 func (r *ExternalAuthsListResponse) GetPage() (value int, ok bool) { 406 ok = r != nil && r.page != nil 407 if ok { 408 value = *r.page 409 } 410 return 411 } 412 413 // Size returns the value of the 'size' parameter. 414 // 415 // Number of items contained in the returned page. 416 func (r *ExternalAuthsListResponse) Size() int { 417 if r != nil && r.size != nil { 418 return *r.size 419 } 420 return 0 421 } 422 423 // GetSize returns the value of the 'size' parameter and 424 // a flag indicating if the parameter has a value. 425 // 426 // Number of items contained in the returned page. 427 func (r *ExternalAuthsListResponse) GetSize() (value int, ok bool) { 428 ok = r != nil && r.size != nil 429 if ok { 430 value = *r.size 431 } 432 return 433 } 434 435 // Total returns the value of the 'total' parameter. 436 // 437 // Total number of items of the collection. 438 func (r *ExternalAuthsListResponse) Total() int { 439 if r != nil && r.total != nil { 440 return *r.total 441 } 442 return 0 443 } 444 445 // GetTotal returns the value of the 'total' parameter and 446 // a flag indicating if the parameter has a value. 447 // 448 // Total number of items of the collection. 449 func (r *ExternalAuthsListResponse) GetTotal() (value int, ok bool) { 450 ok = r != nil && r.total != nil 451 if ok { 452 value = *r.total 453 } 454 return 455 }