github.com/openshift-online/ocm-sdk-go@v0.1.473/addonsmgmt/v1/addon_installations_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  	"path"
    30  
    31  	"github.com/openshift-online/ocm-sdk-go/errors"
    32  	"github.com/openshift-online/ocm-sdk-go/helpers"
    33  )
    34  
    35  // AddonInstallationsClient is the client of the 'addon_installations' resource.
    36  //
    37  // Manages a collection of addon installations for a specific cluster
    38  type AddonInstallationsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewAddonInstallationsClient creates a new client for the 'addon_installations'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewAddonInstallationsClient(transport http.RoundTripper, path string) *AddonInstallationsClient {
    47  	return &AddonInstallationsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Create a new addon status and add it to the collection of addons installation.
    56  func (c *AddonInstallationsClient) Add() *AddonInstallationsAddRequest {
    57  	return &AddonInstallationsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // Delete creates a request for the 'delete' method.
    64  func (c *AddonInstallationsClient) Delete() *AddonInstallationsDeleteRequest {
    65  	return &AddonInstallationsDeleteRequest{
    66  		transport: c.transport,
    67  		path:      c.path,
    68  	}
    69  }
    70  
    71  // List creates a request for the 'list' method.
    72  //
    73  // Retrieves the list of addon installations for a cluster.
    74  func (c *AddonInstallationsClient) List() *AddonInstallationsListRequest {
    75  	return &AddonInstallationsListRequest{
    76  		transport: c.transport,
    77  		path:      c.path,
    78  	}
    79  }
    80  
    81  // Addon returns the target 'addon_installation' resource for the given identifier.
    82  //
    83  // Returns a reference to the service that manages a specific addon installation.
    84  func (c *AddonInstallationsClient) Addon(id string) *AddonInstallationClient {
    85  	return NewAddonInstallationClient(
    86  		c.transport,
    87  		path.Join(c.path, id),
    88  	)
    89  }
    90  
    91  // AddonInstallationsAddRequest is the request for the 'add' method.
    92  type AddonInstallationsAddRequest struct {
    93  	transport http.RoundTripper
    94  	path      string
    95  	query     url.Values
    96  	header    http.Header
    97  	body      *AddonInstallation
    98  }
    99  
   100  // Parameter adds a query parameter.
   101  func (r *AddonInstallationsAddRequest) Parameter(name string, value interface{}) *AddonInstallationsAddRequest {
   102  	helpers.AddValue(&r.query, name, value)
   103  	return r
   104  }
   105  
   106  // Header adds a request header.
   107  func (r *AddonInstallationsAddRequest) Header(name string, value interface{}) *AddonInstallationsAddRequest {
   108  	helpers.AddHeader(&r.header, name, value)
   109  	return r
   110  }
   111  
   112  // Impersonate wraps requests on behalf of another user.
   113  // Note: Services that do not support this feature may silently ignore this call.
   114  func (r *AddonInstallationsAddRequest) Impersonate(user string) *AddonInstallationsAddRequest {
   115  	helpers.AddImpersonationHeader(&r.header, user)
   116  	return r
   117  }
   118  
   119  // Body sets the value of the 'body' parameter.
   120  //
   121  // Description of the addon installation.
   122  func (r *AddonInstallationsAddRequest) Body(value *AddonInstallation) *AddonInstallationsAddRequest {
   123  	r.body = value
   124  	return r
   125  }
   126  
   127  // Send sends this request, waits for the response, and returns it.
   128  //
   129  // This is a potentially lengthy operation, as it requires network communication.
   130  // Consider using a context and the SendContext method.
   131  func (r *AddonInstallationsAddRequest) Send() (result *AddonInstallationsAddResponse, err error) {
   132  	return r.SendContext(context.Background())
   133  }
   134  
   135  // SendContext sends this request, waits for the response, and returns it.
   136  func (r *AddonInstallationsAddRequest) SendContext(ctx context.Context) (result *AddonInstallationsAddResponse, err error) {
   137  	query := helpers.CopyQuery(r.query)
   138  	header := helpers.CopyHeader(r.header)
   139  	buffer := &bytes.Buffer{}
   140  	err = writeAddonInstallationsAddRequest(r, buffer)
   141  	if err != nil {
   142  		return
   143  	}
   144  	uri := &url.URL{
   145  		Path:     r.path,
   146  		RawQuery: query.Encode(),
   147  	}
   148  	request := &http.Request{
   149  		Method: "POST",
   150  		URL:    uri,
   151  		Header: header,
   152  		Body:   io.NopCloser(buffer),
   153  	}
   154  	if ctx != nil {
   155  		request = request.WithContext(ctx)
   156  	}
   157  	response, err := r.transport.RoundTrip(request)
   158  	if err != nil {
   159  		return
   160  	}
   161  	defer response.Body.Close()
   162  	result = &AddonInstallationsAddResponse{}
   163  	result.status = response.StatusCode
   164  	result.header = response.Header
   165  	reader := bufio.NewReader(response.Body)
   166  	_, err = reader.Peek(1)
   167  	if err == io.EOF {
   168  		err = nil
   169  		return
   170  	}
   171  	if result.status >= 400 {
   172  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   173  		if err != nil {
   174  			return
   175  		}
   176  		err = result.err
   177  		return
   178  	}
   179  	err = readAddonInstallationsAddResponse(result, reader)
   180  	if err != nil {
   181  		return
   182  	}
   183  	return
   184  }
   185  
   186  // AddonInstallationsAddResponse is the response for the 'add' method.
   187  type AddonInstallationsAddResponse struct {
   188  	status int
   189  	header http.Header
   190  	err    *errors.Error
   191  	body   *AddonInstallation
   192  }
   193  
   194  // Status returns the response status code.
   195  func (r *AddonInstallationsAddResponse) Status() int {
   196  	if r == nil {
   197  		return 0
   198  	}
   199  	return r.status
   200  }
   201  
   202  // Header returns header of the response.
   203  func (r *AddonInstallationsAddResponse) Header() http.Header {
   204  	if r == nil {
   205  		return nil
   206  	}
   207  	return r.header
   208  }
   209  
   210  // Error returns the response error.
   211  func (r *AddonInstallationsAddResponse) Error() *errors.Error {
   212  	if r == nil {
   213  		return nil
   214  	}
   215  	return r.err
   216  }
   217  
   218  // Body returns the value of the 'body' parameter.
   219  //
   220  // Description of the addon installation.
   221  func (r *AddonInstallationsAddResponse) Body() *AddonInstallation {
   222  	if r == nil {
   223  		return nil
   224  	}
   225  	return r.body
   226  }
   227  
   228  // GetBody returns the value of the 'body' parameter and
   229  // a flag indicating if the parameter has a value.
   230  //
   231  // Description of the addon installation.
   232  func (r *AddonInstallationsAddResponse) GetBody() (value *AddonInstallation, ok bool) {
   233  	ok = r != nil && r.body != nil
   234  	if ok {
   235  		value = r.body
   236  	}
   237  	return
   238  }
   239  
   240  // AddonInstallationsDeleteRequest is the request for the 'delete' method.
   241  type AddonInstallationsDeleteRequest struct {
   242  	transport http.RoundTripper
   243  	path      string
   244  	query     url.Values
   245  	header    http.Header
   246  }
   247  
   248  // Parameter adds a query parameter.
   249  func (r *AddonInstallationsDeleteRequest) Parameter(name string, value interface{}) *AddonInstallationsDeleteRequest {
   250  	helpers.AddValue(&r.query, name, value)
   251  	return r
   252  }
   253  
   254  // Header adds a request header.
   255  func (r *AddonInstallationsDeleteRequest) Header(name string, value interface{}) *AddonInstallationsDeleteRequest {
   256  	helpers.AddHeader(&r.header, name, value)
   257  	return r
   258  }
   259  
   260  // Impersonate wraps requests on behalf of another user.
   261  // Note: Services that do not support this feature may silently ignore this call.
   262  func (r *AddonInstallationsDeleteRequest) Impersonate(user string) *AddonInstallationsDeleteRequest {
   263  	helpers.AddImpersonationHeader(&r.header, user)
   264  	return r
   265  }
   266  
   267  // Send sends this request, waits for the response, and returns it.
   268  //
   269  // This is a potentially lengthy operation, as it requires network communication.
   270  // Consider using a context and the SendContext method.
   271  func (r *AddonInstallationsDeleteRequest) Send() (result *AddonInstallationsDeleteResponse, err error) {
   272  	return r.SendContext(context.Background())
   273  }
   274  
   275  // SendContext sends this request, waits for the response, and returns it.
   276  func (r *AddonInstallationsDeleteRequest) SendContext(ctx context.Context) (result *AddonInstallationsDeleteResponse, err error) {
   277  	query := helpers.CopyQuery(r.query)
   278  	header := helpers.CopyHeader(r.header)
   279  	uri := &url.URL{
   280  		Path:     r.path,
   281  		RawQuery: query.Encode(),
   282  	}
   283  	request := &http.Request{
   284  		Method: "DELETE",
   285  		URL:    uri,
   286  		Header: header,
   287  	}
   288  	if ctx != nil {
   289  		request = request.WithContext(ctx)
   290  	}
   291  	response, err := r.transport.RoundTrip(request)
   292  	if err != nil {
   293  		return
   294  	}
   295  	defer response.Body.Close()
   296  	result = &AddonInstallationsDeleteResponse{}
   297  	result.status = response.StatusCode
   298  	result.header = response.Header
   299  	reader := bufio.NewReader(response.Body)
   300  	_, err = reader.Peek(1)
   301  	if err == io.EOF {
   302  		err = nil
   303  		return
   304  	}
   305  	if result.status >= 400 {
   306  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   307  		if err != nil {
   308  			return
   309  		}
   310  		err = result.err
   311  		return
   312  	}
   313  	return
   314  }
   315  
   316  // AddonInstallationsDeleteResponse is the response for the 'delete' method.
   317  type AddonInstallationsDeleteResponse struct {
   318  	status int
   319  	header http.Header
   320  	err    *errors.Error
   321  }
   322  
   323  // Status returns the response status code.
   324  func (r *AddonInstallationsDeleteResponse) Status() int {
   325  	if r == nil {
   326  		return 0
   327  	}
   328  	return r.status
   329  }
   330  
   331  // Header returns header of the response.
   332  func (r *AddonInstallationsDeleteResponse) Header() http.Header {
   333  	if r == nil {
   334  		return nil
   335  	}
   336  	return r.header
   337  }
   338  
   339  // Error returns the response error.
   340  func (r *AddonInstallationsDeleteResponse) Error() *errors.Error {
   341  	if r == nil {
   342  		return nil
   343  	}
   344  	return r.err
   345  }
   346  
   347  // AddonInstallationsListRequest is the request for the 'list' method.
   348  type AddonInstallationsListRequest struct {
   349  	transport http.RoundTripper
   350  	path      string
   351  	query     url.Values
   352  	header    http.Header
   353  	order     *string
   354  	page      *int
   355  	size      *int
   356  }
   357  
   358  // Parameter adds a query parameter.
   359  func (r *AddonInstallationsListRequest) Parameter(name string, value interface{}) *AddonInstallationsListRequest {
   360  	helpers.AddValue(&r.query, name, value)
   361  	return r
   362  }
   363  
   364  // Header adds a request header.
   365  func (r *AddonInstallationsListRequest) Header(name string, value interface{}) *AddonInstallationsListRequest {
   366  	helpers.AddHeader(&r.header, name, value)
   367  	return r
   368  }
   369  
   370  // Impersonate wraps requests on behalf of another user.
   371  // Note: Services that do not support this feature may silently ignore this call.
   372  func (r *AddonInstallationsListRequest) Impersonate(user string) *AddonInstallationsListRequest {
   373  	helpers.AddImpersonationHeader(&r.header, user)
   374  	return r
   375  }
   376  
   377  // Order sets the value of the 'order' parameter.
   378  //
   379  // If the parameter isn't provided, or if the value is empty, then the order of the
   380  // results is undefined.
   381  func (r *AddonInstallationsListRequest) Order(value string) *AddonInstallationsListRequest {
   382  	r.order = &value
   383  	return r
   384  }
   385  
   386  // Page sets the value of the 'page' parameter.
   387  //
   388  // Index of the requested page, where one corresponds to the first page.
   389  func (r *AddonInstallationsListRequest) Page(value int) *AddonInstallationsListRequest {
   390  	r.page = &value
   391  	return r
   392  }
   393  
   394  // Size sets the value of the 'size' parameter.
   395  //
   396  // Maximum number of items that will be contained in the returned page.
   397  func (r *AddonInstallationsListRequest) Size(value int) *AddonInstallationsListRequest {
   398  	r.size = &value
   399  	return r
   400  }
   401  
   402  // Send sends this request, waits for the response, and returns it.
   403  //
   404  // This is a potentially lengthy operation, as it requires network communication.
   405  // Consider using a context and the SendContext method.
   406  func (r *AddonInstallationsListRequest) Send() (result *AddonInstallationsListResponse, err error) {
   407  	return r.SendContext(context.Background())
   408  }
   409  
   410  // SendContext sends this request, waits for the response, and returns it.
   411  func (r *AddonInstallationsListRequest) SendContext(ctx context.Context) (result *AddonInstallationsListResponse, err error) {
   412  	query := helpers.CopyQuery(r.query)
   413  	if r.order != nil {
   414  		helpers.AddValue(&query, "order", *r.order)
   415  	}
   416  	if r.page != nil {
   417  		helpers.AddValue(&query, "page", *r.page)
   418  	}
   419  	if r.size != nil {
   420  		helpers.AddValue(&query, "size", *r.size)
   421  	}
   422  	header := helpers.CopyHeader(r.header)
   423  	uri := &url.URL{
   424  		Path:     r.path,
   425  		RawQuery: query.Encode(),
   426  	}
   427  	request := &http.Request{
   428  		Method: "GET",
   429  		URL:    uri,
   430  		Header: header,
   431  	}
   432  	if ctx != nil {
   433  		request = request.WithContext(ctx)
   434  	}
   435  	response, err := r.transport.RoundTrip(request)
   436  	if err != nil {
   437  		return
   438  	}
   439  	defer response.Body.Close()
   440  	result = &AddonInstallationsListResponse{}
   441  	result.status = response.StatusCode
   442  	result.header = response.Header
   443  	reader := bufio.NewReader(response.Body)
   444  	_, err = reader.Peek(1)
   445  	if err == io.EOF {
   446  		err = nil
   447  		return
   448  	}
   449  	if result.status >= 400 {
   450  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   451  		if err != nil {
   452  			return
   453  		}
   454  		err = result.err
   455  		return
   456  	}
   457  	err = readAddonInstallationsListResponse(result, reader)
   458  	if err != nil {
   459  		return
   460  	}
   461  	return
   462  }
   463  
   464  // AddonInstallationsListResponse is the response for the 'list' method.
   465  type AddonInstallationsListResponse struct {
   466  	status int
   467  	header http.Header
   468  	err    *errors.Error
   469  	items  *AddonInstallationList
   470  	page   *int
   471  	size   *int
   472  	total  *int
   473  }
   474  
   475  // Status returns the response status code.
   476  func (r *AddonInstallationsListResponse) Status() int {
   477  	if r == nil {
   478  		return 0
   479  	}
   480  	return r.status
   481  }
   482  
   483  // Header returns header of the response.
   484  func (r *AddonInstallationsListResponse) Header() http.Header {
   485  	if r == nil {
   486  		return nil
   487  	}
   488  	return r.header
   489  }
   490  
   491  // Error returns the response error.
   492  func (r *AddonInstallationsListResponse) Error() *errors.Error {
   493  	if r == nil {
   494  		return nil
   495  	}
   496  	return r.err
   497  }
   498  
   499  // Items returns the value of the 'items' parameter.
   500  //
   501  // Retrieved list of addon installations
   502  func (r *AddonInstallationsListResponse) Items() *AddonInstallationList {
   503  	if r == nil {
   504  		return nil
   505  	}
   506  	return r.items
   507  }
   508  
   509  // GetItems returns the value of the 'items' parameter and
   510  // a flag indicating if the parameter has a value.
   511  //
   512  // Retrieved list of addon installations
   513  func (r *AddonInstallationsListResponse) GetItems() (value *AddonInstallationList, ok bool) {
   514  	ok = r != nil && r.items != nil
   515  	if ok {
   516  		value = r.items
   517  	}
   518  	return
   519  }
   520  
   521  // Page returns the value of the 'page' parameter.
   522  //
   523  // Index of the requested page, where one corresponds to the first page.
   524  func (r *AddonInstallationsListResponse) Page() int {
   525  	if r != nil && r.page != nil {
   526  		return *r.page
   527  	}
   528  	return 0
   529  }
   530  
   531  // GetPage returns the value of the 'page' parameter and
   532  // a flag indicating if the parameter has a value.
   533  //
   534  // Index of the requested page, where one corresponds to the first page.
   535  func (r *AddonInstallationsListResponse) GetPage() (value int, ok bool) {
   536  	ok = r != nil && r.page != nil
   537  	if ok {
   538  		value = *r.page
   539  	}
   540  	return
   541  }
   542  
   543  // Size returns the value of the 'size' parameter.
   544  //
   545  // Maximum number of items that will be contained in the returned page.
   546  func (r *AddonInstallationsListResponse) Size() int {
   547  	if r != nil && r.size != nil {
   548  		return *r.size
   549  	}
   550  	return 0
   551  }
   552  
   553  // GetSize returns the value of the 'size' parameter and
   554  // a flag indicating if the parameter has a value.
   555  //
   556  // Maximum number of items that will be contained in the returned page.
   557  func (r *AddonInstallationsListResponse) GetSize() (value int, ok bool) {
   558  	ok = r != nil && r.size != nil
   559  	if ok {
   560  		value = *r.size
   561  	}
   562  	return
   563  }
   564  
   565  // Total returns the value of the 'total' parameter.
   566  //
   567  // Total number of items of the collection regardless of the size of the page.
   568  func (r *AddonInstallationsListResponse) Total() int {
   569  	if r != nil && r.total != nil {
   570  		return *r.total
   571  	}
   572  	return 0
   573  }
   574  
   575  // GetTotal returns the value of the 'total' parameter and
   576  // a flag indicating if the parameter has a value.
   577  //
   578  // Total number of items of the collection regardless of the size of the page.
   579  func (r *AddonInstallationsListResponse) GetTotal() (value int, ok bool) {
   580  	ok = r != nil && r.total != nil
   581  	if ok {
   582  		value = *r.total
   583  	}
   584  	return
   585  }