github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/logs_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 // LogsClient is the client of the 'logs' resource. 35 // 36 // Manages a collection of log links. 37 type LogsClient struct { 38 transport http.RoundTripper 39 path string 40 } 41 42 // NewLogsClient creates a new client for the 'logs' 43 // resource using the given transport to send the requests and receive the 44 // responses. 45 func NewLogsClient(transport http.RoundTripper, path string) *LogsClient { 46 return &LogsClient{ 47 transport: transport, 48 path: path, 49 } 50 } 51 52 // List creates a request for the 'list' method. 53 // 54 // Retrieves the list of log links. 55 func (c *LogsClient) List() *LogsListRequest { 56 return &LogsListRequest{ 57 transport: c.transport, 58 path: c.path, 59 } 60 } 61 62 // Install returns the target 'log' resource. 63 func (c *LogsClient) Install() *LogClient { 64 return NewLogClient( 65 c.transport, 66 path.Join(c.path, "install"), 67 ) 68 } 69 70 // Uninstall returns the target 'log' resource. 71 func (c *LogsClient) Uninstall() *LogClient { 72 return NewLogClient( 73 c.transport, 74 path.Join(c.path, "uninstall"), 75 ) 76 } 77 78 // LogsListRequest is the request for the 'list' method. 79 type LogsListRequest struct { 80 transport http.RoundTripper 81 path string 82 query url.Values 83 header http.Header 84 page *int 85 size *int 86 } 87 88 // Parameter adds a query parameter. 89 func (r *LogsListRequest) Parameter(name string, value interface{}) *LogsListRequest { 90 helpers.AddValue(&r.query, name, value) 91 return r 92 } 93 94 // Header adds a request header. 95 func (r *LogsListRequest) Header(name string, value interface{}) *LogsListRequest { 96 helpers.AddHeader(&r.header, name, value) 97 return r 98 } 99 100 // Impersonate wraps requests on behalf of another user. 101 // Note: Services that do not support this feature may silently ignore this call. 102 func (r *LogsListRequest) Impersonate(user string) *LogsListRequest { 103 helpers.AddImpersonationHeader(&r.header, user) 104 return r 105 } 106 107 // Page sets the value of the 'page' parameter. 108 // 109 // Index of the requested page, where one corresponds to the first page. 110 func (r *LogsListRequest) Page(value int) *LogsListRequest { 111 r.page = &value 112 return r 113 } 114 115 // Size sets the value of the 'size' parameter. 116 // 117 // Number of items contained in the returned page. 118 func (r *LogsListRequest) Size(value int) *LogsListRequest { 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 *LogsListRequest) Send() (result *LogsListResponse, 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 *LogsListRequest) SendContext(ctx context.Context) (result *LogsListResponse, 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 uri := &url.URL{ 142 Path: r.path, 143 RawQuery: query.Encode(), 144 } 145 request := &http.Request{ 146 Method: "GET", 147 URL: uri, 148 Header: header, 149 } 150 if ctx != nil { 151 request = request.WithContext(ctx) 152 } 153 response, err := r.transport.RoundTrip(request) 154 if err != nil { 155 return 156 } 157 defer response.Body.Close() 158 result = &LogsListResponse{} 159 result.status = response.StatusCode 160 result.header = response.Header 161 reader := bufio.NewReader(response.Body) 162 _, err = reader.Peek(1) 163 if err == io.EOF { 164 err = nil 165 return 166 } 167 if result.status >= 400 { 168 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 169 if err != nil { 170 return 171 } 172 err = result.err 173 return 174 } 175 err = readLogsListResponse(result, reader) 176 if err != nil { 177 return 178 } 179 return 180 } 181 182 // LogsListResponse is the response for the 'list' method. 183 type LogsListResponse struct { 184 status int 185 header http.Header 186 err *errors.Error 187 items *LogList 188 page *int 189 size *int 190 total *int 191 } 192 193 // Status returns the response status code. 194 func (r *LogsListResponse) Status() int { 195 if r == nil { 196 return 0 197 } 198 return r.status 199 } 200 201 // Header returns header of the response. 202 func (r *LogsListResponse) Header() http.Header { 203 if r == nil { 204 return nil 205 } 206 return r.header 207 } 208 209 // Error returns the response error. 210 func (r *LogsListResponse) Error() *errors.Error { 211 if r == nil { 212 return nil 213 } 214 return r.err 215 } 216 217 // Items returns the value of the 'items' parameter. 218 // 219 // Retrieved list of log links. 220 func (r *LogsListResponse) Items() *LogList { 221 if r == nil { 222 return nil 223 } 224 return r.items 225 } 226 227 // GetItems returns the value of the 'items' parameter and 228 // a flag indicating if the parameter has a value. 229 // 230 // Retrieved list of log links. 231 func (r *LogsListResponse) GetItems() (value *LogList, ok bool) { 232 ok = r != nil && r.items != nil 233 if ok { 234 value = r.items 235 } 236 return 237 } 238 239 // Page returns the value of the 'page' parameter. 240 // 241 // Index of the requested page, where one corresponds to the first page. 242 func (r *LogsListResponse) Page() int { 243 if r != nil && r.page != nil { 244 return *r.page 245 } 246 return 0 247 } 248 249 // GetPage returns the value of the 'page' parameter and 250 // a flag indicating if the parameter has a value. 251 // 252 // Index of the requested page, where one corresponds to the first page. 253 func (r *LogsListResponse) GetPage() (value int, ok bool) { 254 ok = r != nil && r.page != nil 255 if ok { 256 value = *r.page 257 } 258 return 259 } 260 261 // Size returns the value of the 'size' parameter. 262 // 263 // Number of items contained in the returned page. 264 func (r *LogsListResponse) Size() int { 265 if r != nil && r.size != nil { 266 return *r.size 267 } 268 return 0 269 } 270 271 // GetSize returns the value of the 'size' parameter and 272 // a flag indicating if the parameter has a value. 273 // 274 // Number of items contained in the returned page. 275 func (r *LogsListResponse) GetSize() (value int, ok bool) { 276 ok = r != nil && r.size != nil 277 if ok { 278 value = *r.size 279 } 280 return 281 } 282 283 // Total returns the value of the 'total' parameter. 284 // 285 // Total number of items of the collection. 286 func (r *LogsListResponse) Total() int { 287 if r != nil && r.total != nil { 288 return *r.total 289 } 290 return 0 291 } 292 293 // GetTotal returns the value of the 'total' parameter and 294 // a flag indicating if the parameter has a value. 295 // 296 // Total number of items of the collection. 297 func (r *LogsListResponse) GetTotal() (value int, ok bool) { 298 ok = r != nil && r.total != nil 299 if ok { 300 value = *r.total 301 } 302 return 303 }