github.com/openshift-online/ocm-sdk-go@v0.1.473/arohcp/v1alpha1/external_auth_config_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  	"context"
    25  	"io"
    26  	"net/http"
    27  	"net/url"
    28  	"path"
    29  	"time"
    30  
    31  	"github.com/openshift-online/ocm-sdk-go/errors"
    32  	"github.com/openshift-online/ocm-sdk-go/helpers"
    33  )
    34  
    35  // ExternalAuthConfigClient is the client of the 'external_auth_config' resource.
    36  //
    37  // Manages the external authentication configuration for an ARO HCP cluster.
    38  type ExternalAuthConfigClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewExternalAuthConfigClient creates a new client for the 'external_auth_config'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewExternalAuthConfigClient(transport http.RoundTripper, path string) *ExternalAuthConfigClient {
    47  	return &ExternalAuthConfigClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Get creates a request for the 'get' method.
    54  func (c *ExternalAuthConfigClient) Get() *ExternalAuthConfigGetRequest {
    55  	return &ExternalAuthConfigGetRequest{
    56  		transport: c.transport,
    57  		path:      c.path,
    58  	}
    59  }
    60  
    61  // ExternalAuths returns the target 'external_auths' resource.
    62  //
    63  // Reference to the resource that manages the collection of ExternalAuths resources.
    64  func (c *ExternalAuthConfigClient) ExternalAuths() *ExternalAuthsClient {
    65  	return NewExternalAuthsClient(
    66  		c.transport,
    67  		path.Join(c.path, "external_auths"),
    68  	)
    69  }
    70  
    71  // ExternalAuthConfigPollRequest is the request for the Poll method.
    72  type ExternalAuthConfigPollRequest struct {
    73  	request    *ExternalAuthConfigGetRequest
    74  	interval   time.Duration
    75  	statuses   []int
    76  	predicates []func(interface{}) bool
    77  }
    78  
    79  // Parameter adds a query parameter to all the requests that will be used to retrieve the object.
    80  func (r *ExternalAuthConfigPollRequest) Parameter(name string, value interface{}) *ExternalAuthConfigPollRequest {
    81  	r.request.Parameter(name, value)
    82  	return r
    83  }
    84  
    85  // Header adds a request header to all the requests that will be used to retrieve the object.
    86  func (r *ExternalAuthConfigPollRequest) Header(name string, value interface{}) *ExternalAuthConfigPollRequest {
    87  	r.request.Header(name, value)
    88  	return r
    89  }
    90  
    91  // Interval sets the polling interval. This parameter is mandatory and must be greater than zero.
    92  func (r *ExternalAuthConfigPollRequest) Interval(value time.Duration) *ExternalAuthConfigPollRequest {
    93  	r.interval = value
    94  	return r
    95  }
    96  
    97  // Status set the expected status of the response. Multiple values can be set calling this method
    98  // multiple times. The response will be considered successful if the status is any of those values.
    99  func (r *ExternalAuthConfigPollRequest) Status(value int) *ExternalAuthConfigPollRequest {
   100  	r.statuses = append(r.statuses, value)
   101  	return r
   102  }
   103  
   104  // Predicate adds a predicate that the response should satisfy be considered successful. Multiple
   105  // predicates can be set calling this method multiple times. The response will be considered successful
   106  // if all the predicates are satisfied.
   107  func (r *ExternalAuthConfigPollRequest) Predicate(value func(*ExternalAuthConfigGetResponse) bool) *ExternalAuthConfigPollRequest {
   108  	r.predicates = append(r.predicates, func(response interface{}) bool {
   109  		return value(response.(*ExternalAuthConfigGetResponse))
   110  	})
   111  	return r
   112  }
   113  
   114  // StartContext starts the polling loop. Responses will be considered successful if the status is one of
   115  // the values specified with the Status method and if all the predicates specified with the Predicate
   116  // method return nil.
   117  //
   118  // The context must have a timeout or deadline, otherwise this method will immediately return an error.
   119  func (r *ExternalAuthConfigPollRequest) StartContext(ctx context.Context) (response *ExternalAuthConfigPollResponse, err error) {
   120  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   121  	if result != nil {
   122  		response = &ExternalAuthConfigPollResponse{
   123  			response: result.(*ExternalAuthConfigGetResponse),
   124  		}
   125  	}
   126  	return
   127  }
   128  
   129  // task adapts the types of the request/response types so that they can be used with the generic
   130  // polling function from the helpers package.
   131  func (r *ExternalAuthConfigPollRequest) task(ctx context.Context) (status int, result interface{}, err error) {
   132  	response, err := r.request.SendContext(ctx)
   133  	if response != nil {
   134  		status = response.Status()
   135  		result = response
   136  	}
   137  	return
   138  }
   139  
   140  // ExternalAuthConfigPollResponse is the response for the Poll method.
   141  type ExternalAuthConfigPollResponse struct {
   142  	response *ExternalAuthConfigGetResponse
   143  }
   144  
   145  // Status returns the response status code.
   146  func (r *ExternalAuthConfigPollResponse) Status() int {
   147  	if r == nil {
   148  		return 0
   149  	}
   150  	return r.response.Status()
   151  }
   152  
   153  // Header returns header of the response.
   154  func (r *ExternalAuthConfigPollResponse) Header() http.Header {
   155  	if r == nil {
   156  		return nil
   157  	}
   158  	return r.response.Header()
   159  }
   160  
   161  // Error returns the response error.
   162  func (r *ExternalAuthConfigPollResponse) Error() *errors.Error {
   163  	if r == nil {
   164  		return nil
   165  	}
   166  	return r.response.Error()
   167  }
   168  
   169  // Body returns the value of the 'body' parameter.
   170  func (r *ExternalAuthConfigPollResponse) Body() *ExternalAuthConfig {
   171  	return r.response.Body()
   172  }
   173  
   174  // GetBody returns the value of the 'body' parameter and
   175  // a flag indicating if the parameter has a value.
   176  func (r *ExternalAuthConfigPollResponse) GetBody() (value *ExternalAuthConfig, ok bool) {
   177  	return r.response.GetBody()
   178  }
   179  
   180  // Poll creates a request to repeatedly retrieve the object till the response has one of a given set
   181  // of states and satisfies a set of predicates.
   182  func (c *ExternalAuthConfigClient) Poll() *ExternalAuthConfigPollRequest {
   183  	return &ExternalAuthConfigPollRequest{
   184  		request: c.Get(),
   185  	}
   186  }
   187  
   188  // ExternalAuthConfigGetRequest is the request for the 'get' method.
   189  type ExternalAuthConfigGetRequest struct {
   190  	transport http.RoundTripper
   191  	path      string
   192  	query     url.Values
   193  	header    http.Header
   194  }
   195  
   196  // Parameter adds a query parameter.
   197  func (r *ExternalAuthConfigGetRequest) Parameter(name string, value interface{}) *ExternalAuthConfigGetRequest {
   198  	helpers.AddValue(&r.query, name, value)
   199  	return r
   200  }
   201  
   202  // Header adds a request header.
   203  func (r *ExternalAuthConfigGetRequest) Header(name string, value interface{}) *ExternalAuthConfigGetRequest {
   204  	helpers.AddHeader(&r.header, name, value)
   205  	return r
   206  }
   207  
   208  // Impersonate wraps requests on behalf of another user.
   209  // Note: Services that do not support this feature may silently ignore this call.
   210  func (r *ExternalAuthConfigGetRequest) Impersonate(user string) *ExternalAuthConfigGetRequest {
   211  	helpers.AddImpersonationHeader(&r.header, user)
   212  	return r
   213  }
   214  
   215  // Send sends this request, waits for the response, and returns it.
   216  //
   217  // This is a potentially lengthy operation, as it requires network communication.
   218  // Consider using a context and the SendContext method.
   219  func (r *ExternalAuthConfigGetRequest) Send() (result *ExternalAuthConfigGetResponse, err error) {
   220  	return r.SendContext(context.Background())
   221  }
   222  
   223  // SendContext sends this request, waits for the response, and returns it.
   224  func (r *ExternalAuthConfigGetRequest) SendContext(ctx context.Context) (result *ExternalAuthConfigGetResponse, err error) {
   225  	query := helpers.CopyQuery(r.query)
   226  	header := helpers.CopyHeader(r.header)
   227  	uri := &url.URL{
   228  		Path:     r.path,
   229  		RawQuery: query.Encode(),
   230  	}
   231  	request := &http.Request{
   232  		Method: "GET",
   233  		URL:    uri,
   234  		Header: header,
   235  	}
   236  	if ctx != nil {
   237  		request = request.WithContext(ctx)
   238  	}
   239  	response, err := r.transport.RoundTrip(request)
   240  	if err != nil {
   241  		return
   242  	}
   243  	defer response.Body.Close()
   244  	result = &ExternalAuthConfigGetResponse{}
   245  	result.status = response.StatusCode
   246  	result.header = response.Header
   247  	reader := bufio.NewReader(response.Body)
   248  	_, err = reader.Peek(1)
   249  	if err == io.EOF {
   250  		err = nil
   251  		return
   252  	}
   253  	if result.status >= 400 {
   254  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   255  		if err != nil {
   256  			return
   257  		}
   258  		err = result.err
   259  		return
   260  	}
   261  	err = readExternalAuthConfigGetResponse(result, reader)
   262  	if err != nil {
   263  		return
   264  	}
   265  	return
   266  }
   267  
   268  // ExternalAuthConfigGetResponse is the response for the 'get' method.
   269  type ExternalAuthConfigGetResponse struct {
   270  	status int
   271  	header http.Header
   272  	err    *errors.Error
   273  	body   *ExternalAuthConfig
   274  }
   275  
   276  // Status returns the response status code.
   277  func (r *ExternalAuthConfigGetResponse) Status() int {
   278  	if r == nil {
   279  		return 0
   280  	}
   281  	return r.status
   282  }
   283  
   284  // Header returns header of the response.
   285  func (r *ExternalAuthConfigGetResponse) Header() http.Header {
   286  	if r == nil {
   287  		return nil
   288  	}
   289  	return r.header
   290  }
   291  
   292  // Error returns the response error.
   293  func (r *ExternalAuthConfigGetResponse) Error() *errors.Error {
   294  	if r == nil {
   295  		return nil
   296  	}
   297  	return r.err
   298  }
   299  
   300  // Body returns the value of the 'body' parameter.
   301  func (r *ExternalAuthConfigGetResponse) Body() *ExternalAuthConfig {
   302  	if r == nil {
   303  		return nil
   304  	}
   305  	return r.body
   306  }
   307  
   308  // GetBody returns the value of the 'body' parameter and
   309  // a flag indicating if the parameter has a value.
   310  func (r *ExternalAuthConfigGetResponse) GetBody() (value *ExternalAuthConfig, ok bool) {
   311  	ok = r != nil && r.body != nil
   312  	if ok {
   313  		value = r.body
   314  	}
   315  	return
   316  }