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