github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/break_glass_credentials_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  // BreakGlassCredentialsClient is the client of the 'break_glass_credentials' resource.
    36  //
    37  // Manages the break glass credentials of a cluster.
    38  type BreakGlassCredentialsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewBreakGlassCredentialsClient creates a new client for the 'break_glass_credentials'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewBreakGlassCredentialsClient(transport http.RoundTripper, path string) *BreakGlassCredentialsClient {
    47  	return &BreakGlassCredentialsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Adds a new break glass credential to the cluster.
    56  func (c *BreakGlassCredentialsClient) Add() *BreakGlassCredentialsAddRequest {
    57  	return &BreakGlassCredentialsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // Delete creates a request for the 'delete' method.
    64  //
    65  // Revokes all the break glass certificates signed by a specific signer.
    66  func (c *BreakGlassCredentialsClient) Delete() *BreakGlassCredentialsDeleteRequest {
    67  	return &BreakGlassCredentialsDeleteRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // List creates a request for the 'list' method.
    74  //
    75  // Retrieves the list of break glass credentials.
    76  func (c *BreakGlassCredentialsClient) List() *BreakGlassCredentialsListRequest {
    77  	return &BreakGlassCredentialsListRequest{
    78  		transport: c.transport,
    79  		path:      c.path,
    80  	}
    81  }
    82  
    83  // BreakGlassCredential returns the target 'break_glass_credential' resource for the given identifier.
    84  //
    85  // Reference to the service that manages a specific break glass credential.
    86  func (c *BreakGlassCredentialsClient) BreakGlassCredential(id string) *BreakGlassCredentialClient {
    87  	return NewBreakGlassCredentialClient(
    88  		c.transport,
    89  		path.Join(c.path, id),
    90  	)
    91  }
    92  
    93  // BreakGlassCredentialsAddRequest is the request for the 'add' method.
    94  type BreakGlassCredentialsAddRequest struct {
    95  	transport http.RoundTripper
    96  	path      string
    97  	query     url.Values
    98  	header    http.Header
    99  	body      *BreakGlassCredential
   100  }
   101  
   102  // Parameter adds a query parameter.
   103  func (r *BreakGlassCredentialsAddRequest) Parameter(name string, value interface{}) *BreakGlassCredentialsAddRequest {
   104  	helpers.AddValue(&r.query, name, value)
   105  	return r
   106  }
   107  
   108  // Header adds a request header.
   109  func (r *BreakGlassCredentialsAddRequest) Header(name string, value interface{}) *BreakGlassCredentialsAddRequest {
   110  	helpers.AddHeader(&r.header, name, value)
   111  	return r
   112  }
   113  
   114  // Impersonate wraps requests on behalf of another user.
   115  // Note: Services that do not support this feature may silently ignore this call.
   116  func (r *BreakGlassCredentialsAddRequest) Impersonate(user string) *BreakGlassCredentialsAddRequest {
   117  	helpers.AddImpersonationHeader(&r.header, user)
   118  	return r
   119  }
   120  
   121  // Body sets the value of the 'body' parameter.
   122  //
   123  // Description of the break glass credential.
   124  func (r *BreakGlassCredentialsAddRequest) Body(value *BreakGlassCredential) *BreakGlassCredentialsAddRequest {
   125  	r.body = value
   126  	return r
   127  }
   128  
   129  // Send sends this request, waits for the response, and returns it.
   130  //
   131  // This is a potentially lengthy operation, as it requires network communication.
   132  // Consider using a context and the SendContext method.
   133  func (r *BreakGlassCredentialsAddRequest) Send() (result *BreakGlassCredentialsAddResponse, err error) {
   134  	return r.SendContext(context.Background())
   135  }
   136  
   137  // SendContext sends this request, waits for the response, and returns it.
   138  func (r *BreakGlassCredentialsAddRequest) SendContext(ctx context.Context) (result *BreakGlassCredentialsAddResponse, err error) {
   139  	query := helpers.CopyQuery(r.query)
   140  	header := helpers.CopyHeader(r.header)
   141  	buffer := &bytes.Buffer{}
   142  	err = writeBreakGlassCredentialsAddRequest(r, buffer)
   143  	if err != nil {
   144  		return
   145  	}
   146  	uri := &url.URL{
   147  		Path:     r.path,
   148  		RawQuery: query.Encode(),
   149  	}
   150  	request := &http.Request{
   151  		Method: "POST",
   152  		URL:    uri,
   153  		Header: header,
   154  		Body:   io.NopCloser(buffer),
   155  	}
   156  	if ctx != nil {
   157  		request = request.WithContext(ctx)
   158  	}
   159  	response, err := r.transport.RoundTrip(request)
   160  	if err != nil {
   161  		return
   162  	}
   163  	defer response.Body.Close()
   164  	result = &BreakGlassCredentialsAddResponse{}
   165  	result.status = response.StatusCode
   166  	result.header = response.Header
   167  	reader := bufio.NewReader(response.Body)
   168  	_, err = reader.Peek(1)
   169  	if err == io.EOF {
   170  		err = nil
   171  		return
   172  	}
   173  	if result.status >= 400 {
   174  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   175  		if err != nil {
   176  			return
   177  		}
   178  		err = result.err
   179  		return
   180  	}
   181  	err = readBreakGlassCredentialsAddResponse(result, reader)
   182  	if err != nil {
   183  		return
   184  	}
   185  	return
   186  }
   187  
   188  // BreakGlassCredentialsAddResponse is the response for the 'add' method.
   189  type BreakGlassCredentialsAddResponse struct {
   190  	status int
   191  	header http.Header
   192  	err    *errors.Error
   193  	body   *BreakGlassCredential
   194  }
   195  
   196  // Status returns the response status code.
   197  func (r *BreakGlassCredentialsAddResponse) Status() int {
   198  	if r == nil {
   199  		return 0
   200  	}
   201  	return r.status
   202  }
   203  
   204  // Header returns header of the response.
   205  func (r *BreakGlassCredentialsAddResponse) Header() http.Header {
   206  	if r == nil {
   207  		return nil
   208  	}
   209  	return r.header
   210  }
   211  
   212  // Error returns the response error.
   213  func (r *BreakGlassCredentialsAddResponse) Error() *errors.Error {
   214  	if r == nil {
   215  		return nil
   216  	}
   217  	return r.err
   218  }
   219  
   220  // Body returns the value of the 'body' parameter.
   221  //
   222  // Description of the break glass credential.
   223  func (r *BreakGlassCredentialsAddResponse) Body() *BreakGlassCredential {
   224  	if r == nil {
   225  		return nil
   226  	}
   227  	return r.body
   228  }
   229  
   230  // GetBody returns the value of the 'body' parameter and
   231  // a flag indicating if the parameter has a value.
   232  //
   233  // Description of the break glass credential.
   234  func (r *BreakGlassCredentialsAddResponse) GetBody() (value *BreakGlassCredential, ok bool) {
   235  	ok = r != nil && r.body != nil
   236  	if ok {
   237  		value = r.body
   238  	}
   239  	return
   240  }
   241  
   242  // BreakGlassCredentialsDeleteRequest is the request for the 'delete' method.
   243  type BreakGlassCredentialsDeleteRequest struct {
   244  	transport http.RoundTripper
   245  	path      string
   246  	query     url.Values
   247  	header    http.Header
   248  }
   249  
   250  // Parameter adds a query parameter.
   251  func (r *BreakGlassCredentialsDeleteRequest) Parameter(name string, value interface{}) *BreakGlassCredentialsDeleteRequest {
   252  	helpers.AddValue(&r.query, name, value)
   253  	return r
   254  }
   255  
   256  // Header adds a request header.
   257  func (r *BreakGlassCredentialsDeleteRequest) Header(name string, value interface{}) *BreakGlassCredentialsDeleteRequest {
   258  	helpers.AddHeader(&r.header, name, value)
   259  	return r
   260  }
   261  
   262  // Impersonate wraps requests on behalf of another user.
   263  // Note: Services that do not support this feature may silently ignore this call.
   264  func (r *BreakGlassCredentialsDeleteRequest) Impersonate(user string) *BreakGlassCredentialsDeleteRequest {
   265  	helpers.AddImpersonationHeader(&r.header, user)
   266  	return r
   267  }
   268  
   269  // Send sends this request, waits for the response, and returns it.
   270  //
   271  // This is a potentially lengthy operation, as it requires network communication.
   272  // Consider using a context and the SendContext method.
   273  func (r *BreakGlassCredentialsDeleteRequest) Send() (result *BreakGlassCredentialsDeleteResponse, err error) {
   274  	return r.SendContext(context.Background())
   275  }
   276  
   277  // SendContext sends this request, waits for the response, and returns it.
   278  func (r *BreakGlassCredentialsDeleteRequest) SendContext(ctx context.Context) (result *BreakGlassCredentialsDeleteResponse, err error) {
   279  	query := helpers.CopyQuery(r.query)
   280  	header := helpers.CopyHeader(r.header)
   281  	uri := &url.URL{
   282  		Path:     r.path,
   283  		RawQuery: query.Encode(),
   284  	}
   285  	request := &http.Request{
   286  		Method: "DELETE",
   287  		URL:    uri,
   288  		Header: header,
   289  	}
   290  	if ctx != nil {
   291  		request = request.WithContext(ctx)
   292  	}
   293  	response, err := r.transport.RoundTrip(request)
   294  	if err != nil {
   295  		return
   296  	}
   297  	defer response.Body.Close()
   298  	result = &BreakGlassCredentialsDeleteResponse{}
   299  	result.status = response.StatusCode
   300  	result.header = response.Header
   301  	reader := bufio.NewReader(response.Body)
   302  	_, err = reader.Peek(1)
   303  	if err == io.EOF {
   304  		err = nil
   305  		return
   306  	}
   307  	if result.status >= 400 {
   308  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   309  		if err != nil {
   310  			return
   311  		}
   312  		err = result.err
   313  		return
   314  	}
   315  	return
   316  }
   317  
   318  // BreakGlassCredentialsDeleteResponse is the response for the 'delete' method.
   319  type BreakGlassCredentialsDeleteResponse struct {
   320  	status int
   321  	header http.Header
   322  	err    *errors.Error
   323  }
   324  
   325  // Status returns the response status code.
   326  func (r *BreakGlassCredentialsDeleteResponse) Status() int {
   327  	if r == nil {
   328  		return 0
   329  	}
   330  	return r.status
   331  }
   332  
   333  // Header returns header of the response.
   334  func (r *BreakGlassCredentialsDeleteResponse) Header() http.Header {
   335  	if r == nil {
   336  		return nil
   337  	}
   338  	return r.header
   339  }
   340  
   341  // Error returns the response error.
   342  func (r *BreakGlassCredentialsDeleteResponse) Error() *errors.Error {
   343  	if r == nil {
   344  		return nil
   345  	}
   346  	return r.err
   347  }
   348  
   349  // BreakGlassCredentialsListRequest is the request for the 'list' method.
   350  type BreakGlassCredentialsListRequest struct {
   351  	transport http.RoundTripper
   352  	path      string
   353  	query     url.Values
   354  	header    http.Header
   355  	order     *string
   356  	page      *int
   357  	search    *string
   358  	size      *int
   359  }
   360  
   361  // Parameter adds a query parameter.
   362  func (r *BreakGlassCredentialsListRequest) Parameter(name string, value interface{}) *BreakGlassCredentialsListRequest {
   363  	helpers.AddValue(&r.query, name, value)
   364  	return r
   365  }
   366  
   367  // Header adds a request header.
   368  func (r *BreakGlassCredentialsListRequest) Header(name string, value interface{}) *BreakGlassCredentialsListRequest {
   369  	helpers.AddHeader(&r.header, name, value)
   370  	return r
   371  }
   372  
   373  // Impersonate wraps requests on behalf of another user.
   374  // Note: Services that do not support this feature may silently ignore this call.
   375  func (r *BreakGlassCredentialsListRequest) Impersonate(user string) *BreakGlassCredentialsListRequest {
   376  	helpers.AddImpersonationHeader(&r.header, user)
   377  	return r
   378  }
   379  
   380  // Order sets the value of the 'order' parameter.
   381  //
   382  // Order criteria.
   383  //
   384  // The syntax of this parameter is similar to the syntax of the _order by_ clause of
   385  // a SQL statement, but using the names of the attributes of the break glass credentials
   386  // instead of the the names of the columns of a table. For example, in order to sort the
   387  // credentials descending by identifier the value should be:
   388  //
   389  // ```sql
   390  // id desc
   391  // ```
   392  //
   393  // If the parameter isn't provided, or if the value is empty, then the order of the
   394  // results is undefined.
   395  func (r *BreakGlassCredentialsListRequest) Order(value string) *BreakGlassCredentialsListRequest {
   396  	r.order = &value
   397  	return r
   398  }
   399  
   400  // Page sets the value of the 'page' parameter.
   401  //
   402  // Index of the requested page, where one corresponds to the first page.
   403  func (r *BreakGlassCredentialsListRequest) Page(value int) *BreakGlassCredentialsListRequest {
   404  	r.page = &value
   405  	return r
   406  }
   407  
   408  // Search sets the value of the 'search' parameter.
   409  //
   410  // Search criteria.
   411  //
   412  // The syntax of this parameter is similar to the syntax of the _where_ clause of a
   413  // SQL statement, but using the names of the attributes of the break glass credentials
   414  // instead of the names of the columns of a table. For example, in order to retrieve all
   415  // the credentials with a specific username and status the following is required:
   416  //
   417  // ```sql
   418  // username='user1' AND status='expired'
   419  // ```
   420  //
   421  // If the parameter isn't provided, or if the value is empty, then all the
   422  // break glass credentials that the user has permission to see will be returned.
   423  func (r *BreakGlassCredentialsListRequest) Search(value string) *BreakGlassCredentialsListRequest {
   424  	r.search = &value
   425  	return r
   426  }
   427  
   428  // Size sets the value of the 'size' parameter.
   429  //
   430  // Number of items contained in the returned page.
   431  func (r *BreakGlassCredentialsListRequest) Size(value int) *BreakGlassCredentialsListRequest {
   432  	r.size = &value
   433  	return r
   434  }
   435  
   436  // Send sends this request, waits for the response, and returns it.
   437  //
   438  // This is a potentially lengthy operation, as it requires network communication.
   439  // Consider using a context and the SendContext method.
   440  func (r *BreakGlassCredentialsListRequest) Send() (result *BreakGlassCredentialsListResponse, err error) {
   441  	return r.SendContext(context.Background())
   442  }
   443  
   444  // SendContext sends this request, waits for the response, and returns it.
   445  func (r *BreakGlassCredentialsListRequest) SendContext(ctx context.Context) (result *BreakGlassCredentialsListResponse, err error) {
   446  	query := helpers.CopyQuery(r.query)
   447  	if r.order != nil {
   448  		helpers.AddValue(&query, "order", *r.order)
   449  	}
   450  	if r.page != nil {
   451  		helpers.AddValue(&query, "page", *r.page)
   452  	}
   453  	if r.search != nil {
   454  		helpers.AddValue(&query, "search", *r.search)
   455  	}
   456  	if r.size != nil {
   457  		helpers.AddValue(&query, "size", *r.size)
   458  	}
   459  	header := helpers.CopyHeader(r.header)
   460  	uri := &url.URL{
   461  		Path:     r.path,
   462  		RawQuery: query.Encode(),
   463  	}
   464  	request := &http.Request{
   465  		Method: "GET",
   466  		URL:    uri,
   467  		Header: header,
   468  	}
   469  	if ctx != nil {
   470  		request = request.WithContext(ctx)
   471  	}
   472  	response, err := r.transport.RoundTrip(request)
   473  	if err != nil {
   474  		return
   475  	}
   476  	defer response.Body.Close()
   477  	result = &BreakGlassCredentialsListResponse{}
   478  	result.status = response.StatusCode
   479  	result.header = response.Header
   480  	reader := bufio.NewReader(response.Body)
   481  	_, err = reader.Peek(1)
   482  	if err == io.EOF {
   483  		err = nil
   484  		return
   485  	}
   486  	if result.status >= 400 {
   487  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   488  		if err != nil {
   489  			return
   490  		}
   491  		err = result.err
   492  		return
   493  	}
   494  	err = readBreakGlassCredentialsListResponse(result, reader)
   495  	if err != nil {
   496  		return
   497  	}
   498  	return
   499  }
   500  
   501  // BreakGlassCredentialsListResponse is the response for the 'list' method.
   502  type BreakGlassCredentialsListResponse struct {
   503  	status int
   504  	header http.Header
   505  	err    *errors.Error
   506  	items  *BreakGlassCredentialList
   507  	page   *int
   508  	size   *int
   509  	total  *int
   510  }
   511  
   512  // Status returns the response status code.
   513  func (r *BreakGlassCredentialsListResponse) Status() int {
   514  	if r == nil {
   515  		return 0
   516  	}
   517  	return r.status
   518  }
   519  
   520  // Header returns header of the response.
   521  func (r *BreakGlassCredentialsListResponse) Header() http.Header {
   522  	if r == nil {
   523  		return nil
   524  	}
   525  	return r.header
   526  }
   527  
   528  // Error returns the response error.
   529  func (r *BreakGlassCredentialsListResponse) Error() *errors.Error {
   530  	if r == nil {
   531  		return nil
   532  	}
   533  	return r.err
   534  }
   535  
   536  // Items returns the value of the 'items' parameter.
   537  //
   538  // Retrieved list of break glass credentials.
   539  func (r *BreakGlassCredentialsListResponse) Items() *BreakGlassCredentialList {
   540  	if r == nil {
   541  		return nil
   542  	}
   543  	return r.items
   544  }
   545  
   546  // GetItems returns the value of the 'items' parameter and
   547  // a flag indicating if the parameter has a value.
   548  //
   549  // Retrieved list of break glass credentials.
   550  func (r *BreakGlassCredentialsListResponse) GetItems() (value *BreakGlassCredentialList, ok bool) {
   551  	ok = r != nil && r.items != nil
   552  	if ok {
   553  		value = r.items
   554  	}
   555  	return
   556  }
   557  
   558  // Page returns the value of the 'page' parameter.
   559  //
   560  // Index of the requested page, where one corresponds to the first page.
   561  func (r *BreakGlassCredentialsListResponse) Page() int {
   562  	if r != nil && r.page != nil {
   563  		return *r.page
   564  	}
   565  	return 0
   566  }
   567  
   568  // GetPage returns the value of the 'page' parameter and
   569  // a flag indicating if the parameter has a value.
   570  //
   571  // Index of the requested page, where one corresponds to the first page.
   572  func (r *BreakGlassCredentialsListResponse) GetPage() (value int, ok bool) {
   573  	ok = r != nil && r.page != nil
   574  	if ok {
   575  		value = *r.page
   576  	}
   577  	return
   578  }
   579  
   580  // Size returns the value of the 'size' parameter.
   581  //
   582  // Number of items contained in the returned page.
   583  func (r *BreakGlassCredentialsListResponse) Size() int {
   584  	if r != nil && r.size != nil {
   585  		return *r.size
   586  	}
   587  	return 0
   588  }
   589  
   590  // GetSize returns the value of the 'size' parameter and
   591  // a flag indicating if the parameter has a value.
   592  //
   593  // Number of items contained in the returned page.
   594  func (r *BreakGlassCredentialsListResponse) GetSize() (value int, ok bool) {
   595  	ok = r != nil && r.size != nil
   596  	if ok {
   597  		value = *r.size
   598  	}
   599  	return
   600  }
   601  
   602  // Total returns the value of the 'total' parameter.
   603  //
   604  // Total number of items of the collection.
   605  func (r *BreakGlassCredentialsListResponse) Total() int {
   606  	if r != nil && r.total != nil {
   607  		return *r.total
   608  	}
   609  	return 0
   610  }
   611  
   612  // GetTotal returns the value of the 'total' parameter and
   613  // a flag indicating if the parameter has a value.
   614  //
   615  // Total number of items of the collection.
   616  func (r *BreakGlassCredentialsListResponse) GetTotal() (value int, ok bool) {
   617  	ok = r != nil && r.total != nil
   618  	if ok {
   619  		value = *r.total
   620  	}
   621  	return
   622  }