github.com/openshift-online/ocm-sdk-go@v0.1.473/addonsmgmt/v1/addon_version_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/addonsmgmt/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  // AddonVersionClient is the client of the 'addon_version' resource.
    36  //
    37  // Manages a specific addon version.
    38  type AddonVersionClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewAddonVersionClient creates a new client for the 'addon_version'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewAddonVersionClient(transport http.RoundTripper, path string) *AddonVersionClient {
    47  	return &AddonVersionClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Delete creates a request for the 'delete' method.
    54  //
    55  // Deletes the addon version.
    56  func (c *AddonVersionClient) Delete() *AddonVersionDeleteRequest {
    57  	return &AddonVersionDeleteRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // Get creates a request for the 'get' method.
    64  //
    65  // Retrieves the details of the addon version.
    66  func (c *AddonVersionClient) Get() *AddonVersionGetRequest {
    67  	return &AddonVersionGetRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // Update creates a request for the 'update' method.
    74  //
    75  // Updates the addon version.
    76  func (c *AddonVersionClient) Update() *AddonVersionUpdateRequest {
    77  	return &AddonVersionUpdateRequest{
    78  		transport: c.transport,
    79  		path:      c.path,
    80  	}
    81  }
    82  
    83  // AddonVersionPollRequest is the request for the Poll method.
    84  type AddonVersionPollRequest struct {
    85  	request    *AddonVersionGetRequest
    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 *AddonVersionPollRequest) Parameter(name string, value interface{}) *AddonVersionPollRequest {
    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 *AddonVersionPollRequest) Header(name string, value interface{}) *AddonVersionPollRequest {
    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 *AddonVersionPollRequest) Interval(value time.Duration) *AddonVersionPollRequest {
   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 *AddonVersionPollRequest) Status(value int) *AddonVersionPollRequest {
   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 *AddonVersionPollRequest) Predicate(value func(*AddonVersionGetResponse) bool) *AddonVersionPollRequest {
   120  	r.predicates = append(r.predicates, func(response interface{}) bool {
   121  		return value(response.(*AddonVersionGetResponse))
   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 *AddonVersionPollRequest) StartContext(ctx context.Context) (response *AddonVersionPollResponse, err error) {
   132  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   133  	if result != nil {
   134  		response = &AddonVersionPollResponse{
   135  			response: result.(*AddonVersionGetResponse),
   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 *AddonVersionPollRequest) 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  // AddonVersionPollResponse is the response for the Poll method.
   153  type AddonVersionPollResponse struct {
   154  	response *AddonVersionGetResponse
   155  }
   156  
   157  // Status returns the response status code.
   158  func (r *AddonVersionPollResponse) 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 *AddonVersionPollResponse) 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 *AddonVersionPollResponse) 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 *AddonVersionPollResponse) Body() *AddonVersion {
   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 *AddonVersionPollResponse) GetBody() (value *AddonVersion, 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 *AddonVersionClient) Poll() *AddonVersionPollRequest {
   195  	return &AddonVersionPollRequest{
   196  		request: c.Get(),
   197  	}
   198  }
   199  
   200  // AddonVersionDeleteRequest is the request for the 'delete' method.
   201  type AddonVersionDeleteRequest 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 *AddonVersionDeleteRequest) Parameter(name string, value interface{}) *AddonVersionDeleteRequest {
   210  	helpers.AddValue(&r.query, name, value)
   211  	return r
   212  }
   213  
   214  // Header adds a request header.
   215  func (r *AddonVersionDeleteRequest) Header(name string, value interface{}) *AddonVersionDeleteRequest {
   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 *AddonVersionDeleteRequest) Impersonate(user string) *AddonVersionDeleteRequest {
   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 *AddonVersionDeleteRequest) Send() (result *AddonVersionDeleteResponse, 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 *AddonVersionDeleteRequest) SendContext(ctx context.Context) (result *AddonVersionDeleteResponse, 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 = &AddonVersionDeleteResponse{}
   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  // AddonVersionDeleteResponse is the response for the 'delete' method.
   277  type AddonVersionDeleteResponse struct {
   278  	status int
   279  	header http.Header
   280  	err    *errors.Error
   281  }
   282  
   283  // Status returns the response status code.
   284  func (r *AddonVersionDeleteResponse) 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 *AddonVersionDeleteResponse) 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 *AddonVersionDeleteResponse) Error() *errors.Error {
   301  	if r == nil {
   302  		return nil
   303  	}
   304  	return r.err
   305  }
   306  
   307  // AddonVersionGetRequest is the request for the 'get' method.
   308  type AddonVersionGetRequest struct {
   309  	transport http.RoundTripper
   310  	path      string
   311  	query     url.Values
   312  	header    http.Header
   313  }
   314  
   315  // Parameter adds a query parameter.
   316  func (r *AddonVersionGetRequest) Parameter(name string, value interface{}) *AddonVersionGetRequest {
   317  	helpers.AddValue(&r.query, name, value)
   318  	return r
   319  }
   320  
   321  // Header adds a request header.
   322  func (r *AddonVersionGetRequest) Header(name string, value interface{}) *AddonVersionGetRequest {
   323  	helpers.AddHeader(&r.header, name, value)
   324  	return r
   325  }
   326  
   327  // Impersonate wraps requests on behalf of another user.
   328  // Note: Services that do not support this feature may silently ignore this call.
   329  func (r *AddonVersionGetRequest) Impersonate(user string) *AddonVersionGetRequest {
   330  	helpers.AddImpersonationHeader(&r.header, user)
   331  	return r
   332  }
   333  
   334  // Send sends this request, waits for the response, and returns it.
   335  //
   336  // This is a potentially lengthy operation, as it requires network communication.
   337  // Consider using a context and the SendContext method.
   338  func (r *AddonVersionGetRequest) Send() (result *AddonVersionGetResponse, err error) {
   339  	return r.SendContext(context.Background())
   340  }
   341  
   342  // SendContext sends this request, waits for the response, and returns it.
   343  func (r *AddonVersionGetRequest) SendContext(ctx context.Context) (result *AddonVersionGetResponse, err error) {
   344  	query := helpers.CopyQuery(r.query)
   345  	header := helpers.CopyHeader(r.header)
   346  	uri := &url.URL{
   347  		Path:     r.path,
   348  		RawQuery: query.Encode(),
   349  	}
   350  	request := &http.Request{
   351  		Method: "GET",
   352  		URL:    uri,
   353  		Header: header,
   354  	}
   355  	if ctx != nil {
   356  		request = request.WithContext(ctx)
   357  	}
   358  	response, err := r.transport.RoundTrip(request)
   359  	if err != nil {
   360  		return
   361  	}
   362  	defer response.Body.Close()
   363  	result = &AddonVersionGetResponse{}
   364  	result.status = response.StatusCode
   365  	result.header = response.Header
   366  	reader := bufio.NewReader(response.Body)
   367  	_, err = reader.Peek(1)
   368  	if err == io.EOF {
   369  		err = nil
   370  		return
   371  	}
   372  	if result.status >= 400 {
   373  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   374  		if err != nil {
   375  			return
   376  		}
   377  		err = result.err
   378  		return
   379  	}
   380  	err = readAddonVersionGetResponse(result, reader)
   381  	if err != nil {
   382  		return
   383  	}
   384  	return
   385  }
   386  
   387  // AddonVersionGetResponse is the response for the 'get' method.
   388  type AddonVersionGetResponse struct {
   389  	status int
   390  	header http.Header
   391  	err    *errors.Error
   392  	body   *AddonVersion
   393  }
   394  
   395  // Status returns the response status code.
   396  func (r *AddonVersionGetResponse) Status() int {
   397  	if r == nil {
   398  		return 0
   399  	}
   400  	return r.status
   401  }
   402  
   403  // Header returns header of the response.
   404  func (r *AddonVersionGetResponse) Header() http.Header {
   405  	if r == nil {
   406  		return nil
   407  	}
   408  	return r.header
   409  }
   410  
   411  // Error returns the response error.
   412  func (r *AddonVersionGetResponse) Error() *errors.Error {
   413  	if r == nil {
   414  		return nil
   415  	}
   416  	return r.err
   417  }
   418  
   419  // Body returns the value of the 'body' parameter.
   420  func (r *AddonVersionGetResponse) Body() *AddonVersion {
   421  	if r == nil {
   422  		return nil
   423  	}
   424  	return r.body
   425  }
   426  
   427  // GetBody returns the value of the 'body' parameter and
   428  // a flag indicating if the parameter has a value.
   429  func (r *AddonVersionGetResponse) GetBody() (value *AddonVersion, ok bool) {
   430  	ok = r != nil && r.body != nil
   431  	if ok {
   432  		value = r.body
   433  	}
   434  	return
   435  }
   436  
   437  // AddonVersionUpdateRequest is the request for the 'update' method.
   438  type AddonVersionUpdateRequest struct {
   439  	transport http.RoundTripper
   440  	path      string
   441  	query     url.Values
   442  	header    http.Header
   443  	body      *AddonVersion
   444  	dryRun    *bool
   445  }
   446  
   447  // Parameter adds a query parameter.
   448  func (r *AddonVersionUpdateRequest) Parameter(name string, value interface{}) *AddonVersionUpdateRequest {
   449  	helpers.AddValue(&r.query, name, value)
   450  	return r
   451  }
   452  
   453  // Header adds a request header.
   454  func (r *AddonVersionUpdateRequest) Header(name string, value interface{}) *AddonVersionUpdateRequest {
   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 *AddonVersionUpdateRequest) Impersonate(user string) *AddonVersionUpdateRequest {
   462  	helpers.AddImpersonationHeader(&r.header, user)
   463  	return r
   464  }
   465  
   466  // Body sets the value of the 'body' parameter.
   467  func (r *AddonVersionUpdateRequest) Body(value *AddonVersion) *AddonVersionUpdateRequest {
   468  	r.body = value
   469  	return r
   470  }
   471  
   472  // DryRun sets the value of the 'dry_run' parameter.
   473  //
   474  // DryRun indicates the request body will not be persisted when dryRun=true.
   475  func (r *AddonVersionUpdateRequest) DryRun(value bool) *AddonVersionUpdateRequest {
   476  	r.dryRun = &value
   477  	return r
   478  }
   479  
   480  // Send sends this request, waits for the response, and returns it.
   481  //
   482  // This is a potentially lengthy operation, as it requires network communication.
   483  // Consider using a context and the SendContext method.
   484  func (r *AddonVersionUpdateRequest) Send() (result *AddonVersionUpdateResponse, err error) {
   485  	return r.SendContext(context.Background())
   486  }
   487  
   488  // SendContext sends this request, waits for the response, and returns it.
   489  func (r *AddonVersionUpdateRequest) SendContext(ctx context.Context) (result *AddonVersionUpdateResponse, err error) {
   490  	query := helpers.CopyQuery(r.query)
   491  	if r.dryRun != nil {
   492  		helpers.AddValue(&query, "dryRun", *r.dryRun)
   493  	}
   494  	header := helpers.CopyHeader(r.header)
   495  	buffer := &bytes.Buffer{}
   496  	err = writeAddonVersionUpdateRequest(r, buffer)
   497  	if err != nil {
   498  		return
   499  	}
   500  	uri := &url.URL{
   501  		Path:     r.path,
   502  		RawQuery: query.Encode(),
   503  	}
   504  	request := &http.Request{
   505  		Method: "PATCH",
   506  		URL:    uri,
   507  		Header: header,
   508  		Body:   io.NopCloser(buffer),
   509  	}
   510  	if ctx != nil {
   511  		request = request.WithContext(ctx)
   512  	}
   513  	response, err := r.transport.RoundTrip(request)
   514  	if err != nil {
   515  		return
   516  	}
   517  	defer response.Body.Close()
   518  	result = &AddonVersionUpdateResponse{}
   519  	result.status = response.StatusCode
   520  	result.header = response.Header
   521  	reader := bufio.NewReader(response.Body)
   522  	_, err = reader.Peek(1)
   523  	if err == io.EOF {
   524  		err = nil
   525  		return
   526  	}
   527  	if result.status >= 400 {
   528  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   529  		if err != nil {
   530  			return
   531  		}
   532  		err = result.err
   533  		return
   534  	}
   535  	err = readAddonVersionUpdateResponse(result, reader)
   536  	if err != nil {
   537  		return
   538  	}
   539  	return
   540  }
   541  
   542  // AddonVersionUpdateResponse is the response for the 'update' method.
   543  type AddonVersionUpdateResponse struct {
   544  	status int
   545  	header http.Header
   546  	err    *errors.Error
   547  	body   *AddonVersion
   548  }
   549  
   550  // Status returns the response status code.
   551  func (r *AddonVersionUpdateResponse) Status() int {
   552  	if r == nil {
   553  		return 0
   554  	}
   555  	return r.status
   556  }
   557  
   558  // Header returns header of the response.
   559  func (r *AddonVersionUpdateResponse) Header() http.Header {
   560  	if r == nil {
   561  		return nil
   562  	}
   563  	return r.header
   564  }
   565  
   566  // Error returns the response error.
   567  func (r *AddonVersionUpdateResponse) Error() *errors.Error {
   568  	if r == nil {
   569  		return nil
   570  	}
   571  	return r.err
   572  }
   573  
   574  // Body returns the value of the 'body' parameter.
   575  func (r *AddonVersionUpdateResponse) Body() *AddonVersion {
   576  	if r == nil {
   577  		return nil
   578  	}
   579  	return r.body
   580  }
   581  
   582  // GetBody returns the value of the 'body' parameter and
   583  // a flag indicating if the parameter has a value.
   584  func (r *AddonVersionUpdateResponse) GetBody() (value *AddonVersion, ok bool) {
   585  	ok = r != nil && r.body != nil
   586  	if ok {
   587  		value = r.body
   588  	}
   589  	return
   590  }