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