github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/upgrade_policy_state_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 "time" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // UpgradePolicyStateClient is the client of the 'upgrade_policy_state' resource. 36 // 37 // Manages a specific upgrade policy state. 38 type UpgradePolicyStateClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewUpgradePolicyStateClient creates a new client for the 'upgrade_policy_state' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewUpgradePolicyStateClient(transport http.RoundTripper, path string) *UpgradePolicyStateClient { 47 return &UpgradePolicyStateClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Get creates a request for the 'get' method. 54 // 55 // Retrieves the details of the upgrade policy state. 56 func (c *UpgradePolicyStateClient) Get() *UpgradePolicyStateGetRequest { 57 return &UpgradePolicyStateGetRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // Update creates a request for the 'update' method. 64 // 65 // Update the upgrade policy state. 66 func (c *UpgradePolicyStateClient) Update() *UpgradePolicyStateUpdateRequest { 67 return &UpgradePolicyStateUpdateRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // UpgradePolicyStatePollRequest is the request for the Poll method. 74 type UpgradePolicyStatePollRequest struct { 75 request *UpgradePolicyStateGetRequest 76 interval time.Duration 77 statuses []int 78 predicates []func(interface{}) bool 79 } 80 81 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 82 func (r *UpgradePolicyStatePollRequest) Parameter(name string, value interface{}) *UpgradePolicyStatePollRequest { 83 r.request.Parameter(name, value) 84 return r 85 } 86 87 // Header adds a request header to all the requests that will be used to retrieve the object. 88 func (r *UpgradePolicyStatePollRequest) Header(name string, value interface{}) *UpgradePolicyStatePollRequest { 89 r.request.Header(name, value) 90 return r 91 } 92 93 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 94 func (r *UpgradePolicyStatePollRequest) Interval(value time.Duration) *UpgradePolicyStatePollRequest { 95 r.interval = value 96 return r 97 } 98 99 // Status set the expected status of the response. Multiple values can be set calling this method 100 // multiple times. The response will be considered successful if the status is any of those values. 101 func (r *UpgradePolicyStatePollRequest) Status(value int) *UpgradePolicyStatePollRequest { 102 r.statuses = append(r.statuses, value) 103 return r 104 } 105 106 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 107 // predicates can be set calling this method multiple times. The response will be considered successful 108 // if all the predicates are satisfied. 109 func (r *UpgradePolicyStatePollRequest) Predicate(value func(*UpgradePolicyStateGetResponse) bool) *UpgradePolicyStatePollRequest { 110 r.predicates = append(r.predicates, func(response interface{}) bool { 111 return value(response.(*UpgradePolicyStateGetResponse)) 112 }) 113 return r 114 } 115 116 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 117 // the values specified with the Status method and if all the predicates specified with the Predicate 118 // method return nil. 119 // 120 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 121 func (r *UpgradePolicyStatePollRequest) StartContext(ctx context.Context) (response *UpgradePolicyStatePollResponse, err error) { 122 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 123 if result != nil { 124 response = &UpgradePolicyStatePollResponse{ 125 response: result.(*UpgradePolicyStateGetResponse), 126 } 127 } 128 return 129 } 130 131 // task adapts the types of the request/response types so that they can be used with the generic 132 // polling function from the helpers package. 133 func (r *UpgradePolicyStatePollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 134 response, err := r.request.SendContext(ctx) 135 if response != nil { 136 status = response.Status() 137 result = response 138 } 139 return 140 } 141 142 // UpgradePolicyStatePollResponse is the response for the Poll method. 143 type UpgradePolicyStatePollResponse struct { 144 response *UpgradePolicyStateGetResponse 145 } 146 147 // Status returns the response status code. 148 func (r *UpgradePolicyStatePollResponse) Status() int { 149 if r == nil { 150 return 0 151 } 152 return r.response.Status() 153 } 154 155 // Header returns header of the response. 156 func (r *UpgradePolicyStatePollResponse) Header() http.Header { 157 if r == nil { 158 return nil 159 } 160 return r.response.Header() 161 } 162 163 // Error returns the response error. 164 func (r *UpgradePolicyStatePollResponse) Error() *errors.Error { 165 if r == nil { 166 return nil 167 } 168 return r.response.Error() 169 } 170 171 // Body returns the value of the 'body' parameter. 172 func (r *UpgradePolicyStatePollResponse) Body() *UpgradePolicyState { 173 return r.response.Body() 174 } 175 176 // GetBody returns the value of the 'body' parameter and 177 // a flag indicating if the parameter has a value. 178 func (r *UpgradePolicyStatePollResponse) GetBody() (value *UpgradePolicyState, ok bool) { 179 return r.response.GetBody() 180 } 181 182 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 183 // of states and satisfies a set of predicates. 184 func (c *UpgradePolicyStateClient) Poll() *UpgradePolicyStatePollRequest { 185 return &UpgradePolicyStatePollRequest{ 186 request: c.Get(), 187 } 188 } 189 190 // UpgradePolicyStateGetRequest is the request for the 'get' method. 191 type UpgradePolicyStateGetRequest struct { 192 transport http.RoundTripper 193 path string 194 query url.Values 195 header http.Header 196 } 197 198 // Parameter adds a query parameter. 199 func (r *UpgradePolicyStateGetRequest) Parameter(name string, value interface{}) *UpgradePolicyStateGetRequest { 200 helpers.AddValue(&r.query, name, value) 201 return r 202 } 203 204 // Header adds a request header. 205 func (r *UpgradePolicyStateGetRequest) Header(name string, value interface{}) *UpgradePolicyStateGetRequest { 206 helpers.AddHeader(&r.header, name, value) 207 return r 208 } 209 210 // Impersonate wraps requests on behalf of another user. 211 // Note: Services that do not support this feature may silently ignore this call. 212 func (r *UpgradePolicyStateGetRequest) Impersonate(user string) *UpgradePolicyStateGetRequest { 213 helpers.AddImpersonationHeader(&r.header, user) 214 return r 215 } 216 217 // Send sends this request, waits for the response, and returns it. 218 // 219 // This is a potentially lengthy operation, as it requires network communication. 220 // Consider using a context and the SendContext method. 221 func (r *UpgradePolicyStateGetRequest) Send() (result *UpgradePolicyStateGetResponse, err error) { 222 return r.SendContext(context.Background()) 223 } 224 225 // SendContext sends this request, waits for the response, and returns it. 226 func (r *UpgradePolicyStateGetRequest) SendContext(ctx context.Context) (result *UpgradePolicyStateGetResponse, err error) { 227 query := helpers.CopyQuery(r.query) 228 header := helpers.CopyHeader(r.header) 229 uri := &url.URL{ 230 Path: r.path, 231 RawQuery: query.Encode(), 232 } 233 request := &http.Request{ 234 Method: "GET", 235 URL: uri, 236 Header: header, 237 } 238 if ctx != nil { 239 request = request.WithContext(ctx) 240 } 241 response, err := r.transport.RoundTrip(request) 242 if err != nil { 243 return 244 } 245 defer response.Body.Close() 246 result = &UpgradePolicyStateGetResponse{} 247 result.status = response.StatusCode 248 result.header = response.Header 249 reader := bufio.NewReader(response.Body) 250 _, err = reader.Peek(1) 251 if err == io.EOF { 252 err = nil 253 return 254 } 255 if result.status >= 400 { 256 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 257 if err != nil { 258 return 259 } 260 err = result.err 261 return 262 } 263 err = readUpgradePolicyStateGetResponse(result, reader) 264 if err != nil { 265 return 266 } 267 return 268 } 269 270 // UpgradePolicyStateGetResponse is the response for the 'get' method. 271 type UpgradePolicyStateGetResponse struct { 272 status int 273 header http.Header 274 err *errors.Error 275 body *UpgradePolicyState 276 } 277 278 // Status returns the response status code. 279 func (r *UpgradePolicyStateGetResponse) Status() int { 280 if r == nil { 281 return 0 282 } 283 return r.status 284 } 285 286 // Header returns header of the response. 287 func (r *UpgradePolicyStateGetResponse) Header() http.Header { 288 if r == nil { 289 return nil 290 } 291 return r.header 292 } 293 294 // Error returns the response error. 295 func (r *UpgradePolicyStateGetResponse) Error() *errors.Error { 296 if r == nil { 297 return nil 298 } 299 return r.err 300 } 301 302 // Body returns the value of the 'body' parameter. 303 func (r *UpgradePolicyStateGetResponse) Body() *UpgradePolicyState { 304 if r == nil { 305 return nil 306 } 307 return r.body 308 } 309 310 // GetBody returns the value of the 'body' parameter and 311 // a flag indicating if the parameter has a value. 312 func (r *UpgradePolicyStateGetResponse) GetBody() (value *UpgradePolicyState, ok bool) { 313 ok = r != nil && r.body != nil 314 if ok { 315 value = r.body 316 } 317 return 318 } 319 320 // UpgradePolicyStateUpdateRequest is the request for the 'update' method. 321 type UpgradePolicyStateUpdateRequest struct { 322 transport http.RoundTripper 323 path string 324 query url.Values 325 header http.Header 326 body *UpgradePolicyState 327 } 328 329 // Parameter adds a query parameter. 330 func (r *UpgradePolicyStateUpdateRequest) Parameter(name string, value interface{}) *UpgradePolicyStateUpdateRequest { 331 helpers.AddValue(&r.query, name, value) 332 return r 333 } 334 335 // Header adds a request header. 336 func (r *UpgradePolicyStateUpdateRequest) Header(name string, value interface{}) *UpgradePolicyStateUpdateRequest { 337 helpers.AddHeader(&r.header, name, value) 338 return r 339 } 340 341 // Impersonate wraps requests on behalf of another user. 342 // Note: Services that do not support this feature may silently ignore this call. 343 func (r *UpgradePolicyStateUpdateRequest) Impersonate(user string) *UpgradePolicyStateUpdateRequest { 344 helpers.AddImpersonationHeader(&r.header, user) 345 return r 346 } 347 348 // Body sets the value of the 'body' parameter. 349 func (r *UpgradePolicyStateUpdateRequest) Body(value *UpgradePolicyState) *UpgradePolicyStateUpdateRequest { 350 r.body = value 351 return r 352 } 353 354 // Send sends this request, waits for the response, and returns it. 355 // 356 // This is a potentially lengthy operation, as it requires network communication. 357 // Consider using a context and the SendContext method. 358 func (r *UpgradePolicyStateUpdateRequest) Send() (result *UpgradePolicyStateUpdateResponse, err error) { 359 return r.SendContext(context.Background()) 360 } 361 362 // SendContext sends this request, waits for the response, and returns it. 363 func (r *UpgradePolicyStateUpdateRequest) SendContext(ctx context.Context) (result *UpgradePolicyStateUpdateResponse, err error) { 364 query := helpers.CopyQuery(r.query) 365 header := helpers.CopyHeader(r.header) 366 buffer := &bytes.Buffer{} 367 err = writeUpgradePolicyStateUpdateRequest(r, buffer) 368 if err != nil { 369 return 370 } 371 uri := &url.URL{ 372 Path: r.path, 373 RawQuery: query.Encode(), 374 } 375 request := &http.Request{ 376 Method: "PATCH", 377 URL: uri, 378 Header: header, 379 Body: io.NopCloser(buffer), 380 } 381 if ctx != nil { 382 request = request.WithContext(ctx) 383 } 384 response, err := r.transport.RoundTrip(request) 385 if err != nil { 386 return 387 } 388 defer response.Body.Close() 389 result = &UpgradePolicyStateUpdateResponse{} 390 result.status = response.StatusCode 391 result.header = response.Header 392 reader := bufio.NewReader(response.Body) 393 _, err = reader.Peek(1) 394 if err == io.EOF { 395 err = nil 396 return 397 } 398 if result.status >= 400 { 399 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 400 if err != nil { 401 return 402 } 403 err = result.err 404 return 405 } 406 err = readUpgradePolicyStateUpdateResponse(result, reader) 407 if err != nil { 408 return 409 } 410 return 411 } 412 413 // UpgradePolicyStateUpdateResponse is the response for the 'update' method. 414 type UpgradePolicyStateUpdateResponse struct { 415 status int 416 header http.Header 417 err *errors.Error 418 body *UpgradePolicyState 419 } 420 421 // Status returns the response status code. 422 func (r *UpgradePolicyStateUpdateResponse) Status() int { 423 if r == nil { 424 return 0 425 } 426 return r.status 427 } 428 429 // Header returns header of the response. 430 func (r *UpgradePolicyStateUpdateResponse) Header() http.Header { 431 if r == nil { 432 return nil 433 } 434 return r.header 435 } 436 437 // Error returns the response error. 438 func (r *UpgradePolicyStateUpdateResponse) Error() *errors.Error { 439 if r == nil { 440 return nil 441 } 442 return r.err 443 } 444 445 // Body returns the value of the 'body' parameter. 446 func (r *UpgradePolicyStateUpdateResponse) Body() *UpgradePolicyState { 447 if r == nil { 448 return nil 449 } 450 return r.body 451 } 452 453 // GetBody returns the value of the 'body' parameter and 454 // a flag indicating if the parameter has a value. 455 func (r *UpgradePolicyStateUpdateResponse) GetBody() (value *UpgradePolicyState, ok bool) { 456 ok = r != nil && r.body != nil 457 if ok { 458 value = r.body 459 } 460 return 461 }