github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/external_auth_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 v1alpha1 // github.com/openshift-online/ocm-sdk-go/arohcp/v1alpha1
    21  
    22  import (
    23  	"bufio"
    24  	"bytes"
    25  	"context"
    26  	"io"
    27  	"net/http"
    28  	"net/url"
    29  	"time"
    30  
    31  	"github.com/openshift-online/ocm-sdk-go/errors"
    32  	"github.com/openshift-online/ocm-sdk-go/helpers"
    33  )
    34  
    35  // ExternalAuthClient is the client of the 'external_auth' resource.
    36  //
    37  // Manages a specific external authentication provider for an ARO HCP cluster.
    38  type ExternalAuthClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewExternalAuthClient creates a new client for the 'external_auth'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewExternalAuthClient(transport http.RoundTripper, path string) *ExternalAuthClient {
    47  	return &ExternalAuthClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Delete creates a request for the 'async_delete' method.
    54  //
    55  // Deletes the external authentication provider.
    56  func (c *ExternalAuthClient) Delete() *ExternalAuthDeleteRequest {
    57  	return &ExternalAuthDeleteRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // Update creates a request for the 'async_update' method.
    64  //
    65  // Updates the external authentication provider.
    66  func (c *ExternalAuthClient) Update() *ExternalAuthUpdateRequest {
    67  	return &ExternalAuthUpdateRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // Get creates a request for the 'get' method.
    74  //
    75  // Retrieves the details of an external authentication provider.
    76  func (c *ExternalAuthClient) Get() *ExternalAuthGetRequest {
    77  	return &ExternalAuthGetRequest{
    78  		transport: c.transport,
    79  		path:      c.path,
    80  	}
    81  }
    82  
    83  // ExternalAuthPollRequest is the request for the Poll method.
    84  type ExternalAuthPollRequest struct {
    85  	request    *ExternalAuthGetRequest
    86  	interval   time.Duration
    87  	statuses   []int
    88  	predicates []func(interface{}) bool
    89  }
    90  
    91  // Parameter adds a query parameter to all the requests that will be used to retrieve the object.
    92  func (r *ExternalAuthPollRequest) Parameter(name string, value interface{}) *ExternalAuthPollRequest {
    93  	r.request.Parameter(name, value)
    94  	return r
    95  }
    96  
    97  // Header adds a request header to all the requests that will be used to retrieve the object.
    98  func (r *ExternalAuthPollRequest) Header(name string, value interface{}) *ExternalAuthPollRequest {
    99  	r.request.Header(name, value)
   100  	return r
   101  }
   102  
   103  // Interval sets the polling interval. This parameter is mandatory and must be greater than zero.
   104  func (r *ExternalAuthPollRequest) Interval(value time.Duration) *ExternalAuthPollRequest {
   105  	r.interval = value
   106  	return r
   107  }
   108  
   109  // Status set the expected status of the response. Multiple values can be set calling this method
   110  // multiple times. The response will be considered successful if the status is any of those values.
   111  func (r *ExternalAuthPollRequest) Status(value int) *ExternalAuthPollRequest {
   112  	r.statuses = append(r.statuses, value)
   113  	return r
   114  }
   115  
   116  // Predicate adds a predicate that the response should satisfy be considered successful. Multiple
   117  // predicates can be set calling this method multiple times. The response will be considered successful
   118  // if all the predicates are satisfied.
   119  func (r *ExternalAuthPollRequest) Predicate(value func(*ExternalAuthGetResponse) bool) *ExternalAuthPollRequest {
   120  	r.predicates = append(r.predicates, func(response interface{}) bool {
   121  		return value(response.(*ExternalAuthGetResponse))
   122  	})
   123  	return r
   124  }
   125  
   126  // StartContext starts the polling loop. Responses will be considered successful if the status is one of
   127  // the values specified with the Status method and if all the predicates specified with the Predicate
   128  // method return nil.
   129  //
   130  // The context must have a timeout or deadline, otherwise this method will immediately return an error.
   131  func (r *ExternalAuthPollRequest) StartContext(ctx context.Context) (response *ExternalAuthPollResponse, err error) {
   132  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   133  	if result != nil {
   134  		response = &ExternalAuthPollResponse{
   135  			response: result.(*ExternalAuthGetResponse),
   136  		}
   137  	}
   138  	return
   139  }
   140  
   141  // task adapts the types of the request/response types so that they can be used with the generic
   142  // polling function from the helpers package.
   143  func (r *ExternalAuthPollRequest) task(ctx context.Context) (status int, result interface{}, err error) {
   144  	response, err := r.request.SendContext(ctx)
   145  	if response != nil {
   146  		status = response.Status()
   147  		result = response
   148  	}
   149  	return
   150  }
   151  
   152  // ExternalAuthPollResponse is the response for the Poll method.
   153  type ExternalAuthPollResponse struct {
   154  	response *ExternalAuthGetResponse
   155  }
   156  
   157  // Status returns the response status code.
   158  func (r *ExternalAuthPollResponse) Status() int {
   159  	if r == nil {
   160  		return 0
   161  	}
   162  	return r.response.Status()
   163  }
   164  
   165  // Header returns header of the response.
   166  func (r *ExternalAuthPollResponse) Header() http.Header {
   167  	if r == nil {
   168  		return nil
   169  	}
   170  	return r.response.Header()
   171  }
   172  
   173  // Error returns the response error.
   174  func (r *ExternalAuthPollResponse) Error() *errors.Error {
   175  	if r == nil {
   176  		return nil
   177  	}
   178  	return r.response.Error()
   179  }
   180  
   181  // Body returns the value of the 'body' parameter.
   182  func (r *ExternalAuthPollResponse) Body() *ExternalAuth {
   183  	return r.response.Body()
   184  }
   185  
   186  // GetBody returns the value of the 'body' parameter and
   187  // a flag indicating if the parameter has a value.
   188  func (r *ExternalAuthPollResponse) GetBody() (value *ExternalAuth, ok bool) {
   189  	return r.response.GetBody()
   190  }
   191  
   192  // Poll creates a request to repeatedly retrieve the object till the response has one of a given set
   193  // of states and satisfies a set of predicates.
   194  func (c *ExternalAuthClient) Poll() *ExternalAuthPollRequest {
   195  	return &ExternalAuthPollRequest{
   196  		request: c.Get(),
   197  	}
   198  }
   199  
   200  // ExternalAuthDeleteRequest is the request for the 'async_delete' method.
   201  type ExternalAuthDeleteRequest struct {
   202  	transport http.RoundTripper
   203  	path      string
   204  	query     url.Values
   205  	header    http.Header
   206  }
   207  
   208  // Parameter adds a query parameter.
   209  func (r *ExternalAuthDeleteRequest) Parameter(name string, value interface{}) *ExternalAuthDeleteRequest {
   210  	helpers.AddValue(&r.query, name, value)
   211  	return r
   212  }
   213  
   214  // Header adds a request header.
   215  func (r *ExternalAuthDeleteRequest) Header(name string, value interface{}) *ExternalAuthDeleteRequest {
   216  	helpers.AddHeader(&r.header, name, value)
   217  	return r
   218  }
   219  
   220  // Impersonate wraps requests on behalf of another user.
   221  // Note: Services that do not support this feature may silently ignore this call.
   222  func (r *ExternalAuthDeleteRequest) Impersonate(user string) *ExternalAuthDeleteRequest {
   223  	helpers.AddImpersonationHeader(&r.header, user)
   224  	return r
   225  }
   226  
   227  // Send sends this request, waits for the response, and returns it.
   228  //
   229  // This is a potentially lengthy operation, as it requires network communication.
   230  // Consider using a context and the SendContext method.
   231  func (r *ExternalAuthDeleteRequest) Send() (result *ExternalAuthDeleteResponse, err error) {
   232  	return r.SendContext(context.Background())
   233  }
   234  
   235  // SendContext sends this request, waits for the response, and returns it.
   236  func (r *ExternalAuthDeleteRequest) SendContext(ctx context.Context) (result *ExternalAuthDeleteResponse, err error) {
   237  	query := helpers.CopyQuery(r.query)
   238  	header := helpers.CopyHeader(r.header)
   239  	uri := &url.URL{
   240  		Path:     r.path,
   241  		RawQuery: query.Encode(),
   242  	}
   243  	request := &http.Request{
   244  		Method: "DELETE",
   245  		URL:    uri,
   246  		Header: header,
   247  	}
   248  	if ctx != nil {
   249  		request = request.WithContext(ctx)
   250  	}
   251  	response, err := r.transport.RoundTrip(request)
   252  	if err != nil {
   253  		return
   254  	}
   255  	defer response.Body.Close()
   256  	result = &ExternalAuthDeleteResponse{}
   257  	result.status = response.StatusCode
   258  	result.header = response.Header
   259  	reader := bufio.NewReader(response.Body)
   260  	_, err = reader.Peek(1)
   261  	if err == io.EOF {
   262  		err = nil
   263  		return
   264  	}
   265  	if result.status >= 400 {
   266  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   267  		if err != nil {
   268  			return
   269  		}
   270  		err = result.err
   271  		return
   272  	}
   273  	return
   274  }
   275  
   276  // ExternalAuthDeleteResponse is the response for the 'async_delete' method.
   277  type ExternalAuthDeleteResponse struct {
   278  	status int
   279  	header http.Header
   280  	err    *errors.Error
   281  }
   282  
   283  // Status returns the response status code.
   284  func (r *ExternalAuthDeleteResponse) Status() int {
   285  	if r == nil {
   286  		return 0
   287  	}
   288  	return r.status
   289  }
   290  
   291  // Header returns header of the response.
   292  func (r *ExternalAuthDeleteResponse) Header() http.Header {
   293  	if r == nil {
   294  		return nil
   295  	}
   296  	return r.header
   297  }
   298  
   299  // Error returns the response error.
   300  func (r *ExternalAuthDeleteResponse) Error() *errors.Error {
   301  	if r == nil {
   302  		return nil
   303  	}
   304  	return r.err
   305  }
   306  
   307  // ExternalAuthUpdateRequest is the request for the 'async_update' method.
   308  type ExternalAuthUpdateRequest struct {
   309  	transport http.RoundTripper
   310  	path      string
   311  	query     url.Values
   312  	header    http.Header
   313  	body      *ExternalAuth
   314  }
   315  
   316  // Parameter adds a query parameter.
   317  func (r *ExternalAuthUpdateRequest) Parameter(name string, value interface{}) *ExternalAuthUpdateRequest {
   318  	helpers.AddValue(&r.query, name, value)
   319  	return r
   320  }
   321  
   322  // Header adds a request header.
   323  func (r *ExternalAuthUpdateRequest) Header(name string, value interface{}) *ExternalAuthUpdateRequest {
   324  	helpers.AddHeader(&r.header, name, value)
   325  	return r
   326  }
   327  
   328  // Impersonate wraps requests on behalf of another user.
   329  // Note: Services that do not support this feature may silently ignore this call.
   330  func (r *ExternalAuthUpdateRequest) Impersonate(user string) *ExternalAuthUpdateRequest {
   331  	helpers.AddImpersonationHeader(&r.header, user)
   332  	return r
   333  }
   334  
   335  // Body sets the value of the 'body' parameter.
   336  func (r *ExternalAuthUpdateRequest) Body(value *ExternalAuth) *ExternalAuthUpdateRequest {
   337  	r.body = value
   338  	return r
   339  }
   340  
   341  // Send sends this request, waits for the response, and returns it.
   342  //
   343  // This is a potentially lengthy operation, as it requires network communication.
   344  // Consider using a context and the SendContext method.
   345  func (r *ExternalAuthUpdateRequest) Send() (result *ExternalAuthUpdateResponse, err error) {
   346  	return r.SendContext(context.Background())
   347  }
   348  
   349  // SendContext sends this request, waits for the response, and returns it.
   350  func (r *ExternalAuthUpdateRequest) SendContext(ctx context.Context) (result *ExternalAuthUpdateResponse, err error) {
   351  	query := helpers.CopyQuery(r.query)
   352  	header := helpers.CopyHeader(r.header)
   353  	buffer := &bytes.Buffer{}
   354  	err = writeExternalAuthAsyncUpdateRequest(r, buffer)
   355  	if err != nil {
   356  		return
   357  	}
   358  	uri := &url.URL{
   359  		Path:     r.path,
   360  		RawQuery: query.Encode(),
   361  	}
   362  	request := &http.Request{
   363  		Method: "PATCH",
   364  		URL:    uri,
   365  		Header: header,
   366  		Body:   io.NopCloser(buffer),
   367  	}
   368  	if ctx != nil {
   369  		request = request.WithContext(ctx)
   370  	}
   371  	response, err := r.transport.RoundTrip(request)
   372  	if err != nil {
   373  		return
   374  	}
   375  	defer response.Body.Close()
   376  	result = &ExternalAuthUpdateResponse{}
   377  	result.status = response.StatusCode
   378  	result.header = response.Header
   379  	reader := bufio.NewReader(response.Body)
   380  	_, err = reader.Peek(1)
   381  	if err == io.EOF {
   382  		err = nil
   383  		return
   384  	}
   385  	if result.status >= 400 {
   386  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   387  		if err != nil {
   388  			return
   389  		}
   390  		err = result.err
   391  		return
   392  	}
   393  	err = readExternalAuthAsyncUpdateResponse(result, reader)
   394  	if err != nil {
   395  		return
   396  	}
   397  	return
   398  }
   399  
   400  // ExternalAuthUpdateResponse is the response for the 'async_update' method.
   401  type ExternalAuthUpdateResponse struct {
   402  	status int
   403  	header http.Header
   404  	err    *errors.Error
   405  	body   *ExternalAuth
   406  }
   407  
   408  // Status returns the response status code.
   409  func (r *ExternalAuthUpdateResponse) Status() int {
   410  	if r == nil {
   411  		return 0
   412  	}
   413  	return r.status
   414  }
   415  
   416  // Header returns header of the response.
   417  func (r *ExternalAuthUpdateResponse) Header() http.Header {
   418  	if r == nil {
   419  		return nil
   420  	}
   421  	return r.header
   422  }
   423  
   424  // Error returns the response error.
   425  func (r *ExternalAuthUpdateResponse) Error() *errors.Error {
   426  	if r == nil {
   427  		return nil
   428  	}
   429  	return r.err
   430  }
   431  
   432  // Body returns the value of the 'body' parameter.
   433  func (r *ExternalAuthUpdateResponse) Body() *ExternalAuth {
   434  	if r == nil {
   435  		return nil
   436  	}
   437  	return r.body
   438  }
   439  
   440  // GetBody returns the value of the 'body' parameter and
   441  // a flag indicating if the parameter has a value.
   442  func (r *ExternalAuthUpdateResponse) GetBody() (value *ExternalAuth, ok bool) {
   443  	ok = r != nil && r.body != nil
   444  	if ok {
   445  		value = r.body
   446  	}
   447  	return
   448  }
   449  
   450  // ExternalAuthGetRequest is the request for the 'get' method.
   451  type ExternalAuthGetRequest struct {
   452  	transport http.RoundTripper
   453  	path      string
   454  	query     url.Values
   455  	header    http.Header
   456  }
   457  
   458  // Parameter adds a query parameter.
   459  func (r *ExternalAuthGetRequest) Parameter(name string, value interface{}) *ExternalAuthGetRequest {
   460  	helpers.AddValue(&r.query, name, value)
   461  	return r
   462  }
   463  
   464  // Header adds a request header.
   465  func (r *ExternalAuthGetRequest) Header(name string, value interface{}) *ExternalAuthGetRequest {
   466  	helpers.AddHeader(&r.header, name, value)
   467  	return r
   468  }
   469  
   470  // Impersonate wraps requests on behalf of another user.
   471  // Note: Services that do not support this feature may silently ignore this call.
   472  func (r *ExternalAuthGetRequest) Impersonate(user string) *ExternalAuthGetRequest {
   473  	helpers.AddImpersonationHeader(&r.header, user)
   474  	return r
   475  }
   476  
   477  // Send sends this request, waits for the response, and returns it.
   478  //
   479  // This is a potentially lengthy operation, as it requires network communication.
   480  // Consider using a context and the SendContext method.
   481  func (r *ExternalAuthGetRequest) Send() (result *ExternalAuthGetResponse, err error) {
   482  	return r.SendContext(context.Background())
   483  }
   484  
   485  // SendContext sends this request, waits for the response, and returns it.
   486  func (r *ExternalAuthGetRequest) SendContext(ctx context.Context) (result *ExternalAuthGetResponse, err error) {
   487  	query := helpers.CopyQuery(r.query)
   488  	header := helpers.CopyHeader(r.header)
   489  	uri := &url.URL{
   490  		Path:     r.path,
   491  		RawQuery: query.Encode(),
   492  	}
   493  	request := &http.Request{
   494  		Method: "GET",
   495  		URL:    uri,
   496  		Header: header,
   497  	}
   498  	if ctx != nil {
   499  		request = request.WithContext(ctx)
   500  	}
   501  	response, err := r.transport.RoundTrip(request)
   502  	if err != nil {
   503  		return
   504  	}
   505  	defer response.Body.Close()
   506  	result = &ExternalAuthGetResponse{}
   507  	result.status = response.StatusCode
   508  	result.header = response.Header
   509  	reader := bufio.NewReader(response.Body)
   510  	_, err = reader.Peek(1)
   511  	if err == io.EOF {
   512  		err = nil
   513  		return
   514  	}
   515  	if result.status >= 400 {
   516  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   517  		if err != nil {
   518  			return
   519  		}
   520  		err = result.err
   521  		return
   522  	}
   523  	err = readExternalAuthGetResponse(result, reader)
   524  	if err != nil {
   525  		return
   526  	}
   527  	return
   528  }
   529  
   530  // ExternalAuthGetResponse is the response for the 'get' method.
   531  type ExternalAuthGetResponse struct {
   532  	status int
   533  	header http.Header
   534  	err    *errors.Error
   535  	body   *ExternalAuth
   536  }
   537  
   538  // Status returns the response status code.
   539  func (r *ExternalAuthGetResponse) Status() int {
   540  	if r == nil {
   541  		return 0
   542  	}
   543  	return r.status
   544  }
   545  
   546  // Header returns header of the response.
   547  func (r *ExternalAuthGetResponse) Header() http.Header {
   548  	if r == nil {
   549  		return nil
   550  	}
   551  	return r.header
   552  }
   553  
   554  // Error returns the response error.
   555  func (r *ExternalAuthGetResponse) Error() *errors.Error {
   556  	if r == nil {
   557  		return nil
   558  	}
   559  	return r.err
   560  }
   561  
   562  // Body returns the value of the 'body' parameter.
   563  func (r *ExternalAuthGetResponse) Body() *ExternalAuth {
   564  	if r == nil {
   565  		return nil
   566  	}
   567  	return r.body
   568  }
   569  
   570  // GetBody returns the value of the 'body' parameter and
   571  // a flag indicating if the parameter has a value.
   572  func (r *ExternalAuthGetResponse) GetBody() (value *ExternalAuth, ok bool) {
   573  	ok = r != nil && r.body != nil
   574  	if ok {
   575  		value = r.body
   576  	}
   577  	return
   578  }