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