github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/cloud_providers_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 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // CloudProvidersClient is the client of the 'cloud_providers' resource. 35 // 36 // Manages the collection of cloud providers. 37 type CloudProvidersClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewCloudProvidersClient creates a new client for the 'cloud_providers' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewCloudProvidersClient(transport http.RoundTripper, path string) *CloudProvidersClient { 46 return &CloudProvidersClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // List creates a request for the 'list' method. 53 // 54 // Retrieves the list of cloud providers. 55 func (c *CloudProvidersClient) List() *CloudProvidersListRequest { 56 return &CloudProvidersListRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // CloudProvider returns the target 'cloud_provider' resource for the given identifier. 63 // 64 // Returns a reference to the service that manages an specific cloud provider. 65 func (c *CloudProvidersClient) CloudProvider(id string) *CloudProviderClient { 66 return NewCloudProviderClient( 67 c.transport, 68 path.Join(c.path, id), 69 ) 70 } 71 72 // CloudProvidersListRequest is the request for the 'list' method. 73 type CloudProvidersListRequest struct { 74 transport http.RoundTripper 75 path string 76 query url.Values 77 header http.Header 78 fetchRegions *bool 79 order *string 80 page *int 81 search *string 82 size *int 83 } 84 85 // Parameter adds a query parameter. 86 func (r *CloudProvidersListRequest) Parameter(name string, value interface{}) *CloudProvidersListRequest { 87 helpers.AddValue(&r.query, name, value) 88 return r 89 } 90 91 // Header adds a request header. 92 func (r *CloudProvidersListRequest) Header(name string, value interface{}) *CloudProvidersListRequest { 93 helpers.AddHeader(&r.header, name, value) 94 return r 95 } 96 97 // Impersonate wraps requests on behalf of another user. 98 // Note: Services that do not support this feature may silently ignore this call. 99 func (r *CloudProvidersListRequest) Impersonate(user string) *CloudProvidersListRequest { 100 helpers.AddImpersonationHeader(&r.header, user) 101 return r 102 } 103 104 // FetchRegions sets the value of the 'fetch_regions' parameter. 105 // 106 // If true, includes the regions on each provider in the output. Could slow request response time. 107 func (r *CloudProvidersListRequest) FetchRegions(value bool) *CloudProvidersListRequest { 108 r.fetchRegions = &value 109 return r 110 } 111 112 // Order sets the value of the 'order' parameter. 113 // 114 // Order criteria. 115 // 116 // The syntax of this parameter is similar to the syntax of the _order by_ clause of 117 // a SQL statement, but using the names of the attributes of the cloud provider 118 // instead of the names of the columns of a table. For example, in order to sort the 119 // clusters descending by name identifier the value should be: 120 // 121 // ```sql 122 // name desc 123 // ``` 124 // 125 // If the parameter isn't provided, or if the value is empty, then the order of the 126 // results is undefined. 127 func (r *CloudProvidersListRequest) Order(value string) *CloudProvidersListRequest { 128 r.order = &value 129 return r 130 } 131 132 // Page sets the value of the 'page' parameter. 133 // 134 // Index of the requested page, where one corresponds to the first page. 135 func (r *CloudProvidersListRequest) Page(value int) *CloudProvidersListRequest { 136 r.page = &value 137 return r 138 } 139 140 // Search sets the value of the 'search' parameter. 141 // 142 // Search criteria. 143 // 144 // The syntax of this parameter is similar to the syntax of the _where_ clause of a 145 // SQL statement, but using the names of the attributes of the cloud provider 146 // instead of the names of the columns of a table. For example, in order to retrieve 147 // all the cloud providers with a name starting with `A` the value should be: 148 // 149 // ```sql 150 // name like 'A%' 151 // ``` 152 // 153 // If the parameter isn't provided, or if the value is empty, then all the clusters 154 // that the user has permission to see will be returned. 155 func (r *CloudProvidersListRequest) Search(value string) *CloudProvidersListRequest { 156 r.search = &value 157 return r 158 } 159 160 // Size sets the value of the 'size' parameter. 161 // 162 // Maximum number of items that will be contained in the returned page. 163 func (r *CloudProvidersListRequest) Size(value int) *CloudProvidersListRequest { 164 r.size = &value 165 return r 166 } 167 168 // Send sends this request, waits for the response, and returns it. 169 // 170 // This is a potentially lengthy operation, as it requires network communication. 171 // Consider using a context and the SendContext method. 172 func (r *CloudProvidersListRequest) Send() (result *CloudProvidersListResponse, err error) { 173 return r.SendContext(context.Background()) 174 } 175 176 // SendContext sends this request, waits for the response, and returns it. 177 func (r *CloudProvidersListRequest) SendContext(ctx context.Context) (result *CloudProvidersListResponse, err error) { 178 query := helpers.CopyQuery(r.query) 179 if r.fetchRegions != nil { 180 helpers.AddValue(&query, "fetchRegions", *r.fetchRegions) 181 } 182 if r.order != nil { 183 helpers.AddValue(&query, "order", *r.order) 184 } 185 if r.page != nil { 186 helpers.AddValue(&query, "page", *r.page) 187 } 188 if r.search != nil { 189 helpers.AddValue(&query, "search", *r.search) 190 } 191 if r.size != nil { 192 helpers.AddValue(&query, "size", *r.size) 193 } 194 header := helpers.CopyHeader(r.header) 195 uri := &url.URL{ 196 Path: r.path, 197 RawQuery: query.Encode(), 198 } 199 request := &http.Request{ 200 Method: "GET", 201 URL: uri, 202 Header: header, 203 } 204 if ctx != nil { 205 request = request.WithContext(ctx) 206 } 207 response, err := r.transport.RoundTrip(request) 208 if err != nil { 209 return 210 } 211 defer response.Body.Close() 212 result = &CloudProvidersListResponse{} 213 result.status = response.StatusCode 214 result.header = response.Header 215 reader := bufio.NewReader(response.Body) 216 _, err = reader.Peek(1) 217 if err == io.EOF { 218 err = nil 219 return 220 } 221 if result.status >= 400 { 222 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 223 if err != nil { 224 return 225 } 226 err = result.err 227 return 228 } 229 err = readCloudProvidersListResponse(result, reader) 230 if err != nil { 231 return 232 } 233 return 234 } 235 236 // CloudProvidersListResponse is the response for the 'list' method. 237 type CloudProvidersListResponse struct { 238 status int 239 header http.Header 240 err *errors.Error 241 items *CloudProviderList 242 page *int 243 size *int 244 total *int 245 } 246 247 // Status returns the response status code. 248 func (r *CloudProvidersListResponse) Status() int { 249 if r == nil { 250 return 0 251 } 252 return r.status 253 } 254 255 // Header returns header of the response. 256 func (r *CloudProvidersListResponse) Header() http.Header { 257 if r == nil { 258 return nil 259 } 260 return r.header 261 } 262 263 // Error returns the response error. 264 func (r *CloudProvidersListResponse) Error() *errors.Error { 265 if r == nil { 266 return nil 267 } 268 return r.err 269 } 270 271 // Items returns the value of the 'items' parameter. 272 // 273 // Retrieved list of cloud providers. 274 func (r *CloudProvidersListResponse) Items() *CloudProviderList { 275 if r == nil { 276 return nil 277 } 278 return r.items 279 } 280 281 // GetItems returns the value of the 'items' parameter and 282 // a flag indicating if the parameter has a value. 283 // 284 // Retrieved list of cloud providers. 285 func (r *CloudProvidersListResponse) GetItems() (value *CloudProviderList, ok bool) { 286 ok = r != nil && r.items != nil 287 if ok { 288 value = r.items 289 } 290 return 291 } 292 293 // Page returns the value of the 'page' parameter. 294 // 295 // Index of the requested page, where one corresponds to the first page. 296 func (r *CloudProvidersListResponse) Page() int { 297 if r != nil && r.page != nil { 298 return *r.page 299 } 300 return 0 301 } 302 303 // GetPage returns the value of the 'page' parameter and 304 // a flag indicating if the parameter has a value. 305 // 306 // Index of the requested page, where one corresponds to the first page. 307 func (r *CloudProvidersListResponse) GetPage() (value int, ok bool) { 308 ok = r != nil && r.page != nil 309 if ok { 310 value = *r.page 311 } 312 return 313 } 314 315 // Size returns the value of the 'size' parameter. 316 // 317 // Maximum number of items that will be contained in the returned page. 318 func (r *CloudProvidersListResponse) Size() int { 319 if r != nil && r.size != nil { 320 return *r.size 321 } 322 return 0 323 } 324 325 // GetSize returns the value of the 'size' parameter and 326 // a flag indicating if the parameter has a value. 327 // 328 // Maximum number of items that will be contained in the returned page. 329 func (r *CloudProvidersListResponse) GetSize() (value int, ok bool) { 330 ok = r != nil && r.size != nil 331 if ok { 332 value = *r.size 333 } 334 return 335 } 336 337 // Total returns the value of the 'total' parameter. 338 // 339 // Total number of items of the collection that match the search criteria, 340 // regardless of the size of the page. 341 func (r *CloudProvidersListResponse) Total() int { 342 if r != nil && r.total != nil { 343 return *r.total 344 } 345 return 0 346 } 347 348 // GetTotal returns the value of the 'total' parameter and 349 // a flag indicating if the parameter has a value. 350 // 351 // Total number of items of the collection that match the search criteria, 352 // regardless of the size of the page. 353 func (r *CloudProvidersListResponse) GetTotal() (value int, ok bool) { 354 ok = r != nil && r.total != nil 355 if ok { 356 value = *r.total 357 } 358 return 359 }