github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/add_on_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/clustersmgmt/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 'add_on_installations' resource.
    36  //
    37  // Manages the collection of add-on installations.
    38  type AddOnInstallationsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewAddOnInstallationsClient creates a new client for the 'add_on_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 add-on installation and add it to the collection of add-on installations on the cluster.
    56  func (c *AddOnInstallationsClient) Add() *AddOnInstallationsAddRequest {
    57  	return &AddOnInstallationsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // List creates a request for the 'list' method.
    64  //
    65  // Retrieves the list of add-on installations.
    66  func (c *AddOnInstallationsClient) List() *AddOnInstallationsListRequest {
    67  	return &AddOnInstallationsListRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // Addoninstallation returns the target 'add_on_installation' resource for the given identifier.
    74  //
    75  // Returns a reference to the service that manages a specific add-on installation.
    76  func (c *AddOnInstallationsClient) Addoninstallation(id string) *AddOnInstallationClient {
    77  	return NewAddOnInstallationClient(
    78  		c.transport,
    79  		path.Join(c.path, id),
    80  	)
    81  }
    82  
    83  // AddOnInstallationsAddRequest is the request for the 'add' method.
    84  type AddOnInstallationsAddRequest struct {
    85  	transport http.RoundTripper
    86  	path      string
    87  	query     url.Values
    88  	header    http.Header
    89  	body      *AddOnInstallation
    90  }
    91  
    92  // Parameter adds a query parameter.
    93  func (r *AddOnInstallationsAddRequest) Parameter(name string, value interface{}) *AddOnInstallationsAddRequest {
    94  	helpers.AddValue(&r.query, name, value)
    95  	return r
    96  }
    97  
    98  // Header adds a request header.
    99  func (r *AddOnInstallationsAddRequest) Header(name string, value interface{}) *AddOnInstallationsAddRequest {
   100  	helpers.AddHeader(&r.header, name, value)
   101  	return r
   102  }
   103  
   104  // Impersonate wraps requests on behalf of another user.
   105  // Note: Services that do not support this feature may silently ignore this call.
   106  func (r *AddOnInstallationsAddRequest) Impersonate(user string) *AddOnInstallationsAddRequest {
   107  	helpers.AddImpersonationHeader(&r.header, user)
   108  	return r
   109  }
   110  
   111  // Body sets the value of the 'body' parameter.
   112  //
   113  // Description of the add-on installation.
   114  func (r *AddOnInstallationsAddRequest) Body(value *AddOnInstallation) *AddOnInstallationsAddRequest {
   115  	r.body = value
   116  	return r
   117  }
   118  
   119  // Send sends this request, waits for the response, and returns it.
   120  //
   121  // This is a potentially lengthy operation, as it requires network communication.
   122  // Consider using a context and the SendContext method.
   123  func (r *AddOnInstallationsAddRequest) Send() (result *AddOnInstallationsAddResponse, err error) {
   124  	return r.SendContext(context.Background())
   125  }
   126  
   127  // SendContext sends this request, waits for the response, and returns it.
   128  func (r *AddOnInstallationsAddRequest) SendContext(ctx context.Context) (result *AddOnInstallationsAddResponse, err error) {
   129  	query := helpers.CopyQuery(r.query)
   130  	header := helpers.CopyHeader(r.header)
   131  	buffer := &bytes.Buffer{}
   132  	err = writeAddOnInstallationsAddRequest(r, buffer)
   133  	if err != nil {
   134  		return
   135  	}
   136  	uri := &url.URL{
   137  		Path:     r.path,
   138  		RawQuery: query.Encode(),
   139  	}
   140  	request := &http.Request{
   141  		Method: "POST",
   142  		URL:    uri,
   143  		Header: header,
   144  		Body:   io.NopCloser(buffer),
   145  	}
   146  	if ctx != nil {
   147  		request = request.WithContext(ctx)
   148  	}
   149  	response, err := r.transport.RoundTrip(request)
   150  	if err != nil {
   151  		return
   152  	}
   153  	defer response.Body.Close()
   154  	result = &AddOnInstallationsAddResponse{}
   155  	result.status = response.StatusCode
   156  	result.header = response.Header
   157  	reader := bufio.NewReader(response.Body)
   158  	_, err = reader.Peek(1)
   159  	if err == io.EOF {
   160  		err = nil
   161  		return
   162  	}
   163  	if result.status >= 400 {
   164  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   165  		if err != nil {
   166  			return
   167  		}
   168  		err = result.err
   169  		return
   170  	}
   171  	err = readAddOnInstallationsAddResponse(result, reader)
   172  	if err != nil {
   173  		return
   174  	}
   175  	return
   176  }
   177  
   178  // AddOnInstallationsAddResponse is the response for the 'add' method.
   179  type AddOnInstallationsAddResponse struct {
   180  	status int
   181  	header http.Header
   182  	err    *errors.Error
   183  	body   *AddOnInstallation
   184  }
   185  
   186  // Status returns the response status code.
   187  func (r *AddOnInstallationsAddResponse) Status() int {
   188  	if r == nil {
   189  		return 0
   190  	}
   191  	return r.status
   192  }
   193  
   194  // Header returns header of the response.
   195  func (r *AddOnInstallationsAddResponse) Header() http.Header {
   196  	if r == nil {
   197  		return nil
   198  	}
   199  	return r.header
   200  }
   201  
   202  // Error returns the response error.
   203  func (r *AddOnInstallationsAddResponse) Error() *errors.Error {
   204  	if r == nil {
   205  		return nil
   206  	}
   207  	return r.err
   208  }
   209  
   210  // Body returns the value of the 'body' parameter.
   211  //
   212  // Description of the add-on installation.
   213  func (r *AddOnInstallationsAddResponse) Body() *AddOnInstallation {
   214  	if r == nil {
   215  		return nil
   216  	}
   217  	return r.body
   218  }
   219  
   220  // GetBody returns the value of the 'body' parameter and
   221  // a flag indicating if the parameter has a value.
   222  //
   223  // Description of the add-on installation.
   224  func (r *AddOnInstallationsAddResponse) GetBody() (value *AddOnInstallation, ok bool) {
   225  	ok = r != nil && r.body != nil
   226  	if ok {
   227  		value = r.body
   228  	}
   229  	return
   230  }
   231  
   232  // AddOnInstallationsListRequest is the request for the 'list' method.
   233  type AddOnInstallationsListRequest struct {
   234  	transport http.RoundTripper
   235  	path      string
   236  	query     url.Values
   237  	header    http.Header
   238  	order     *string
   239  	page      *int
   240  	search    *string
   241  	size      *int
   242  }
   243  
   244  // Parameter adds a query parameter.
   245  func (r *AddOnInstallationsListRequest) Parameter(name string, value interface{}) *AddOnInstallationsListRequest {
   246  	helpers.AddValue(&r.query, name, value)
   247  	return r
   248  }
   249  
   250  // Header adds a request header.
   251  func (r *AddOnInstallationsListRequest) Header(name string, value interface{}) *AddOnInstallationsListRequest {
   252  	helpers.AddHeader(&r.header, name, value)
   253  	return r
   254  }
   255  
   256  // Impersonate wraps requests on behalf of another user.
   257  // Note: Services that do not support this feature may silently ignore this call.
   258  func (r *AddOnInstallationsListRequest) Impersonate(user string) *AddOnInstallationsListRequest {
   259  	helpers.AddImpersonationHeader(&r.header, user)
   260  	return r
   261  }
   262  
   263  // Order sets the value of the 'order' parameter.
   264  //
   265  // Order criteria.
   266  //
   267  // The syntax of this parameter is similar to the syntax of the _order by_ clause of
   268  // a SQL statement, but using the names of the attributes of the add-on installation
   269  // instead of the names of the columns of a table. For example, in order to sort the
   270  // add-on installations descending by name the value should be:
   271  //
   272  // ```sql
   273  // name desc
   274  // ```
   275  //
   276  // If the parameter isn't provided, or if the value is empty, then the order of the
   277  // results is undefined.
   278  func (r *AddOnInstallationsListRequest) Order(value string) *AddOnInstallationsListRequest {
   279  	r.order = &value
   280  	return r
   281  }
   282  
   283  // Page sets the value of the 'page' parameter.
   284  //
   285  // Index of the requested page, where one corresponds to the first page.
   286  func (r *AddOnInstallationsListRequest) Page(value int) *AddOnInstallationsListRequest {
   287  	r.page = &value
   288  	return r
   289  }
   290  
   291  // Search sets the value of the 'search' parameter.
   292  //
   293  // Search criteria.
   294  //
   295  // The syntax of this parameter is similar to the syntax of the _where_ clause of an
   296  // SQL statement, but using the names of the attributes of the add-on installation
   297  // instead of the names of the columns of a table. For example, in order to retrieve
   298  // all the add-on installations with a name starting with `my` the value should be:
   299  //
   300  // ```sql
   301  // name like 'my%'
   302  // ```
   303  //
   304  // If the parameter isn't provided, or if the value is empty, then all the add-on
   305  // installations that the user has permission to see will be returned.
   306  func (r *AddOnInstallationsListRequest) Search(value string) *AddOnInstallationsListRequest {
   307  	r.search = &value
   308  	return r
   309  }
   310  
   311  // Size sets the value of the 'size' parameter.
   312  //
   313  // Maximum number of items that will be contained in the returned page.
   314  func (r *AddOnInstallationsListRequest) Size(value int) *AddOnInstallationsListRequest {
   315  	r.size = &value
   316  	return r
   317  }
   318  
   319  // Send sends this request, waits for the response, and returns it.
   320  //
   321  // This is a potentially lengthy operation, as it requires network communication.
   322  // Consider using a context and the SendContext method.
   323  func (r *AddOnInstallationsListRequest) Send() (result *AddOnInstallationsListResponse, err error) {
   324  	return r.SendContext(context.Background())
   325  }
   326  
   327  // SendContext sends this request, waits for the response, and returns it.
   328  func (r *AddOnInstallationsListRequest) SendContext(ctx context.Context) (result *AddOnInstallationsListResponse, err error) {
   329  	query := helpers.CopyQuery(r.query)
   330  	if r.order != nil {
   331  		helpers.AddValue(&query, "order", *r.order)
   332  	}
   333  	if r.page != nil {
   334  		helpers.AddValue(&query, "page", *r.page)
   335  	}
   336  	if r.search != nil {
   337  		helpers.AddValue(&query, "search", *r.search)
   338  	}
   339  	if r.size != nil {
   340  		helpers.AddValue(&query, "size", *r.size)
   341  	}
   342  	header := helpers.CopyHeader(r.header)
   343  	uri := &url.URL{
   344  		Path:     r.path,
   345  		RawQuery: query.Encode(),
   346  	}
   347  	request := &http.Request{
   348  		Method: "GET",
   349  		URL:    uri,
   350  		Header: header,
   351  	}
   352  	if ctx != nil {
   353  		request = request.WithContext(ctx)
   354  	}
   355  	response, err := r.transport.RoundTrip(request)
   356  	if err != nil {
   357  		return
   358  	}
   359  	defer response.Body.Close()
   360  	result = &AddOnInstallationsListResponse{}
   361  	result.status = response.StatusCode
   362  	result.header = response.Header
   363  	reader := bufio.NewReader(response.Body)
   364  	_, err = reader.Peek(1)
   365  	if err == io.EOF {
   366  		err = nil
   367  		return
   368  	}
   369  	if result.status >= 400 {
   370  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   371  		if err != nil {
   372  			return
   373  		}
   374  		err = result.err
   375  		return
   376  	}
   377  	err = readAddOnInstallationsListResponse(result, reader)
   378  	if err != nil {
   379  		return
   380  	}
   381  	return
   382  }
   383  
   384  // AddOnInstallationsListResponse is the response for the 'list' method.
   385  type AddOnInstallationsListResponse struct {
   386  	status int
   387  	header http.Header
   388  	err    *errors.Error
   389  	items  *AddOnInstallationList
   390  	page   *int
   391  	size   *int
   392  	total  *int
   393  }
   394  
   395  // Status returns the response status code.
   396  func (r *AddOnInstallationsListResponse) 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 *AddOnInstallationsListResponse) 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 *AddOnInstallationsListResponse) Error() *errors.Error {
   413  	if r == nil {
   414  		return nil
   415  	}
   416  	return r.err
   417  }
   418  
   419  // Items returns the value of the 'items' parameter.
   420  //
   421  // Retrieved list of add-on installations.
   422  func (r *AddOnInstallationsListResponse) Items() *AddOnInstallationList {
   423  	if r == nil {
   424  		return nil
   425  	}
   426  	return r.items
   427  }
   428  
   429  // GetItems returns the value of the 'items' parameter and
   430  // a flag indicating if the parameter has a value.
   431  //
   432  // Retrieved list of add-on installations.
   433  func (r *AddOnInstallationsListResponse) GetItems() (value *AddOnInstallationList, ok bool) {
   434  	ok = r != nil && r.items != nil
   435  	if ok {
   436  		value = r.items
   437  	}
   438  	return
   439  }
   440  
   441  // Page returns the value of the 'page' parameter.
   442  //
   443  // Index of the requested page, where one corresponds to the first page.
   444  func (r *AddOnInstallationsListResponse) Page() int {
   445  	if r != nil && r.page != nil {
   446  		return *r.page
   447  	}
   448  	return 0
   449  }
   450  
   451  // GetPage returns the value of the 'page' parameter and
   452  // a flag indicating if the parameter has a value.
   453  //
   454  // Index of the requested page, where one corresponds to the first page.
   455  func (r *AddOnInstallationsListResponse) GetPage() (value int, ok bool) {
   456  	ok = r != nil && r.page != nil
   457  	if ok {
   458  		value = *r.page
   459  	}
   460  	return
   461  }
   462  
   463  // Size returns the value of the 'size' parameter.
   464  //
   465  // Maximum number of items that will be contained in the returned page.
   466  func (r *AddOnInstallationsListResponse) Size() int {
   467  	if r != nil && r.size != nil {
   468  		return *r.size
   469  	}
   470  	return 0
   471  }
   472  
   473  // GetSize returns the value of the 'size' parameter and
   474  // a flag indicating if the parameter has a value.
   475  //
   476  // Maximum number of items that will be contained in the returned page.
   477  func (r *AddOnInstallationsListResponse) GetSize() (value int, ok bool) {
   478  	ok = r != nil && r.size != nil
   479  	if ok {
   480  		value = *r.size
   481  	}
   482  	return
   483  }
   484  
   485  // Total returns the value of the 'total' parameter.
   486  //
   487  // Total number of items of the collection that match the search criteria,
   488  // regardless of the size of the page.
   489  func (r *AddOnInstallationsListResponse) Total() int {
   490  	if r != nil && r.total != nil {
   491  		return *r.total
   492  	}
   493  	return 0
   494  }
   495  
   496  // GetTotal returns the value of the 'total' parameter and
   497  // a flag indicating if the parameter has a value.
   498  //
   499  // Total number of items of the collection that match the search criteria,
   500  // regardless of the size of the page.
   501  func (r *AddOnInstallationsListResponse) GetTotal() (value int, ok bool) {
   502  	ok = r != nil && r.total != nil
   503  	if ok {
   504  		value = *r.total
   505  	}
   506  	return
   507  }