github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/managed_identities_requirements_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 "context" 25 "io" 26 "net/http" 27 "net/url" 28 "time" 29 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // ManagedIdentitiesRequirementsClient is the client of the 'managed_identities_requirements' resource. 35 // 36 // Manages the ManagedIdentitiesRequirements resource. 37 type ManagedIdentitiesRequirementsClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewManagedIdentitiesRequirementsClient creates a new client for the 'managed_identities_requirements' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewManagedIdentitiesRequirementsClient(transport http.RoundTripper, path string) *ManagedIdentitiesRequirementsClient { 46 return &ManagedIdentitiesRequirementsClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // Get creates a request for the 'get' method. 53 // 54 // Retrieves an ManagedIdentitiesRequirements by version query param. 55 func (c *ManagedIdentitiesRequirementsClient) Get() *ManagedIdentitiesRequirementsGetRequest { 56 return &ManagedIdentitiesRequirementsGetRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // ManagedIdentitiesRequirementsPollRequest is the request for the Poll method. 63 type ManagedIdentitiesRequirementsPollRequest struct { 64 request *ManagedIdentitiesRequirementsGetRequest 65 interval time.Duration 66 statuses []int 67 predicates []func(interface{}) bool 68 } 69 70 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 71 func (r *ManagedIdentitiesRequirementsPollRequest) Parameter(name string, value interface{}) *ManagedIdentitiesRequirementsPollRequest { 72 r.request.Parameter(name, value) 73 return r 74 } 75 76 // Header adds a request header to all the requests that will be used to retrieve the object. 77 func (r *ManagedIdentitiesRequirementsPollRequest) Header(name string, value interface{}) *ManagedIdentitiesRequirementsPollRequest { 78 r.request.Header(name, value) 79 return r 80 } 81 82 // Required sets the value of the 'required' parameter for all the requests that 83 // will be used to retrieve the object. 84 // 85 // Get the managed identities requirements depending on when they are required. 86 // The query parameter is optional, it needs to be either ("always" or "on_enablement"). 87 // When not supplied, this enablement constraint won't be taken into account. 88 // When supplied and among the accepted values, the query parameter will be used to return all managed identities requirements 89 // that matches the value given in the query parameter. 90 // When supplied but the value is invalid, an error is going to be returned. 91 func (r *ManagedIdentitiesRequirementsPollRequest) Required(value string) *ManagedIdentitiesRequirementsPollRequest { 92 r.request.Required(value) 93 return r 94 } 95 96 // Version sets the value of the 'version' parameter for all the requests that 97 // will be used to retrieve the object. 98 // 99 // Get the managed identities requirements by OpenShift version. 100 // The query parameter is optional, but when supplied it needs to be 101 // in the format X.Y (e.g 4.18) where X and Y are major and minor segments of 102 // the OpenShift version respectively. 103 // When supplied, the returned response will include all the control plane 104 // and data plane operators requirements for the given version. 105 // If not supplied, the OpenShift version constraint won't be taken into account 106 // when returning the managed identities requirements. 107 func (r *ManagedIdentitiesRequirementsPollRequest) Version(value string) *ManagedIdentitiesRequirementsPollRequest { 108 r.request.Version(value) 109 return r 110 } 111 112 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 113 func (r *ManagedIdentitiesRequirementsPollRequest) Interval(value time.Duration) *ManagedIdentitiesRequirementsPollRequest { 114 r.interval = value 115 return r 116 } 117 118 // Status set the expected status of the response. Multiple values can be set calling this method 119 // multiple times. The response will be considered successful if the status is any of those values. 120 func (r *ManagedIdentitiesRequirementsPollRequest) Status(value int) *ManagedIdentitiesRequirementsPollRequest { 121 r.statuses = append(r.statuses, value) 122 return r 123 } 124 125 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 126 // predicates can be set calling this method multiple times. The response will be considered successful 127 // if all the predicates are satisfied. 128 func (r *ManagedIdentitiesRequirementsPollRequest) Predicate(value func(*ManagedIdentitiesRequirementsGetResponse) bool) *ManagedIdentitiesRequirementsPollRequest { 129 r.predicates = append(r.predicates, func(response interface{}) bool { 130 return value(response.(*ManagedIdentitiesRequirementsGetResponse)) 131 }) 132 return r 133 } 134 135 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 136 // the values specified with the Status method and if all the predicates specified with the Predicate 137 // method return nil. 138 // 139 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 140 func (r *ManagedIdentitiesRequirementsPollRequest) StartContext(ctx context.Context) (response *ManagedIdentitiesRequirementsPollResponse, err error) { 141 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 142 if result != nil { 143 response = &ManagedIdentitiesRequirementsPollResponse{ 144 response: result.(*ManagedIdentitiesRequirementsGetResponse), 145 } 146 } 147 return 148 } 149 150 // task adapts the types of the request/response types so that they can be used with the generic 151 // polling function from the helpers package. 152 func (r *ManagedIdentitiesRequirementsPollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 153 response, err := r.request.SendContext(ctx) 154 if response != nil { 155 status = response.Status() 156 result = response 157 } 158 return 159 } 160 161 // ManagedIdentitiesRequirementsPollResponse is the response for the Poll method. 162 type ManagedIdentitiesRequirementsPollResponse struct { 163 response *ManagedIdentitiesRequirementsGetResponse 164 } 165 166 // Status returns the response status code. 167 func (r *ManagedIdentitiesRequirementsPollResponse) Status() int { 168 if r == nil { 169 return 0 170 } 171 return r.response.Status() 172 } 173 174 // Header returns header of the response. 175 func (r *ManagedIdentitiesRequirementsPollResponse) Header() http.Header { 176 if r == nil { 177 return nil 178 } 179 return r.response.Header() 180 } 181 182 // Error returns the response error. 183 func (r *ManagedIdentitiesRequirementsPollResponse) Error() *errors.Error { 184 if r == nil { 185 return nil 186 } 187 return r.response.Error() 188 } 189 190 // Body returns the value of the 'body' parameter. 191 // 192 // ManagedIdentitiesRequirements status response. 193 func (r *ManagedIdentitiesRequirementsPollResponse) Body() *ManagedIdentitiesRequirements { 194 return r.response.Body() 195 } 196 197 // GetBody returns the value of the 'body' parameter and 198 // a flag indicating if the parameter has a value. 199 // 200 // ManagedIdentitiesRequirements status response. 201 func (r *ManagedIdentitiesRequirementsPollResponse) GetBody() (value *ManagedIdentitiesRequirements, ok bool) { 202 return r.response.GetBody() 203 } 204 205 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 206 // of states and satisfies a set of predicates. 207 func (c *ManagedIdentitiesRequirementsClient) Poll() *ManagedIdentitiesRequirementsPollRequest { 208 return &ManagedIdentitiesRequirementsPollRequest{ 209 request: c.Get(), 210 } 211 } 212 213 // ManagedIdentitiesRequirementsGetRequest is the request for the 'get' method. 214 type ManagedIdentitiesRequirementsGetRequest struct { 215 transport http.RoundTripper 216 path string 217 query url.Values 218 header http.Header 219 required *string 220 version *string 221 } 222 223 // Parameter adds a query parameter. 224 func (r *ManagedIdentitiesRequirementsGetRequest) Parameter(name string, value interface{}) *ManagedIdentitiesRequirementsGetRequest { 225 helpers.AddValue(&r.query, name, value) 226 return r 227 } 228 229 // Header adds a request header. 230 func (r *ManagedIdentitiesRequirementsGetRequest) Header(name string, value interface{}) *ManagedIdentitiesRequirementsGetRequest { 231 helpers.AddHeader(&r.header, name, value) 232 return r 233 } 234 235 // Impersonate wraps requests on behalf of another user. 236 // Note: Services that do not support this feature may silently ignore this call. 237 func (r *ManagedIdentitiesRequirementsGetRequest) Impersonate(user string) *ManagedIdentitiesRequirementsGetRequest { 238 helpers.AddImpersonationHeader(&r.header, user) 239 return r 240 } 241 242 // Required sets the value of the 'required' parameter. 243 // 244 // Get the managed identities requirements depending on when they are required. 245 // The query parameter is optional, it needs to be either ("always" or "on_enablement"). 246 // When not supplied, this enablement constraint won't be taken into account. 247 // When supplied and among the accepted values, the query parameter will be used to return all managed identities requirements 248 // that matches the value given in the query parameter. 249 // When supplied but the value is invalid, an error is going to be returned. 250 func (r *ManagedIdentitiesRequirementsGetRequest) Required(value string) *ManagedIdentitiesRequirementsGetRequest { 251 r.required = &value 252 return r 253 } 254 255 // Version sets the value of the 'version' parameter. 256 // 257 // Get the managed identities requirements by OpenShift version. 258 // The query parameter is optional, but when supplied it needs to be 259 // in the format X.Y (e.g 4.18) where X and Y are major and minor segments of 260 // the OpenShift version respectively. 261 // When supplied, the returned response will include all the control plane 262 // and data plane operators requirements for the given version. 263 // If not supplied, the OpenShift version constraint won't be taken into account 264 // when returning the managed identities requirements. 265 func (r *ManagedIdentitiesRequirementsGetRequest) Version(value string) *ManagedIdentitiesRequirementsGetRequest { 266 r.version = &value 267 return r 268 } 269 270 // Send sends this request, waits for the response, and returns it. 271 // 272 // This is a potentially lengthy operation, as it requires network communication. 273 // Consider using a context and the SendContext method. 274 func (r *ManagedIdentitiesRequirementsGetRequest) Send() (result *ManagedIdentitiesRequirementsGetResponse, err error) { 275 return r.SendContext(context.Background()) 276 } 277 278 // SendContext sends this request, waits for the response, and returns it. 279 func (r *ManagedIdentitiesRequirementsGetRequest) SendContext(ctx context.Context) (result *ManagedIdentitiesRequirementsGetResponse, err error) { 280 query := helpers.CopyQuery(r.query) 281 if r.required != nil { 282 helpers.AddValue(&query, "required", *r.required) 283 } 284 if r.version != nil { 285 helpers.AddValue(&query, "version", *r.version) 286 } 287 header := helpers.CopyHeader(r.header) 288 uri := &url.URL{ 289 Path: r.path, 290 RawQuery: query.Encode(), 291 } 292 request := &http.Request{ 293 Method: "GET", 294 URL: uri, 295 Header: header, 296 } 297 if ctx != nil { 298 request = request.WithContext(ctx) 299 } 300 response, err := r.transport.RoundTrip(request) 301 if err != nil { 302 return 303 } 304 defer response.Body.Close() 305 result = &ManagedIdentitiesRequirementsGetResponse{} 306 result.status = response.StatusCode 307 result.header = response.Header 308 reader := bufio.NewReader(response.Body) 309 _, err = reader.Peek(1) 310 if err == io.EOF { 311 err = nil 312 return 313 } 314 if result.status >= 400 { 315 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 316 if err != nil { 317 return 318 } 319 err = result.err 320 return 321 } 322 err = readManagedIdentitiesRequirementsGetResponse(result, reader) 323 if err != nil { 324 return 325 } 326 return 327 } 328 329 // ManagedIdentitiesRequirementsGetResponse is the response for the 'get' method. 330 type ManagedIdentitiesRequirementsGetResponse struct { 331 status int 332 header http.Header 333 err *errors.Error 334 body *ManagedIdentitiesRequirements 335 } 336 337 // Status returns the response status code. 338 func (r *ManagedIdentitiesRequirementsGetResponse) Status() int { 339 if r == nil { 340 return 0 341 } 342 return r.status 343 } 344 345 // Header returns header of the response. 346 func (r *ManagedIdentitiesRequirementsGetResponse) Header() http.Header { 347 if r == nil { 348 return nil 349 } 350 return r.header 351 } 352 353 // Error returns the response error. 354 func (r *ManagedIdentitiesRequirementsGetResponse) Error() *errors.Error { 355 if r == nil { 356 return nil 357 } 358 return r.err 359 } 360 361 // Body returns the value of the 'body' parameter. 362 // 363 // ManagedIdentitiesRequirements status response. 364 func (r *ManagedIdentitiesRequirementsGetResponse) Body() *ManagedIdentitiesRequirements { 365 if r == nil { 366 return nil 367 } 368 return r.body 369 } 370 371 // GetBody returns the value of the 'body' parameter and 372 // a flag indicating if the parameter has a value. 373 // 374 // ManagedIdentitiesRequirements status response. 375 func (r *ManagedIdentitiesRequirementsGetResponse) GetBody() (value *ManagedIdentitiesRequirements, ok bool) { 376 ok = r != nil && r.body != nil 377 if ok { 378 value = r.body 379 } 380 return 381 }