github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/current_access_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 // CurrentAccessClient is the client of the 'current_access' resource. 34 // 35 // Manages roles/permissions of the current authenticated account. 36 type CurrentAccessClient struct { 37 transport http.RoundTripper 38 path string 39 } 40 41 // NewCurrentAccessClient creates a new client for the 'current_access' 42 // resource using the given transport to send the requests and receive the 43 // responses. 44 func NewCurrentAccessClient(transport http.RoundTripper, path string) *CurrentAccessClient { 45 return &CurrentAccessClient{ 46 transport: transport, 47 path: path, 48 } 49 } 50 51 // List creates a request for the 'list' method. 52 // 53 // Retrieves the details of the account. 54 func (c *CurrentAccessClient) List() *CurrentAccessListRequest { 55 return &CurrentAccessListRequest{ 56 transport: c.transport, 57 path: c.path, 58 } 59 } 60 61 // CurrentAccessListRequest is the request for the 'list' method. 62 type CurrentAccessListRequest struct { 63 transport http.RoundTripper 64 path string 65 query url.Values 66 header http.Header 67 page *int 68 size *int 69 } 70 71 // Parameter adds a query parameter. 72 func (r *CurrentAccessListRequest) Parameter(name string, value interface{}) *CurrentAccessListRequest { 73 helpers.AddValue(&r.query, name, value) 74 return r 75 } 76 77 // Header adds a request header. 78 func (r *CurrentAccessListRequest) Header(name string, value interface{}) *CurrentAccessListRequest { 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 *CurrentAccessListRequest) Impersonate(user string) *CurrentAccessListRequest { 86 helpers.AddImpersonationHeader(&r.header, user) 87 return r 88 } 89 90 // Page sets the value of the 'page' parameter. 91 // 92 // Index of the requested page, where one corresponds to the first page. 93 func (r *CurrentAccessListRequest) Page(value int) *CurrentAccessListRequest { 94 r.page = &value 95 return r 96 } 97 98 // Size sets the value of the 'size' parameter. 99 // 100 // Maximum number of items that will be contained in the returned page. 101 func (r *CurrentAccessListRequest) Size(value int) *CurrentAccessListRequest { 102 r.size = &value 103 return r 104 } 105 106 // Send sends this request, waits for the response, and returns it. 107 // 108 // This is a potentially lengthy operation, as it requires network communication. 109 // Consider using a context and the SendContext method. 110 func (r *CurrentAccessListRequest) Send() (result *CurrentAccessListResponse, err error) { 111 return r.SendContext(context.Background()) 112 } 113 114 // SendContext sends this request, waits for the response, and returns it. 115 func (r *CurrentAccessListRequest) SendContext(ctx context.Context) (result *CurrentAccessListResponse, err error) { 116 query := helpers.CopyQuery(r.query) 117 if r.page != nil { 118 helpers.AddValue(&query, "page", *r.page) 119 } 120 if r.size != nil { 121 helpers.AddValue(&query, "size", *r.size) 122 } 123 header := helpers.CopyHeader(r.header) 124 uri := &url.URL{ 125 Path: r.path, 126 RawQuery: query.Encode(), 127 } 128 request := &http.Request{ 129 Method: "GET", 130 URL: uri, 131 Header: header, 132 } 133 if ctx != nil { 134 request = request.WithContext(ctx) 135 } 136 response, err := r.transport.RoundTrip(request) 137 if err != nil { 138 return 139 } 140 defer response.Body.Close() 141 result = &CurrentAccessListResponse{} 142 result.status = response.StatusCode 143 result.header = response.Header 144 reader := bufio.NewReader(response.Body) 145 _, err = reader.Peek(1) 146 if err == io.EOF { 147 err = nil 148 return 149 } 150 if result.status >= 400 { 151 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 152 if err != nil { 153 return 154 } 155 err = result.err 156 return 157 } 158 err = readCurrentAccessListResponse(result, reader) 159 if err != nil { 160 return 161 } 162 return 163 } 164 165 // CurrentAccessListResponse is the response for the 'list' method. 166 type CurrentAccessListResponse struct { 167 status int 168 header http.Header 169 err *errors.Error 170 items *RoleList 171 page *int 172 size *int 173 total *int 174 } 175 176 // Status returns the response status code. 177 func (r *CurrentAccessListResponse) Status() int { 178 if r == nil { 179 return 0 180 } 181 return r.status 182 } 183 184 // Header returns header of the response. 185 func (r *CurrentAccessListResponse) Header() http.Header { 186 if r == nil { 187 return nil 188 } 189 return r.header 190 } 191 192 // Error returns the response error. 193 func (r *CurrentAccessListResponse) Error() *errors.Error { 194 if r == nil { 195 return nil 196 } 197 return r.err 198 } 199 200 // Items returns the value of the 'items' parameter. 201 func (r *CurrentAccessListResponse) Items() *RoleList { 202 if r == nil { 203 return nil 204 } 205 return r.items 206 } 207 208 // GetItems returns the value of the 'items' parameter and 209 // a flag indicating if the parameter has a value. 210 func (r *CurrentAccessListResponse) GetItems() (value *RoleList, ok bool) { 211 ok = r != nil && r.items != nil 212 if ok { 213 value = r.items 214 } 215 return 216 } 217 218 // Page returns the value of the 'page' parameter. 219 // 220 // Index of the requested page, where one corresponds to the first page. 221 func (r *CurrentAccessListResponse) Page() int { 222 if r != nil && r.page != nil { 223 return *r.page 224 } 225 return 0 226 } 227 228 // GetPage returns the value of the 'page' parameter and 229 // a flag indicating if the parameter has a value. 230 // 231 // Index of the requested page, where one corresponds to the first page. 232 func (r *CurrentAccessListResponse) GetPage() (value int, ok bool) { 233 ok = r != nil && r.page != nil 234 if ok { 235 value = *r.page 236 } 237 return 238 } 239 240 // Size returns the value of the 'size' parameter. 241 // 242 // Maximum number of items that will be contained in the returned page. 243 func (r *CurrentAccessListResponse) Size() int { 244 if r != nil && r.size != nil { 245 return *r.size 246 } 247 return 0 248 } 249 250 // GetSize returns the value of the 'size' parameter and 251 // a flag indicating if the parameter has a value. 252 // 253 // Maximum number of items that will be contained in the returned page. 254 func (r *CurrentAccessListResponse) GetSize() (value int, ok bool) { 255 ok = r != nil && r.size != nil 256 if ok { 257 value = *r.size 258 } 259 return 260 } 261 262 // Total returns the value of the 'total' parameter. 263 // 264 // Total number of items of the collection that match the search criteria, 265 // regardless of the size of the page. 266 func (r *CurrentAccessListResponse) Total() int { 267 if r != nil && r.total != nil { 268 return *r.total 269 } 270 return 0 271 } 272 273 // GetTotal returns the value of the 'total' parameter and 274 // a flag indicating if the parameter has a value. 275 // 276 // Total number of items of the collection that match the search criteria, 277 // regardless of the size of the page. 278 func (r *CurrentAccessListResponse) GetTotal() (value int, ok bool) { 279 ok = r != nil && r.total != nil 280 if ok { 281 value = *r.total 282 } 283 return 284 }