github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/delete_protection_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  // DeleteProtectionClient is the client of the 'delete_protection' resource.
    36  //
    37  // Manages delete protection specific parts for a specific cluster.
    38  type DeleteProtectionClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewDeleteProtectionClient creates a new client for the 'delete_protection'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewDeleteProtectionClient(transport http.RoundTripper, path string) *DeleteProtectionClient {
    47  	return &DeleteProtectionClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Get creates a request for the 'get' method.
    54  func (c *DeleteProtectionClient) Get() *DeleteProtectionGetRequest {
    55  	return &DeleteProtectionGetRequest{
    56  		transport: c.transport,
    57  		path:      c.path,
    58  	}
    59  }
    60  
    61  // Update creates a request for the 'update' method.
    62  func (c *DeleteProtectionClient) Update() *DeleteProtectionUpdateRequest {
    63  	return &DeleteProtectionUpdateRequest{
    64  		transport: c.transport,
    65  		path:      c.path,
    66  	}
    67  }
    68  
    69  // DeleteProtectionPollRequest is the request for the Poll method.
    70  type DeleteProtectionPollRequest struct {
    71  	request    *DeleteProtectionGetRequest
    72  	interval   time.Duration
    73  	statuses   []int
    74  	predicates []func(interface{}) bool
    75  }
    76  
    77  // Parameter adds a query parameter to all the requests that will be used to retrieve the object.
    78  func (r *DeleteProtectionPollRequest) Parameter(name string, value interface{}) *DeleteProtectionPollRequest {
    79  	r.request.Parameter(name, value)
    80  	return r
    81  }
    82  
    83  // Header adds a request header to all the requests that will be used to retrieve the object.
    84  func (r *DeleteProtectionPollRequest) Header(name string, value interface{}) *DeleteProtectionPollRequest {
    85  	r.request.Header(name, value)
    86  	return r
    87  }
    88  
    89  // Interval sets the polling interval. This parameter is mandatory and must be greater than zero.
    90  func (r *DeleteProtectionPollRequest) Interval(value time.Duration) *DeleteProtectionPollRequest {
    91  	r.interval = value
    92  	return r
    93  }
    94  
    95  // Status set the expected status of the response. Multiple values can be set calling this method
    96  // multiple times. The response will be considered successful if the status is any of those values.
    97  func (r *DeleteProtectionPollRequest) Status(value int) *DeleteProtectionPollRequest {
    98  	r.statuses = append(r.statuses, value)
    99  	return r
   100  }
   101  
   102  // Predicate adds a predicate that the response should satisfy be considered successful. Multiple
   103  // predicates can be set calling this method multiple times. The response will be considered successful
   104  // if all the predicates are satisfied.
   105  func (r *DeleteProtectionPollRequest) Predicate(value func(*DeleteProtectionGetResponse) bool) *DeleteProtectionPollRequest {
   106  	r.predicates = append(r.predicates, func(response interface{}) bool {
   107  		return value(response.(*DeleteProtectionGetResponse))
   108  	})
   109  	return r
   110  }
   111  
   112  // StartContext starts the polling loop. Responses will be considered successful if the status is one of
   113  // the values specified with the Status method and if all the predicates specified with the Predicate
   114  // method return nil.
   115  //
   116  // The context must have a timeout or deadline, otherwise this method will immediately return an error.
   117  func (r *DeleteProtectionPollRequest) StartContext(ctx context.Context) (response *DeleteProtectionPollResponse, err error) {
   118  	result, err := helpers.PollContext(ctx, r.interval, r.statuses, r.predicates, r.task)
   119  	if result != nil {
   120  		response = &DeleteProtectionPollResponse{
   121  			response: result.(*DeleteProtectionGetResponse),
   122  		}
   123  	}
   124  	return
   125  }
   126  
   127  // task adapts the types of the request/response types so that they can be used with the generic
   128  // polling function from the helpers package.
   129  func (r *DeleteProtectionPollRequest) task(ctx context.Context) (status int, result interface{}, err error) {
   130  	response, err := r.request.SendContext(ctx)
   131  	if response != nil {
   132  		status = response.Status()
   133  		result = response
   134  	}
   135  	return
   136  }
   137  
   138  // DeleteProtectionPollResponse is the response for the Poll method.
   139  type DeleteProtectionPollResponse struct {
   140  	response *DeleteProtectionGetResponse
   141  }
   142  
   143  // Status returns the response status code.
   144  func (r *DeleteProtectionPollResponse) Status() int {
   145  	if r == nil {
   146  		return 0
   147  	}
   148  	return r.response.Status()
   149  }
   150  
   151  // Header returns header of the response.
   152  func (r *DeleteProtectionPollResponse) Header() http.Header {
   153  	if r == nil {
   154  		return nil
   155  	}
   156  	return r.response.Header()
   157  }
   158  
   159  // Error returns the response error.
   160  func (r *DeleteProtectionPollResponse) Error() *errors.Error {
   161  	if r == nil {
   162  		return nil
   163  	}
   164  	return r.response.Error()
   165  }
   166  
   167  // Body returns the value of the 'body' parameter.
   168  func (r *DeleteProtectionPollResponse) Body() *DeleteProtection {
   169  	return r.response.Body()
   170  }
   171  
   172  // GetBody returns the value of the 'body' parameter and
   173  // a flag indicating if the parameter has a value.
   174  func (r *DeleteProtectionPollResponse) GetBody() (value *DeleteProtection, ok bool) {
   175  	return r.response.GetBody()
   176  }
   177  
   178  // Poll creates a request to repeatedly retrieve the object till the response has one of a given set
   179  // of states and satisfies a set of predicates.
   180  func (c *DeleteProtectionClient) Poll() *DeleteProtectionPollRequest {
   181  	return &DeleteProtectionPollRequest{
   182  		request: c.Get(),
   183  	}
   184  }
   185  
   186  // DeleteProtectionGetRequest is the request for the 'get' method.
   187  type DeleteProtectionGetRequest struct {
   188  	transport http.RoundTripper
   189  	path      string
   190  	query     url.Values
   191  	header    http.Header
   192  }
   193  
   194  // Parameter adds a query parameter.
   195  func (r *DeleteProtectionGetRequest) Parameter(name string, value interface{}) *DeleteProtectionGetRequest {
   196  	helpers.AddValue(&r.query, name, value)
   197  	return r
   198  }
   199  
   200  // Header adds a request header.
   201  func (r *DeleteProtectionGetRequest) Header(name string, value interface{}) *DeleteProtectionGetRequest {
   202  	helpers.AddHeader(&r.header, name, value)
   203  	return r
   204  }
   205  
   206  // Impersonate wraps requests on behalf of another user.
   207  // Note: Services that do not support this feature may silently ignore this call.
   208  func (r *DeleteProtectionGetRequest) Impersonate(user string) *DeleteProtectionGetRequest {
   209  	helpers.AddImpersonationHeader(&r.header, user)
   210  	return r
   211  }
   212  
   213  // Send sends this request, waits for the response, and returns it.
   214  //
   215  // This is a potentially lengthy operation, as it requires network communication.
   216  // Consider using a context and the SendContext method.
   217  func (r *DeleteProtectionGetRequest) Send() (result *DeleteProtectionGetResponse, err error) {
   218  	return r.SendContext(context.Background())
   219  }
   220  
   221  // SendContext sends this request, waits for the response, and returns it.
   222  func (r *DeleteProtectionGetRequest) SendContext(ctx context.Context) (result *DeleteProtectionGetResponse, err error) {
   223  	query := helpers.CopyQuery(r.query)
   224  	header := helpers.CopyHeader(r.header)
   225  	uri := &url.URL{
   226  		Path:     r.path,
   227  		RawQuery: query.Encode(),
   228  	}
   229  	request := &http.Request{
   230  		Method: "GET",
   231  		URL:    uri,
   232  		Header: header,
   233  	}
   234  	if ctx != nil {
   235  		request = request.WithContext(ctx)
   236  	}
   237  	response, err := r.transport.RoundTrip(request)
   238  	if err != nil {
   239  		return
   240  	}
   241  	defer response.Body.Close()
   242  	result = &DeleteProtectionGetResponse{}
   243  	result.status = response.StatusCode
   244  	result.header = response.Header
   245  	reader := bufio.NewReader(response.Body)
   246  	_, err = reader.Peek(1)
   247  	if err == io.EOF {
   248  		err = nil
   249  		return
   250  	}
   251  	if result.status >= 400 {
   252  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   253  		if err != nil {
   254  			return
   255  		}
   256  		err = result.err
   257  		return
   258  	}
   259  	err = readDeleteProtectionGetResponse(result, reader)
   260  	if err != nil {
   261  		return
   262  	}
   263  	return
   264  }
   265  
   266  // DeleteProtectionGetResponse is the response for the 'get' method.
   267  type DeleteProtectionGetResponse struct {
   268  	status int
   269  	header http.Header
   270  	err    *errors.Error
   271  	body   *DeleteProtection
   272  }
   273  
   274  // Status returns the response status code.
   275  func (r *DeleteProtectionGetResponse) Status() int {
   276  	if r == nil {
   277  		return 0
   278  	}
   279  	return r.status
   280  }
   281  
   282  // Header returns header of the response.
   283  func (r *DeleteProtectionGetResponse) Header() http.Header {
   284  	if r == nil {
   285  		return nil
   286  	}
   287  	return r.header
   288  }
   289  
   290  // Error returns the response error.
   291  func (r *DeleteProtectionGetResponse) Error() *errors.Error {
   292  	if r == nil {
   293  		return nil
   294  	}
   295  	return r.err
   296  }
   297  
   298  // Body returns the value of the 'body' parameter.
   299  func (r *DeleteProtectionGetResponse) Body() *DeleteProtection {
   300  	if r == nil {
   301  		return nil
   302  	}
   303  	return r.body
   304  }
   305  
   306  // GetBody returns the value of the 'body' parameter and
   307  // a flag indicating if the parameter has a value.
   308  func (r *DeleteProtectionGetResponse) GetBody() (value *DeleteProtection, ok bool) {
   309  	ok = r != nil && r.body != nil
   310  	if ok {
   311  		value = r.body
   312  	}
   313  	return
   314  }
   315  
   316  // DeleteProtectionUpdateRequest is the request for the 'update' method.
   317  type DeleteProtectionUpdateRequest struct {
   318  	transport http.RoundTripper
   319  	path      string
   320  	query     url.Values
   321  	header    http.Header
   322  	body      *DeleteProtection
   323  }
   324  
   325  // Parameter adds a query parameter.
   326  func (r *DeleteProtectionUpdateRequest) Parameter(name string, value interface{}) *DeleteProtectionUpdateRequest {
   327  	helpers.AddValue(&r.query, name, value)
   328  	return r
   329  }
   330  
   331  // Header adds a request header.
   332  func (r *DeleteProtectionUpdateRequest) Header(name string, value interface{}) *DeleteProtectionUpdateRequest {
   333  	helpers.AddHeader(&r.header, name, value)
   334  	return r
   335  }
   336  
   337  // Impersonate wraps requests on behalf of another user.
   338  // Note: Services that do not support this feature may silently ignore this call.
   339  func (r *DeleteProtectionUpdateRequest) Impersonate(user string) *DeleteProtectionUpdateRequest {
   340  	helpers.AddImpersonationHeader(&r.header, user)
   341  	return r
   342  }
   343  
   344  // Body sets the value of the 'body' parameter.
   345  func (r *DeleteProtectionUpdateRequest) Body(value *DeleteProtection) *DeleteProtectionUpdateRequest {
   346  	r.body = value
   347  	return r
   348  }
   349  
   350  // Send sends this request, waits for the response, and returns it.
   351  //
   352  // This is a potentially lengthy operation, as it requires network communication.
   353  // Consider using a context and the SendContext method.
   354  func (r *DeleteProtectionUpdateRequest) Send() (result *DeleteProtectionUpdateResponse, err error) {
   355  	return r.SendContext(context.Background())
   356  }
   357  
   358  // SendContext sends this request, waits for the response, and returns it.
   359  func (r *DeleteProtectionUpdateRequest) SendContext(ctx context.Context) (result *DeleteProtectionUpdateResponse, err error) {
   360  	query := helpers.CopyQuery(r.query)
   361  	header := helpers.CopyHeader(r.header)
   362  	buffer := &bytes.Buffer{}
   363  	err = writeDeleteProtectionUpdateRequest(r, buffer)
   364  	if err != nil {
   365  		return
   366  	}
   367  	uri := &url.URL{
   368  		Path:     r.path,
   369  		RawQuery: query.Encode(),
   370  	}
   371  	request := &http.Request{
   372  		Method: "PATCH",
   373  		URL:    uri,
   374  		Header: header,
   375  		Body:   io.NopCloser(buffer),
   376  	}
   377  	if ctx != nil {
   378  		request = request.WithContext(ctx)
   379  	}
   380  	response, err := r.transport.RoundTrip(request)
   381  	if err != nil {
   382  		return
   383  	}
   384  	defer response.Body.Close()
   385  	result = &DeleteProtectionUpdateResponse{}
   386  	result.status = response.StatusCode
   387  	result.header = response.Header
   388  	reader := bufio.NewReader(response.Body)
   389  	_, err = reader.Peek(1)
   390  	if err == io.EOF {
   391  		err = nil
   392  		return
   393  	}
   394  	if result.status >= 400 {
   395  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   396  		if err != nil {
   397  			return
   398  		}
   399  		err = result.err
   400  		return
   401  	}
   402  	err = readDeleteProtectionUpdateResponse(result, reader)
   403  	if err != nil {
   404  		return
   405  	}
   406  	return
   407  }
   408  
   409  // DeleteProtectionUpdateResponse is the response for the 'update' method.
   410  type DeleteProtectionUpdateResponse struct {
   411  	status int
   412  	header http.Header
   413  	err    *errors.Error
   414  	body   *DeleteProtection
   415  }
   416  
   417  // Status returns the response status code.
   418  func (r *DeleteProtectionUpdateResponse) Status() int {
   419  	if r == nil {
   420  		return 0
   421  	}
   422  	return r.status
   423  }
   424  
   425  // Header returns header of the response.
   426  func (r *DeleteProtectionUpdateResponse) Header() http.Header {
   427  	if r == nil {
   428  		return nil
   429  	}
   430  	return r.header
   431  }
   432  
   433  // Error returns the response error.
   434  func (r *DeleteProtectionUpdateResponse) Error() *errors.Error {
   435  	if r == nil {
   436  		return nil
   437  	}
   438  	return r.err
   439  }
   440  
   441  // Body returns the value of the 'body' parameter.
   442  func (r *DeleteProtectionUpdateResponse) Body() *DeleteProtection {
   443  	if r == nil {
   444  		return nil
   445  	}
   446  	return r.body
   447  }
   448  
   449  // GetBody returns the value of the 'body' parameter and
   450  // a flag indicating if the parameter has a value.
   451  func (r *DeleteProtectionUpdateResponse) GetBody() (value *DeleteProtection, ok bool) {
   452  	ok = r != nil && r.body != nil
   453  	if ok {
   454  		value = r.body
   455  	}
   456  	return
   457  }