github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/available_regions_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 30 "github.com/openshift-online/ocm-sdk-go/errors" 31 "github.com/openshift-online/ocm-sdk-go/helpers" 32 ) 33 34 // AvailableRegionsClient is the client of the 'available_regions' resource. 35 // 36 // Manages collection of cloud provider regions available to a particular cloud provider account 37 type AvailableRegionsClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewAvailableRegionsClient creates a new client for the 'available_regions' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewAvailableRegionsClient(transport http.RoundTripper, path string) *AvailableRegionsClient { 46 return &AvailableRegionsClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // Search creates a request for the 'search' method. 53 // 54 // Retrieves the list of available regions of the cloud provider. 55 // 56 // IMPORTANT: This collection doesn't currently support paging or searching, so the returned 57 // `page` will always be 1 and `size` and `total` will always be the total number of available regions 58 // of the provider. 59 func (c *AvailableRegionsClient) Search() *AvailableRegionsSearchRequest { 60 return &AvailableRegionsSearchRequest{ 61 transport: c.transport, 62 path: c.path, 63 } 64 } 65 66 // AvailableRegionsSearchRequest is the request for the 'search' method. 67 type AvailableRegionsSearchRequest struct { 68 transport http.RoundTripper 69 path string 70 query url.Values 71 header http.Header 72 body *AWS 73 page *int 74 size *int 75 } 76 77 // Parameter adds a query parameter. 78 func (r *AvailableRegionsSearchRequest) Parameter(name string, value interface{}) *AvailableRegionsSearchRequest { 79 helpers.AddValue(&r.query, name, value) 80 return r 81 } 82 83 // Header adds a request header. 84 func (r *AvailableRegionsSearchRequest) Header(name string, value interface{}) *AvailableRegionsSearchRequest { 85 helpers.AddHeader(&r.header, name, value) 86 return r 87 } 88 89 // Impersonate wraps requests on behalf of another user. 90 // Note: Services that do not support this feature may silently ignore this call. 91 func (r *AvailableRegionsSearchRequest) Impersonate(user string) *AvailableRegionsSearchRequest { 92 helpers.AddImpersonationHeader(&r.header, user) 93 return r 94 } 95 96 // Body sets the value of the 'body' parameter. 97 // 98 // AWS account details 99 func (r *AvailableRegionsSearchRequest) Body(value *AWS) *AvailableRegionsSearchRequest { 100 r.body = value 101 return r 102 } 103 104 // Page sets the value of the 'page' parameter. 105 // 106 // Index of the returned page, where one corresponds to the first page. As this 107 // collection doesn't support paging the result will always be `1`. 108 func (r *AvailableRegionsSearchRequest) Page(value int) *AvailableRegionsSearchRequest { 109 r.page = &value 110 return r 111 } 112 113 // Size sets the value of the 'size' parameter. 114 // 115 // Number of items that will be contained in the returned page. As this collection 116 // doesn't support paging or searching the result will always be the total number of 117 // regions of the provider. 118 func (r *AvailableRegionsSearchRequest) Size(value int) *AvailableRegionsSearchRequest { 119 r.size = &value 120 return r 121 } 122 123 // Send sends this request, waits for the response, and returns it. 124 // 125 // This is a potentially lengthy operation, as it requires network communication. 126 // Consider using a context and the SendContext method. 127 func (r *AvailableRegionsSearchRequest) Send() (result *AvailableRegionsSearchResponse, err error) { 128 return r.SendContext(context.Background()) 129 } 130 131 // SendContext sends this request, waits for the response, and returns it. 132 func (r *AvailableRegionsSearchRequest) SendContext(ctx context.Context) (result *AvailableRegionsSearchResponse, err error) { 133 query := helpers.CopyQuery(r.query) 134 if r.page != nil { 135 helpers.AddValue(&query, "page", *r.page) 136 } 137 if r.size != nil { 138 helpers.AddValue(&query, "size", *r.size) 139 } 140 header := helpers.CopyHeader(r.header) 141 buffer := &bytes.Buffer{} 142 err = writeAvailableRegionsSearchRequest(r, buffer) 143 if err != nil { 144 return 145 } 146 uri := &url.URL{ 147 Path: r.path, 148 RawQuery: query.Encode(), 149 } 150 request := &http.Request{ 151 Method: "POST", 152 URL: uri, 153 Header: header, 154 Body: io.NopCloser(buffer), 155 } 156 if ctx != nil { 157 request = request.WithContext(ctx) 158 } 159 response, err := r.transport.RoundTrip(request) 160 if err != nil { 161 return 162 } 163 defer response.Body.Close() 164 result = &AvailableRegionsSearchResponse{} 165 result.status = response.StatusCode 166 result.header = response.Header 167 reader := bufio.NewReader(response.Body) 168 _, err = reader.Peek(1) 169 if err == io.EOF { 170 err = nil 171 return 172 } 173 if result.status >= 400 { 174 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 175 if err != nil { 176 return 177 } 178 err = result.err 179 return 180 } 181 err = readAvailableRegionsSearchResponse(result, reader) 182 if err != nil { 183 return 184 } 185 return 186 } 187 188 // AvailableRegionsSearchResponse is the response for the 'search' method. 189 type AvailableRegionsSearchResponse struct { 190 status int 191 header http.Header 192 err *errors.Error 193 items *CloudRegionList 194 page *int 195 size *int 196 total *int 197 } 198 199 // Status returns the response status code. 200 func (r *AvailableRegionsSearchResponse) Status() int { 201 if r == nil { 202 return 0 203 } 204 return r.status 205 } 206 207 // Header returns header of the response. 208 func (r *AvailableRegionsSearchResponse) Header() http.Header { 209 if r == nil { 210 return nil 211 } 212 return r.header 213 } 214 215 // Error returns the response error. 216 func (r *AvailableRegionsSearchResponse) Error() *errors.Error { 217 if r == nil { 218 return nil 219 } 220 return r.err 221 } 222 223 // Items returns the value of the 'items' parameter. 224 // 225 // Retrieved list of cloud regions. 226 func (r *AvailableRegionsSearchResponse) Items() *CloudRegionList { 227 if r == nil { 228 return nil 229 } 230 return r.items 231 } 232 233 // GetItems returns the value of the 'items' parameter and 234 // a flag indicating if the parameter has a value. 235 // 236 // Retrieved list of cloud regions. 237 func (r *AvailableRegionsSearchResponse) GetItems() (value *CloudRegionList, ok bool) { 238 ok = r != nil && r.items != nil 239 if ok { 240 value = r.items 241 } 242 return 243 } 244 245 // Page returns the value of the 'page' parameter. 246 // 247 // Index of the returned page, where one corresponds to the first page. As this 248 // collection doesn't support paging the result will always be `1`. 249 func (r *AvailableRegionsSearchResponse) Page() int { 250 if r != nil && r.page != nil { 251 return *r.page 252 } 253 return 0 254 } 255 256 // GetPage returns the value of the 'page' parameter and 257 // a flag indicating if the parameter has a value. 258 // 259 // Index of the returned page, where one corresponds to the first page. As this 260 // collection doesn't support paging the result will always be `1`. 261 func (r *AvailableRegionsSearchResponse) GetPage() (value int, ok bool) { 262 ok = r != nil && r.page != nil 263 if ok { 264 value = *r.page 265 } 266 return 267 } 268 269 // Size returns the value of the 'size' parameter. 270 // 271 // Number of items that will be contained in the returned page. As this collection 272 // doesn't support paging or searching the result will always be the total number of 273 // regions of the provider. 274 func (r *AvailableRegionsSearchResponse) Size() int { 275 if r != nil && r.size != nil { 276 return *r.size 277 } 278 return 0 279 } 280 281 // GetSize returns the value of the 'size' parameter and 282 // a flag indicating if the parameter has a value. 283 // 284 // Number of items that will be contained in the returned page. As this collection 285 // doesn't support paging or searching the result will always be the total number of 286 // regions of the provider. 287 func (r *AvailableRegionsSearchResponse) GetSize() (value int, ok bool) { 288 ok = r != nil && r.size != nil 289 if ok { 290 value = *r.size 291 } 292 return 293 } 294 295 // Total returns the value of the 'total' parameter. 296 // 297 // Total number of items of the collection that match the search criteria, 298 // regardless of the size of the page. As this collection doesn't support paging or 299 // searching the result will always be the total number of available regions of the provider. 300 func (r *AvailableRegionsSearchResponse) Total() int { 301 if r != nil && r.total != nil { 302 return *r.total 303 } 304 return 0 305 } 306 307 // GetTotal returns the value of the 'total' parameter and 308 // a flag indicating if the parameter has a value. 309 // 310 // Total number of items of the collection that match the search criteria, 311 // regardless of the size of the page. As this collection doesn't support paging or 312 // searching the result will always be the total number of available regions of the provider. 313 func (r *AvailableRegionsSearchResponse) GetTotal() (value int, ok bool) { 314 ok = r != nil && r.total != nil 315 if ok { 316 value = *r.total 317 } 318 return 319 }