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