github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/aws_validate_credentials_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 // AwsValidateCredentialsClient is the client of the 'aws_validate_credentials' resource. 35 // 36 // Manages aws creds validation 37 type AwsValidateCredentialsClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewAwsValidateCredentialsClient creates a new client for the 'aws_validate_credentials' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewAwsValidateCredentialsClient(transport http.RoundTripper, path string) *AwsValidateCredentialsClient { 46 return &AwsValidateCredentialsClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // Post creates a request for the 'post' method. 53 // 54 // Manages aws creds validation. 55 func (c *AwsValidateCredentialsClient) Post() *AwsValidateCredentialsPostRequest { 56 return &AwsValidateCredentialsPostRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // AwsValidateCredentialsPostRequest is the request for the 'post' method. 63 type AwsValidateCredentialsPostRequest struct { 64 transport http.RoundTripper 65 path string 66 query url.Values 67 header http.Header 68 body *CloudProviderData 69 } 70 71 // Parameter adds a query parameter. 72 func (r *AwsValidateCredentialsPostRequest) Parameter(name string, value interface{}) *AwsValidateCredentialsPostRequest { 73 helpers.AddValue(&r.query, name, value) 74 return r 75 } 76 77 // Header adds a request header. 78 func (r *AwsValidateCredentialsPostRequest) Header(name string, value interface{}) *AwsValidateCredentialsPostRequest { 79 helpers.AddHeader(&r.header, name, value) 80 return r 81 } 82 83 // Impersonate wraps requests on behalf of another user. 84 // Note: Services that do not support this feature may silently ignore this call. 85 func (r *AwsValidateCredentialsPostRequest) Impersonate(user string) *AwsValidateCredentialsPostRequest { 86 helpers.AddImpersonationHeader(&r.header, user) 87 return r 88 } 89 90 // Body sets the value of the 'body' parameter. 91 // 92 // Cloud provider data needed for the inquiry. 93 func (r *AwsValidateCredentialsPostRequest) Body(value *CloudProviderData) *AwsValidateCredentialsPostRequest { 94 r.body = value 95 return r 96 } 97 98 // Send sends this request, waits for the response, and returns it. 99 // 100 // This is a potentially lengthy operation, as it requires network communication. 101 // Consider using a context and the SendContext method. 102 func (r *AwsValidateCredentialsPostRequest) Send() (result *AwsValidateCredentialsPostResponse, err error) { 103 return r.SendContext(context.Background()) 104 } 105 106 // SendContext sends this request, waits for the response, and returns it. 107 func (r *AwsValidateCredentialsPostRequest) SendContext(ctx context.Context) (result *AwsValidateCredentialsPostResponse, err error) { 108 query := helpers.CopyQuery(r.query) 109 header := helpers.CopyHeader(r.header) 110 buffer := &bytes.Buffer{} 111 err = writeAwsValidateCredentialsPostRequest(r, buffer) 112 if err != nil { 113 return 114 } 115 uri := &url.URL{ 116 Path: r.path, 117 RawQuery: query.Encode(), 118 } 119 request := &http.Request{ 120 Method: "POST", 121 URL: uri, 122 Header: header, 123 Body: io.NopCloser(buffer), 124 } 125 if ctx != nil { 126 request = request.WithContext(ctx) 127 } 128 response, err := r.transport.RoundTrip(request) 129 if err != nil { 130 return 131 } 132 defer response.Body.Close() 133 result = &AwsValidateCredentialsPostResponse{} 134 result.status = response.StatusCode 135 result.header = response.Header 136 reader := bufio.NewReader(response.Body) 137 _, err = reader.Peek(1) 138 if err == io.EOF { 139 err = nil 140 return 141 } 142 if result.status >= 400 { 143 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 144 if err != nil { 145 return 146 } 147 err = result.err 148 return 149 } 150 err = readAwsValidateCredentialsPostResponse(result, reader) 151 if err != nil { 152 return 153 } 154 return 155 } 156 157 // AwsValidateCredentialsPostResponse is the response for the 'post' method. 158 type AwsValidateCredentialsPostResponse struct { 159 status int 160 header http.Header 161 err *errors.Error 162 body *CloudProviderData 163 } 164 165 // Status returns the response status code. 166 func (r *AwsValidateCredentialsPostResponse) Status() int { 167 if r == nil { 168 return 0 169 } 170 return r.status 171 } 172 173 // Header returns header of the response. 174 func (r *AwsValidateCredentialsPostResponse) Header() http.Header { 175 if r == nil { 176 return nil 177 } 178 return r.header 179 } 180 181 // Error returns the response error. 182 func (r *AwsValidateCredentialsPostResponse) Error() *errors.Error { 183 if r == nil { 184 return nil 185 } 186 return r.err 187 } 188 189 // Body returns the value of the 'body' parameter. 190 // 191 // Cloud provider data needed for the inquiry. 192 func (r *AwsValidateCredentialsPostResponse) Body() *CloudProviderData { 193 if r == nil { 194 return nil 195 } 196 return r.body 197 } 198 199 // GetBody returns the value of the 'body' parameter and 200 // a flag indicating if the parameter has a value. 201 // 202 // Cloud provider data needed for the inquiry. 203 func (r *AwsValidateCredentialsPostResponse) GetBody() (value *CloudProviderData, ok bool) { 204 ok = r != nil && r.body != nil 205 if ok { 206 value = r.body 207 } 208 return 209 }