github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/external_configuration_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 "context" 25 "io" 26 "net/http" 27 "net/url" 28 "path" 29 "time" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // ExternalConfigurationClient is the client of the 'external_configuration' resource. 36 // 37 // Manages a specific external configuration. 38 type ExternalConfigurationClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewExternalConfigurationClient creates a new client for the 'external_configuration' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewExternalConfigurationClient(transport http.RoundTripper, path string) *ExternalConfigurationClient { 47 return &ExternalConfigurationClient{ 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 external configuration. 56 func (c *ExternalConfigurationClient) Get() *ExternalConfigurationGetRequest { 57 return &ExternalConfigurationGetRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // Labels returns the target 'labels' resource. 64 // 65 // Reference to the resource that manages the collection of labels. 66 func (c *ExternalConfigurationClient) Labels() *LabelsClient { 67 return NewLabelsClient( 68 c.transport, 69 path.Join(c.path, "labels"), 70 ) 71 } 72 73 // Manifests returns the target 'manifests' resource. 74 // 75 // Reference to the resource that manages the collection of manifests. 76 func (c *ExternalConfigurationClient) Manifests() *ManifestsClient { 77 return NewManifestsClient( 78 c.transport, 79 path.Join(c.path, "manifests"), 80 ) 81 } 82 83 // Syncsets returns the target 'syncsets' resource. 84 // 85 // Reference to the resource that manages the collection of syncsets. 86 func (c *ExternalConfigurationClient) Syncsets() *SyncsetsClient { 87 return NewSyncsetsClient( 88 c.transport, 89 path.Join(c.path, "syncsets"), 90 ) 91 } 92 93 // ExternalConfigurationPollRequest is the request for the Poll method. 94 type ExternalConfigurationPollRequest struct { 95 request *ExternalConfigurationGetRequest 96 interval time.Duration 97 statuses []int 98 predicates []func(interface{}) bool 99 } 100 101 // Parameter adds a query parameter to all the requests that will be used to retrieve the object. 102 func (r *ExternalConfigurationPollRequest) Parameter(name string, value interface{}) *ExternalConfigurationPollRequest { 103 r.request.Parameter(name, value) 104 return r 105 } 106 107 // Header adds a request header to all the requests that will be used to retrieve the object. 108 func (r *ExternalConfigurationPollRequest) Header(name string, value interface{}) *ExternalConfigurationPollRequest { 109 r.request.Header(name, value) 110 return r 111 } 112 113 // Interval sets the polling interval. This parameter is mandatory and must be greater than zero. 114 func (r *ExternalConfigurationPollRequest) Interval(value time.Duration) *ExternalConfigurationPollRequest { 115 r.interval = value 116 return r 117 } 118 119 // Status set the expected status of the response. Multiple values can be set calling this method 120 // multiple times. The response will be considered successful if the status is any of those values. 121 func (r *ExternalConfigurationPollRequest) Status(value int) *ExternalConfigurationPollRequest { 122 r.statuses = append(r.statuses, value) 123 return r 124 } 125 126 // Predicate adds a predicate that the response should satisfy be considered successful. Multiple 127 // predicates can be set calling this method multiple times. The response will be considered successful 128 // if all the predicates are satisfied. 129 func (r *ExternalConfigurationPollRequest) Predicate(value func(*ExternalConfigurationGetResponse) bool) *ExternalConfigurationPollRequest { 130 r.predicates = append(r.predicates, func(response interface{}) bool { 131 return value(response.(*ExternalConfigurationGetResponse)) 132 }) 133 return r 134 } 135 136 // StartContext starts the polling loop. Responses will be considered successful if the status is one of 137 // the values specified with the Status method and if all the predicates specified with the Predicate 138 // method return nil. 139 // 140 // The context must have a timeout or deadline, otherwise this method will immediately return an error. 141 func (r *ExternalConfigurationPollRequest) StartContext(ctx context.Context) (response *ExternalConfigurationPollResponse, err error) { 142 result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task) 143 if result != nil { 144 response = &ExternalConfigurationPollResponse{ 145 response: result.(*ExternalConfigurationGetResponse), 146 } 147 } 148 return 149 } 150 151 // task adapts the types of the request/response types so that they can be used with the generic 152 // polling function from the helpers package. 153 func (r *ExternalConfigurationPollRequest) task(ctx context.Context) (status int, result interface{}, err error) { 154 response, err := r.request.SendContext(ctx) 155 if response != nil { 156 status = response.Status() 157 result = response 158 } 159 return 160 } 161 162 // ExternalConfigurationPollResponse is the response for the Poll method. 163 type ExternalConfigurationPollResponse struct { 164 response *ExternalConfigurationGetResponse 165 } 166 167 // Status returns the response status code. 168 func (r *ExternalConfigurationPollResponse) Status() int { 169 if r == nil { 170 return 0 171 } 172 return r.response.Status() 173 } 174 175 // Header returns header of the response. 176 func (r *ExternalConfigurationPollResponse) Header() http.Header { 177 if r == nil { 178 return nil 179 } 180 return r.response.Header() 181 } 182 183 // Error returns the response error. 184 func (r *ExternalConfigurationPollResponse) Error() *errors.Error { 185 if r == nil { 186 return nil 187 } 188 return r.response.Error() 189 } 190 191 // Body returns the value of the 'body' parameter. 192 // 193 // Retreived log. 194 func (r *ExternalConfigurationPollResponse) Body() *ExternalConfiguration { 195 return r.response.Body() 196 } 197 198 // GetBody returns the value of the 'body' parameter and 199 // a flag indicating if the parameter has a value. 200 // 201 // Retreived log. 202 func (r *ExternalConfigurationPollResponse) GetBody() (value *ExternalConfiguration, ok bool) { 203 return r.response.GetBody() 204 } 205 206 // Poll creates a request to repeatedly retrieve the object till the response has one of a given set 207 // of states and satisfies a set of predicates. 208 func (c *ExternalConfigurationClient) Poll() *ExternalConfigurationPollRequest { 209 return &ExternalConfigurationPollRequest{ 210 request: c.Get(), 211 } 212 } 213 214 // ExternalConfigurationGetRequest is the request for the 'get' method. 215 type ExternalConfigurationGetRequest struct { 216 transport http.RoundTripper 217 path string 218 query url.Values 219 header http.Header 220 } 221 222 // Parameter adds a query parameter. 223 func (r *ExternalConfigurationGetRequest) Parameter(name string, value interface{}) *ExternalConfigurationGetRequest { 224 helpers.AddValue(&r.query, name, value) 225 return r 226 } 227 228 // Header adds a request header. 229 func (r *ExternalConfigurationGetRequest) Header(name string, value interface{}) *ExternalConfigurationGetRequest { 230 helpers.AddHeader(&r.header, name, value) 231 return r 232 } 233 234 // Impersonate wraps requests on behalf of another user. 235 // Note: Services that do not support this feature may silently ignore this call. 236 func (r *ExternalConfigurationGetRequest) Impersonate(user string) *ExternalConfigurationGetRequest { 237 helpers.AddImpersonationHeader(&r.header, user) 238 return r 239 } 240 241 // Send sends this request, waits for the response, and returns it. 242 // 243 // This is a potentially lengthy operation, as it requires network communication. 244 // Consider using a context and the SendContext method. 245 func (r *ExternalConfigurationGetRequest) Send() (result *ExternalConfigurationGetResponse, err error) { 246 return r.SendContext(context.Background()) 247 } 248 249 // SendContext sends this request, waits for the response, and returns it. 250 func (r *ExternalConfigurationGetRequest) SendContext(ctx context.Context) (result *ExternalConfigurationGetResponse, err error) { 251 query := helpers.CopyQuery(r.query) 252 header := helpers.CopyHeader(r.header) 253 uri := &url.URL{ 254 Path: r.path, 255 RawQuery: query.Encode(), 256 } 257 request := &http.Request{ 258 Method: "GET", 259 URL: uri, 260 Header: header, 261 } 262 if ctx != nil { 263 request = request.WithContext(ctx) 264 } 265 response, err := r.transport.RoundTrip(request) 266 if err != nil { 267 return 268 } 269 defer response.Body.Close() 270 result = &ExternalConfigurationGetResponse{} 271 result.status = response.StatusCode 272 result.header = response.Header 273 reader := bufio.NewReader(response.Body) 274 _, err = reader.Peek(1) 275 if err == io.EOF { 276 err = nil 277 return 278 } 279 if result.status >= 400 { 280 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 281 if err != nil { 282 return 283 } 284 err = result.err 285 return 286 } 287 err = readExternalConfigurationGetResponse(result, reader) 288 if err != nil { 289 return 290 } 291 return 292 } 293 294 // ExternalConfigurationGetResponse is the response for the 'get' method. 295 type ExternalConfigurationGetResponse struct { 296 status int 297 header http.Header 298 err *errors.Error 299 body *ExternalConfiguration 300 } 301 302 // Status returns the response status code. 303 func (r *ExternalConfigurationGetResponse) Status() int { 304 if r == nil { 305 return 0 306 } 307 return r.status 308 } 309 310 // Header returns header of the response. 311 func (r *ExternalConfigurationGetResponse) Header() http.Header { 312 if r == nil { 313 return nil 314 } 315 return r.header 316 } 317 318 // Error returns the response error. 319 func (r *ExternalConfigurationGetResponse) Error() *errors.Error { 320 if r == nil { 321 return nil 322 } 323 return r.err 324 } 325 326 // Body returns the value of the 'body' parameter. 327 // 328 // Retreived log. 329 func (r *ExternalConfigurationGetResponse) Body() *ExternalConfiguration { 330 if r == nil { 331 return nil 332 } 333 return r.body 334 } 335 336 // GetBody returns the value of the 'body' parameter and 337 // a flag indicating if the parameter has a value. 338 // 339 // Retreived log. 340 func (r *ExternalConfigurationGetResponse) GetBody() (value *ExternalConfiguration, ok bool) { 341 ok = r != nil && r.body != nil 342 if ok { 343 value = r.body 344 } 345 return 346 }