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