github.com/openshift-online/ocm-sdk-go@v0.1.473/accountsmgmt/v1/role_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/accountsmgmt/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  // RoleBindingsClient is the client of the 'role_bindings' resource.
    36  //
    37  // Manages the collection of role bindings.
    38  type RoleBindingsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewRoleBindingsClient creates a new client for the 'role_bindings'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewRoleBindingsClient(transport http.RoundTripper, path string) *RoleBindingsClient {
    47  	return &RoleBindingsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Creates a new role binding.
    56  func (c *RoleBindingsClient) Add() *RoleBindingsAddRequest {
    57  	return &RoleBindingsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // List creates a request for the 'list' method.
    64  //
    65  // Retrieves a list of role bindings.
    66  func (c *RoleBindingsClient) List() *RoleBindingsListRequest {
    67  	return &RoleBindingsListRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // RoleBinding returns the target 'role_binding' resource for the given identifier.
    74  //
    75  // Reference to the service that manages a specific role binding.
    76  func (c *RoleBindingsClient) RoleBinding(id string) *RoleBindingClient {
    77  	return NewRoleBindingClient(
    78  		c.transport,
    79  		path.Join(c.path, id),
    80  	)
    81  }
    82  
    83  // RoleBindingsAddRequest is the request for the 'add' method.
    84  type RoleBindingsAddRequest struct {
    85  	transport http.RoundTripper
    86  	path      string
    87  	query     url.Values
    88  	header    http.Header
    89  	body      *RoleBinding
    90  }
    91  
    92  // Parameter adds a query parameter.
    93  func (r *RoleBindingsAddRequest) Parameter(name string, value interface{}) *RoleBindingsAddRequest {
    94  	helpers.AddValue(&r.query, name, value)
    95  	return r
    96  }
    97  
    98  // Header adds a request header.
    99  func (r *RoleBindingsAddRequest) Header(name string, value interface{}) *RoleBindingsAddRequest {
   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 *RoleBindingsAddRequest) Impersonate(user string) *RoleBindingsAddRequest {
   107  	helpers.AddImpersonationHeader(&r.header, user)
   108  	return r
   109  }
   110  
   111  // Body sets the value of the 'body' parameter.
   112  //
   113  // Role binding data.
   114  func (r *RoleBindingsAddRequest) Body(value *RoleBinding) *RoleBindingsAddRequest {
   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 *RoleBindingsAddRequest) Send() (result *RoleBindingsAddResponse, 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 *RoleBindingsAddRequest) SendContext(ctx context.Context) (result *RoleBindingsAddResponse, err error) {
   129  	query := helpers.CopyQuery(r.query)
   130  	header := helpers.CopyHeader(r.header)
   131  	buffer := &bytes.Buffer{}
   132  	err = writeRoleBindingsAddRequest(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 = &RoleBindingsAddResponse{}
   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 = readRoleBindingsAddResponse(result, reader)
   172  	if err != nil {
   173  		return
   174  	}
   175  	return
   176  }
   177  
   178  // RoleBindingsAddResponse is the response for the 'add' method.
   179  type RoleBindingsAddResponse struct {
   180  	status int
   181  	header http.Header
   182  	err    *errors.Error
   183  	body   *RoleBinding
   184  }
   185  
   186  // Status returns the response status code.
   187  func (r *RoleBindingsAddResponse) 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 *RoleBindingsAddResponse) 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 *RoleBindingsAddResponse) 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  // Role binding data.
   213  func (r *RoleBindingsAddResponse) Body() *RoleBinding {
   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  // Role binding data.
   224  func (r *RoleBindingsAddResponse) GetBody() (value *RoleBinding, ok bool) {
   225  	ok = r != nil && r.body != nil
   226  	if ok {
   227  		value = r.body
   228  	}
   229  	return
   230  }
   231  
   232  // RoleBindingsListRequest is the request for the 'list' method.
   233  type RoleBindingsListRequest struct {
   234  	transport http.RoundTripper
   235  	path      string
   236  	query     url.Values
   237  	header    http.Header
   238  	page      *int
   239  	search    *string
   240  	size      *int
   241  }
   242  
   243  // Parameter adds a query parameter.
   244  func (r *RoleBindingsListRequest) Parameter(name string, value interface{}) *RoleBindingsListRequest {
   245  	helpers.AddValue(&r.query, name, value)
   246  	return r
   247  }
   248  
   249  // Header adds a request header.
   250  func (r *RoleBindingsListRequest) Header(name string, value interface{}) *RoleBindingsListRequest {
   251  	helpers.AddHeader(&r.header, name, value)
   252  	return r
   253  }
   254  
   255  // Impersonate wraps requests on behalf of another user.
   256  // Note: Services that do not support this feature may silently ignore this call.
   257  func (r *RoleBindingsListRequest) Impersonate(user string) *RoleBindingsListRequest {
   258  	helpers.AddImpersonationHeader(&r.header, user)
   259  	return r
   260  }
   261  
   262  // Page sets the value of the 'page' parameter.
   263  //
   264  // Index of the requested page, where one corresponds to the first page.
   265  func (r *RoleBindingsListRequest) Page(value int) *RoleBindingsListRequest {
   266  	r.page = &value
   267  	return r
   268  }
   269  
   270  // Search sets the value of the 'search' parameter.
   271  //
   272  // Search criteria.
   273  //
   274  // The syntax of this parameter is similar to the syntax of the _where_ clause
   275  // of an SQL statement, but using the names of the attributes of the role binding
   276  // instead of the names of the columns of a table. For example, in order to
   277  // retrieve role bindings with role_id AuthenticatedUser:
   278  //
   279  // ```sql
   280  // role_id = 'AuthenticatedUser'
   281  // ```
   282  //
   283  // If the parameter isn't provided, or if the value is empty, then all the
   284  // items that the user has permission to see will be returned.
   285  func (r *RoleBindingsListRequest) Search(value string) *RoleBindingsListRequest {
   286  	r.search = &value
   287  	return r
   288  }
   289  
   290  // Size sets the value of the 'size' parameter.
   291  //
   292  // Maximum number of items that will be contained in the returned page.
   293  func (r *RoleBindingsListRequest) Size(value int) *RoleBindingsListRequest {
   294  	r.size = &value
   295  	return r
   296  }
   297  
   298  // Send sends this request, waits for the response, and returns it.
   299  //
   300  // This is a potentially lengthy operation, as it requires network communication.
   301  // Consider using a context and the SendContext method.
   302  func (r *RoleBindingsListRequest) Send() (result *RoleBindingsListResponse, err error) {
   303  	return r.SendContext(context.Background())
   304  }
   305  
   306  // SendContext sends this request, waits for the response, and returns it.
   307  func (r *RoleBindingsListRequest) SendContext(ctx context.Context) (result *RoleBindingsListResponse, err error) {
   308  	query := helpers.CopyQuery(r.query)
   309  	if r.page != nil {
   310  		helpers.AddValue(&query, "page", *r.page)
   311  	}
   312  	if r.search != nil {
   313  		helpers.AddValue(&query, "search", *r.search)
   314  	}
   315  	if r.size != nil {
   316  		helpers.AddValue(&query, "size", *r.size)
   317  	}
   318  	header := helpers.CopyHeader(r.header)
   319  	uri := &url.URL{
   320  		Path:     r.path,
   321  		RawQuery: query.Encode(),
   322  	}
   323  	request := &http.Request{
   324  		Method: "GET",
   325  		URL:    uri,
   326  		Header: header,
   327  	}
   328  	if ctx != nil {
   329  		request = request.WithContext(ctx)
   330  	}
   331  	response, err := r.transport.RoundTrip(request)
   332  	if err != nil {
   333  		return
   334  	}
   335  	defer response.Body.Close()
   336  	result = &RoleBindingsListResponse{}
   337  	result.status = response.StatusCode
   338  	result.header = response.Header
   339  	reader := bufio.NewReader(response.Body)
   340  	_, err = reader.Peek(1)
   341  	if err == io.EOF {
   342  		err = nil
   343  		return
   344  	}
   345  	if result.status >= 400 {
   346  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   347  		if err != nil {
   348  			return
   349  		}
   350  		err = result.err
   351  		return
   352  	}
   353  	err = readRoleBindingsListResponse(result, reader)
   354  	if err != nil {
   355  		return
   356  	}
   357  	return
   358  }
   359  
   360  // RoleBindingsListResponse is the response for the 'list' method.
   361  type RoleBindingsListResponse struct {
   362  	status int
   363  	header http.Header
   364  	err    *errors.Error
   365  	items  *RoleBindingList
   366  	page   *int
   367  	size   *int
   368  	total  *int
   369  }
   370  
   371  // Status returns the response status code.
   372  func (r *RoleBindingsListResponse) Status() int {
   373  	if r == nil {
   374  		return 0
   375  	}
   376  	return r.status
   377  }
   378  
   379  // Header returns header of the response.
   380  func (r *RoleBindingsListResponse) Header() http.Header {
   381  	if r == nil {
   382  		return nil
   383  	}
   384  	return r.header
   385  }
   386  
   387  // Error returns the response error.
   388  func (r *RoleBindingsListResponse) Error() *errors.Error {
   389  	if r == nil {
   390  		return nil
   391  	}
   392  	return r.err
   393  }
   394  
   395  // Items returns the value of the 'items' parameter.
   396  //
   397  // Retrieved list of role bindings.
   398  func (r *RoleBindingsListResponse) Items() *RoleBindingList {
   399  	if r == nil {
   400  		return nil
   401  	}
   402  	return r.items
   403  }
   404  
   405  // GetItems returns the value of the 'items' parameter and
   406  // a flag indicating if the parameter has a value.
   407  //
   408  // Retrieved list of role bindings.
   409  func (r *RoleBindingsListResponse) GetItems() (value *RoleBindingList, ok bool) {
   410  	ok = r != nil && r.items != nil
   411  	if ok {
   412  		value = r.items
   413  	}
   414  	return
   415  }
   416  
   417  // Page returns the value of the 'page' parameter.
   418  //
   419  // Index of the requested page, where one corresponds to the first page.
   420  func (r *RoleBindingsListResponse) Page() int {
   421  	if r != nil && r.page != nil {
   422  		return *r.page
   423  	}
   424  	return 0
   425  }
   426  
   427  // GetPage returns the value of the 'page' parameter and
   428  // a flag indicating if the parameter has a value.
   429  //
   430  // Index of the requested page, where one corresponds to the first page.
   431  func (r *RoleBindingsListResponse) GetPage() (value int, ok bool) {
   432  	ok = r != nil && r.page != nil
   433  	if ok {
   434  		value = *r.page
   435  	}
   436  	return
   437  }
   438  
   439  // Size returns the value of the 'size' parameter.
   440  //
   441  // Maximum number of items that will be contained in the returned page.
   442  func (r *RoleBindingsListResponse) Size() int {
   443  	if r != nil && r.size != nil {
   444  		return *r.size
   445  	}
   446  	return 0
   447  }
   448  
   449  // GetSize returns the value of the 'size' parameter and
   450  // a flag indicating if the parameter has a value.
   451  //
   452  // Maximum number of items that will be contained in the returned page.
   453  func (r *RoleBindingsListResponse) GetSize() (value int, ok bool) {
   454  	ok = r != nil && r.size != nil
   455  	if ok {
   456  		value = *r.size
   457  	}
   458  	return
   459  }
   460  
   461  // Total returns the value of the 'total' parameter.
   462  //
   463  // Total number of items of the collection that match the search criteria,
   464  // regardless of the size of the page.
   465  func (r *RoleBindingsListResponse) Total() int {
   466  	if r != nil && r.total != nil {
   467  		return *r.total
   468  	}
   469  	return 0
   470  }
   471  
   472  // GetTotal returns the value of the 'total' parameter and
   473  // a flag indicating if the parameter has a value.
   474  //
   475  // Total number of items of the collection that match the search criteria,
   476  // regardless of the size of the page.
   477  func (r *RoleBindingsListResponse) GetTotal() (value int, ok bool) {
   478  	ok = r != nil && r.total != nil
   479  	if ok {
   480  		value = *r.total
   481  	}
   482  	return
   483  }