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