github.com/openshift-online/ocm-sdk-go@v0.1.473/accesstransparency/v1/decisions_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/accesstransparency/v1 21 22 import ( 23 "bufio" 24 "bytes" 25 "context" 26 "io" 27 "net/http" 28 "net/url" 29 "path" 30 31 "github.com/openshift-online/ocm-sdk-go/errors" 32 "github.com/openshift-online/ocm-sdk-go/helpers" 33 ) 34 35 // DecisionsClient is the client of the 'decisions' resource. 36 // 37 // Manages a collection of decisions attached to an access request. 38 type DecisionsClient struct { 39 transport http.RoundTripper 40 path string 41 } 42 43 // NewDecisionsClient creates a new client for the 'decisions' 44 // resource using the given transport to send the requests and receive the 45 // responses. 46 func NewDecisionsClient(transport http.RoundTripper, path string) *DecisionsClient { 47 return &DecisionsClient{ 48 transport: transport, 49 path: path, 50 } 51 } 52 53 // Add creates a request for the 'add' method. 54 // 55 // Create a new decision and add it to the collection of decisions of an access request. 56 func (c *DecisionsClient) Add() *DecisionsAddRequest { 57 return &DecisionsAddRequest{ 58 transport: c.transport, 59 path: c.path, 60 } 61 } 62 63 // List creates a request for the 'list' method. 64 // 65 // Retrieves the list of decisions. 66 func (c *DecisionsClient) List() *DecisionsListRequest { 67 return &DecisionsListRequest{ 68 transport: c.transport, 69 path: c.path, 70 } 71 } 72 73 // Decision returns the target 'decision' resource for the given identifier. 74 // 75 // Returns a reference to the service that manages a specific decision. 76 func (c *DecisionsClient) Decision(id string) *DecisionClient { 77 return NewDecisionClient( 78 c.transport, 79 path.Join(c.path, id), 80 ) 81 } 82 83 // DecisionsAddRequest is the request for the 'add' method. 84 type DecisionsAddRequest struct { 85 transport http.RoundTripper 86 path string 87 query url.Values 88 header http.Header 89 body *Decision 90 } 91 92 // Parameter adds a query parameter. 93 func (r *DecisionsAddRequest) Parameter(name string, value interface{}) *DecisionsAddRequest { 94 helpers.AddValue(&r.query, name, value) 95 return r 96 } 97 98 // Header adds a request header. 99 func (r *DecisionsAddRequest) Header(name string, value interface{}) *DecisionsAddRequest { 100 helpers.AddHeader(&r.header, name, value) 101 return r 102 } 103 104 // Impersonate wraps requests on behalf of another user. 105 // Note: Services that do not support this feature may silently ignore this call. 106 func (r *DecisionsAddRequest) Impersonate(user string) *DecisionsAddRequest { 107 helpers.AddImpersonationHeader(&r.header, user) 108 return r 109 } 110 111 // Body sets the value of the 'body' parameter. 112 // 113 // Description of the decision addition. 114 func (r *DecisionsAddRequest) Body(value *Decision) *DecisionsAddRequest { 115 r.body = value 116 return r 117 } 118 119 // Send sends this request, waits for the response, and returns it. 120 // 121 // This is a potentially lengthy operation, as it requires network communication. 122 // Consider using a context and the SendContext method. 123 func (r *DecisionsAddRequest) Send() (result *DecisionsAddResponse, err error) { 124 return r.SendContext(context.Background()) 125 } 126 127 // SendContext sends this request, waits for the response, and returns it. 128 func (r *DecisionsAddRequest) SendContext(ctx context.Context) (result *DecisionsAddResponse, err error) { 129 query := helpers.CopyQuery(r.query) 130 header := helpers.CopyHeader(r.header) 131 buffer := &bytes.Buffer{} 132 err = writeDecisionsAddRequest(r, buffer) 133 if err != nil { 134 return 135 } 136 uri := &url.URL{ 137 Path: r.path, 138 RawQuery: query.Encode(), 139 } 140 request := &http.Request{ 141 Method: "POST", 142 URL: uri, 143 Header: header, 144 Body: io.NopCloser(buffer), 145 } 146 if ctx != nil { 147 request = request.WithContext(ctx) 148 } 149 response, err := r.transport.RoundTrip(request) 150 if err != nil { 151 return 152 } 153 defer response.Body.Close() 154 result = &DecisionsAddResponse{} 155 result.status = response.StatusCode 156 result.header = response.Header 157 reader := bufio.NewReader(response.Body) 158 _, err = reader.Peek(1) 159 if err == io.EOF { 160 err = nil 161 return 162 } 163 if result.status >= 400 { 164 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 165 if err != nil { 166 return 167 } 168 err = result.err 169 return 170 } 171 err = readDecisionsAddResponse(result, reader) 172 if err != nil { 173 return 174 } 175 return 176 } 177 178 // DecisionsAddResponse is the response for the 'add' method. 179 type DecisionsAddResponse struct { 180 status int 181 header http.Header 182 err *errors.Error 183 body *Decision 184 } 185 186 // Status returns the response status code. 187 func (r *DecisionsAddResponse) Status() int { 188 if r == nil { 189 return 0 190 } 191 return r.status 192 } 193 194 // Header returns header of the response. 195 func (r *DecisionsAddResponse) Header() http.Header { 196 if r == nil { 197 return nil 198 } 199 return r.header 200 } 201 202 // Error returns the response error. 203 func (r *DecisionsAddResponse) Error() *errors.Error { 204 if r == nil { 205 return nil 206 } 207 return r.err 208 } 209 210 // Body returns the value of the 'body' parameter. 211 // 212 // Description of the decision addition. 213 func (r *DecisionsAddResponse) Body() *Decision { 214 if r == nil { 215 return nil 216 } 217 return r.body 218 } 219 220 // GetBody returns the value of the 'body' parameter and 221 // a flag indicating if the parameter has a value. 222 // 223 // Description of the decision addition. 224 func (r *DecisionsAddResponse) GetBody() (value *Decision, ok bool) { 225 ok = r != nil && r.body != nil 226 if ok { 227 value = r.body 228 } 229 return 230 } 231 232 // DecisionsListRequest is the request for the 'list' method. 233 type DecisionsListRequest struct { 234 transport http.RoundTripper 235 path string 236 query url.Values 237 header http.Header 238 order *string 239 page *int 240 search *string 241 size *int 242 } 243 244 // Parameter adds a query parameter. 245 func (r *DecisionsListRequest) Parameter(name string, value interface{}) *DecisionsListRequest { 246 helpers.AddValue(&r.query, name, value) 247 return r 248 } 249 250 // Header adds a request header. 251 func (r *DecisionsListRequest) Header(name string, value interface{}) *DecisionsListRequest { 252 helpers.AddHeader(&r.header, name, value) 253 return r 254 } 255 256 // Impersonate wraps requests on behalf of another user. 257 // Note: Services that do not support this feature may silently ignore this call. 258 func (r *DecisionsListRequest) Impersonate(user string) *DecisionsListRequest { 259 helpers.AddImpersonationHeader(&r.header, user) 260 return r 261 } 262 263 // Order sets the value of the 'order' parameter. 264 // 265 // Order criteria. 266 // 267 // The syntax of this parameter is similar to the syntax of the _order by_ clause of 268 // a SQL statement, but using the names of the attributes of the decision instead of 269 // the names of the columns of a table. For example, in order to sort the decisions 270 // descending by created_at the value should be: 271 // 272 // ```sql 273 // created_at desc 274 // ``` 275 // 276 // If the parameter isn't provided, or if the value is empty, then the order of the 277 // results is undefined. 278 func (r *DecisionsListRequest) Order(value string) *DecisionsListRequest { 279 r.order = &value 280 return r 281 } 282 283 // Page sets the value of the 'page' parameter. 284 // 285 // Index of the requested page, where one corresponds to the first page. 286 func (r *DecisionsListRequest) Page(value int) *DecisionsListRequest { 287 r.page = &value 288 return r 289 } 290 291 // Search sets the value of the 'search' parameter. 292 // 293 // Search criteria. 294 // 295 // The syntax of this parameter is similar to the syntax of the _where_ clause of an 296 // SQL statement, but using the names of the attributes of the decision instead of 297 // the names of the columns of a table. For example, in order to retrieve all the 298 // decisions with a decided_by starting with `my` the value should be: 299 // 300 // ```sql 301 // decided_by like 'my%' 302 // ``` 303 // 304 // If the parameter isn't provided, or if the value is empty, then all the decisions 305 // that the user has permission to see will be returned. 306 func (r *DecisionsListRequest) Search(value string) *DecisionsListRequest { 307 r.search = &value 308 return r 309 } 310 311 // Size sets the value of the 'size' parameter. 312 // 313 // Maximum number of items that will be contained in the returned page. 314 func (r *DecisionsListRequest) Size(value int) *DecisionsListRequest { 315 r.size = &value 316 return r 317 } 318 319 // Send sends this request, waits for the response, and returns it. 320 // 321 // This is a potentially lengthy operation, as it requires network communication. 322 // Consider using a context and the SendContext method. 323 func (r *DecisionsListRequest) Send() (result *DecisionsListResponse, err error) { 324 return r.SendContext(context.Background()) 325 } 326 327 // SendContext sends this request, waits for the response, and returns it. 328 func (r *DecisionsListRequest) SendContext(ctx context.Context) (result *DecisionsListResponse, err error) { 329 query := helpers.CopyQuery(r.query) 330 if r.order != nil { 331 helpers.AddValue(&query, "order", *r.order) 332 } 333 if r.page != nil { 334 helpers.AddValue(&query, "page", *r.page) 335 } 336 if r.search != nil { 337 helpers.AddValue(&query, "search", *r.search) 338 } 339 if r.size != nil { 340 helpers.AddValue(&query, "size", *r.size) 341 } 342 header := helpers.CopyHeader(r.header) 343 uri := &url.URL{ 344 Path: r.path, 345 RawQuery: query.Encode(), 346 } 347 request := &http.Request{ 348 Method: "GET", 349 URL: uri, 350 Header: header, 351 } 352 if ctx != nil { 353 request = request.WithContext(ctx) 354 } 355 response, err := r.transport.RoundTrip(request) 356 if err != nil { 357 return 358 } 359 defer response.Body.Close() 360 result = &DecisionsListResponse{} 361 result.status = response.StatusCode 362 result.header = response.Header 363 reader := bufio.NewReader(response.Body) 364 _, err = reader.Peek(1) 365 if err == io.EOF { 366 err = nil 367 return 368 } 369 if result.status >= 400 { 370 result.err, err = errors.UnmarshalErrorStatus(reader, result.status) 371 if err != nil { 372 return 373 } 374 err = result.err 375 return 376 } 377 err = readDecisionsListResponse(result, reader) 378 if err != nil { 379 return 380 } 381 return 382 } 383 384 // DecisionsListResponse is the response for the 'list' method. 385 type DecisionsListResponse struct { 386 status int 387 header http.Header 388 err *errors.Error 389 items *DecisionList 390 page *int 391 size *int 392 total *int 393 } 394 395 // Status returns the response status code. 396 func (r *DecisionsListResponse) Status() int { 397 if r == nil { 398 return 0 399 } 400 return r.status 401 } 402 403 // Header returns header of the response. 404 func (r *DecisionsListResponse) Header() http.Header { 405 if r == nil { 406 return nil 407 } 408 return r.header 409 } 410 411 // Error returns the response error. 412 func (r *DecisionsListResponse) Error() *errors.Error { 413 if r == nil { 414 return nil 415 } 416 return r.err 417 } 418 419 // Items returns the value of the 'items' parameter. 420 // 421 // Retrieved list of decisions. 422 func (r *DecisionsListResponse) Items() *DecisionList { 423 if r == nil { 424 return nil 425 } 426 return r.items 427 } 428 429 // GetItems returns the value of the 'items' parameter and 430 // a flag indicating if the parameter has a value. 431 // 432 // Retrieved list of decisions. 433 func (r *DecisionsListResponse) GetItems() (value *DecisionList, ok bool) { 434 ok = r != nil && r.items != nil 435 if ok { 436 value = r.items 437 } 438 return 439 } 440 441 // Page returns the value of the 'page' parameter. 442 // 443 // Index of the requested page, where one corresponds to the first page. 444 func (r *DecisionsListResponse) Page() int { 445 if r != nil && r.page != nil { 446 return *r.page 447 } 448 return 0 449 } 450 451 // GetPage returns the value of the 'page' parameter and 452 // a flag indicating if the parameter has a value. 453 // 454 // Index of the requested page, where one corresponds to the first page. 455 func (r *DecisionsListResponse) GetPage() (value int, ok bool) { 456 ok = r != nil && r.page != nil 457 if ok { 458 value = *r.page 459 } 460 return 461 } 462 463 // Size returns the value of the 'size' parameter. 464 // 465 // Maximum number of items that will be contained in the returned page. 466 func (r *DecisionsListResponse) Size() int { 467 if r != nil && r.size != nil { 468 return *r.size 469 } 470 return 0 471 } 472 473 // GetSize returns the value of the 'size' parameter and 474 // a flag indicating if the parameter has a value. 475 // 476 // Maximum number of items that will be contained in the returned page. 477 func (r *DecisionsListResponse) GetSize() (value int, ok bool) { 478 ok = r != nil && r.size != nil 479 if ok { 480 value = *r.size 481 } 482 return 483 } 484 485 // Total returns the value of the 'total' parameter. 486 // 487 // Total number of items of the collection that match the search criteria, 488 // regardless of the size of the page. 489 func (r *DecisionsListResponse) Total() int { 490 if r != nil && r.total != nil { 491 return *r.total 492 } 493 return 0 494 } 495 496 // GetTotal returns the value of the 'total' parameter and 497 // a flag indicating if the parameter has a value. 498 // 499 // Total number of items of the collection that match the search criteria, 500 // regardless of the size of the page. 501 func (r *DecisionsListResponse) GetTotal() (value int, ok bool) { 502 ok = r != nil && r.total != nil 503 if ok { 504 value = *r.total 505 } 506 return 507 }