github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/wif_configs_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  // WifConfigsClient is the client of the 'wif_configs' resource.
    36  //
    37  // Manages the collection of wif_configs.
    38  type WifConfigsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewWifConfigsClient creates a new client for the 'wif_configs'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewWifConfigsClient(transport http.RoundTripper, path string) *WifConfigsClient {
    47  	return &WifConfigsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Provision a new wif_config resource and add it to the collection of wif_configs.
    56  func (c *WifConfigsClient) Add() *WifConfigsAddRequest {
    57  	return &WifConfigsAddRequest{
    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 wif_configs
    66  func (c *WifConfigsClient) List() *WifConfigsListRequest {
    67  	return &WifConfigsListRequest{
    68  		transport: c.transport,
    69  		path:      c.path,
    70  	}
    71  }
    72  
    73  // WifConfig returns the target 'wif_config' resource for the given identifier.
    74  //
    75  // Returns a reference to the service that manages an specific wif_config.
    76  func (c *WifConfigsClient) WifConfig(id string) *WifConfigClient {
    77  	return NewWifConfigClient(
    78  		c.transport,
    79  		path.Join(c.path, id),
    80  	)
    81  }
    82  
    83  // WifConfigsAddRequest is the request for the 'add' method.
    84  type WifConfigsAddRequest struct {
    85  	transport http.RoundTripper
    86  	path      string
    87  	query     url.Values
    88  	header    http.Header
    89  	body      *WifConfig
    90  }
    91  
    92  // Parameter adds a query parameter.
    93  func (r *WifConfigsAddRequest) Parameter(name string, value interface{}) *WifConfigsAddRequest {
    94  	helpers.AddValue(&r.query, name, value)
    95  	return r
    96  }
    97  
    98  // Header adds a request header.
    99  func (r *WifConfigsAddRequest) Header(name string, value interface{}) *WifConfigsAddRequest {
   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 *WifConfigsAddRequest) Impersonate(user string) *WifConfigsAddRequest {
   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 wif_config.
   114  func (r *WifConfigsAddRequest) Body(value *WifConfig) *WifConfigsAddRequest {
   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 *WifConfigsAddRequest) Send() (result *WifConfigsAddResponse, 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 *WifConfigsAddRequest) SendContext(ctx context.Context) (result *WifConfigsAddResponse, err error) {
   129  	query := helpers.CopyQuery(r.query)
   130  	header := helpers.CopyHeader(r.header)
   131  	buffer := &bytes.Buffer{}
   132  	err = writeWifConfigsAddRequest(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 = &WifConfigsAddResponse{}
   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 = readWifConfigsAddResponse(result, reader)
   172  	if err != nil {
   173  		return
   174  	}
   175  	return
   176  }
   177  
   178  // WifConfigsAddResponse is the response for the 'add' method.
   179  type WifConfigsAddResponse struct {
   180  	status int
   181  	header http.Header
   182  	err    *errors.Error
   183  	body   *WifConfig
   184  }
   185  
   186  // Status returns the response status code.
   187  func (r *WifConfigsAddResponse) 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 *WifConfigsAddResponse) 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 *WifConfigsAddResponse) 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 wif_config.
   213  func (r *WifConfigsAddResponse) Body() *WifConfig {
   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 wif_config.
   224  func (r *WifConfigsAddResponse) GetBody() (value *WifConfig, ok bool) {
   225  	ok = r != nil && r.body != nil
   226  	if ok {
   227  		value = r.body
   228  	}
   229  	return
   230  }
   231  
   232  // WifConfigsListRequest is the request for the 'list' method.
   233  type WifConfigsListRequest 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 *WifConfigsListRequest) Parameter(name string, value interface{}) *WifConfigsListRequest {
   246  	helpers.AddValue(&r.query, name, value)
   247  	return r
   248  }
   249  
   250  // Header adds a request header.
   251  func (r *WifConfigsListRequest) Header(name string, value interface{}) *WifConfigsListRequest {
   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 *WifConfigsListRequest) Impersonate(user string) *WifConfigsListRequest {
   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 cluster instead of
   269  // the names of the columns of a table. For example, in order to sort the clusters
   270  // descending by region identifier the value should be:
   271  //
   272  // ```sql
   273  // region.id 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 *WifConfigsListRequest) Order(value string) *WifConfigsListRequest {
   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 *WifConfigsListRequest) Page(value int) *WifConfigsListRequest {
   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 a
   296  // SQL statement, but using the names of the attributes of the cluster instead of
   297  // the names of the columns of a table. For example, in order to retrieve all the
   298  // clusters with a name starting with `my` in the `us-east-1` region the value
   299  // should be:
   300  //
   301  // ```sql
   302  // name like 'my%' and region.id = 'us-east-1'
   303  // ```
   304  //
   305  // If the parameter isn't provided, or if the value is empty, then all the
   306  // wif_configs that the user has permission to see will be returned.
   307  func (r *WifConfigsListRequest) Search(value string) *WifConfigsListRequest {
   308  	r.search = &value
   309  	return r
   310  }
   311  
   312  // Size sets the value of the 'size' parameter.
   313  //
   314  // Maximum number of items that will be contained in the returned page.
   315  func (r *WifConfigsListRequest) Size(value int) *WifConfigsListRequest {
   316  	r.size = &value
   317  	return r
   318  }
   319  
   320  // Send sends this request, waits for the response, and returns it.
   321  //
   322  // This is a potentially lengthy operation, as it requires network communication.
   323  // Consider using a context and the SendContext method.
   324  func (r *WifConfigsListRequest) Send() (result *WifConfigsListResponse, err error) {
   325  	return r.SendContext(context.Background())
   326  }
   327  
   328  // SendContext sends this request, waits for the response, and returns it.
   329  func (r *WifConfigsListRequest) SendContext(ctx context.Context) (result *WifConfigsListResponse, err error) {
   330  	query := helpers.CopyQuery(r.query)
   331  	if r.order != nil {
   332  		helpers.AddValue(&query, "order", *r.order)
   333  	}
   334  	if r.page != nil {
   335  		helpers.AddValue(&query, "page", *r.page)
   336  	}
   337  	if r.search != nil {
   338  		helpers.AddValue(&query, "search", *r.search)
   339  	}
   340  	if r.size != nil {
   341  		helpers.AddValue(&query, "size", *r.size)
   342  	}
   343  	header := helpers.CopyHeader(r.header)
   344  	uri := &url.URL{
   345  		Path:     r.path,
   346  		RawQuery: query.Encode(),
   347  	}
   348  	request := &http.Request{
   349  		Method: "GET",
   350  		URL:    uri,
   351  		Header: header,
   352  	}
   353  	if ctx != nil {
   354  		request = request.WithContext(ctx)
   355  	}
   356  	response, err := r.transport.RoundTrip(request)
   357  	if err != nil {
   358  		return
   359  	}
   360  	defer response.Body.Close()
   361  	result = &WifConfigsListResponse{}
   362  	result.status = response.StatusCode
   363  	result.header = response.Header
   364  	reader := bufio.NewReader(response.Body)
   365  	_, err = reader.Peek(1)
   366  	if err == io.EOF {
   367  		err = nil
   368  		return
   369  	}
   370  	if result.status >= 400 {
   371  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   372  		if err != nil {
   373  			return
   374  		}
   375  		err = result.err
   376  		return
   377  	}
   378  	err = readWifConfigsListResponse(result, reader)
   379  	if err != nil {
   380  		return
   381  	}
   382  	return
   383  }
   384  
   385  // WifConfigsListResponse is the response for the 'list' method.
   386  type WifConfigsListResponse struct {
   387  	status int
   388  	header http.Header
   389  	err    *errors.Error
   390  	items  *WifConfigList
   391  	page   *int
   392  	size   *int
   393  	total  *int
   394  }
   395  
   396  // Status returns the response status code.
   397  func (r *WifConfigsListResponse) 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 *WifConfigsListResponse) 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 *WifConfigsListResponse) Error() *errors.Error {
   414  	if r == nil {
   415  		return nil
   416  	}
   417  	return r.err
   418  }
   419  
   420  // Items returns the value of the 'items' parameter.
   421  //
   422  // Retrieved list of wif_configs.
   423  func (r *WifConfigsListResponse) Items() *WifConfigList {
   424  	if r == nil {
   425  		return nil
   426  	}
   427  	return r.items
   428  }
   429  
   430  // GetItems returns the value of the 'items' parameter and
   431  // a flag indicating if the parameter has a value.
   432  //
   433  // Retrieved list of wif_configs.
   434  func (r *WifConfigsListResponse) GetItems() (value *WifConfigList, ok bool) {
   435  	ok = r != nil && r.items != nil
   436  	if ok {
   437  		value = r.items
   438  	}
   439  	return
   440  }
   441  
   442  // Page returns the value of the 'page' parameter.
   443  //
   444  // Index of the requested page, where one corresponds to the first page.
   445  func (r *WifConfigsListResponse) Page() int {
   446  	if r != nil && r.page != nil {
   447  		return *r.page
   448  	}
   449  	return 0
   450  }
   451  
   452  // GetPage returns the value of the 'page' parameter and
   453  // a flag indicating if the parameter has a value.
   454  //
   455  // Index of the requested page, where one corresponds to the first page.
   456  func (r *WifConfigsListResponse) GetPage() (value int, ok bool) {
   457  	ok = r != nil && r.page != nil
   458  	if ok {
   459  		value = *r.page
   460  	}
   461  	return
   462  }
   463  
   464  // Size returns the value of the 'size' parameter.
   465  //
   466  // Maximum number of items that will be contained in the returned page.
   467  func (r *WifConfigsListResponse) Size() int {
   468  	if r != nil && r.size != nil {
   469  		return *r.size
   470  	}
   471  	return 0
   472  }
   473  
   474  // GetSize returns the value of the 'size' parameter and
   475  // a flag indicating if the parameter has a value.
   476  //
   477  // Maximum number of items that will be contained in the returned page.
   478  func (r *WifConfigsListResponse) GetSize() (value int, ok bool) {
   479  	ok = r != nil && r.size != nil
   480  	if ok {
   481  		value = *r.size
   482  	}
   483  	return
   484  }
   485  
   486  // Total returns the value of the 'total' parameter.
   487  //
   488  // Total number of items of the collection that match the search criteria,
   489  // regardless of the size of the page.
   490  func (r *WifConfigsListResponse) Total() int {
   491  	if r != nil && r.total != nil {
   492  		return *r.total
   493  	}
   494  	return 0
   495  }
   496  
   497  // GetTotal returns the value of the 'total' parameter and
   498  // a flag indicating if the parameter has a value.
   499  //
   500  // Total number of items of the collection that match the search criteria,
   501  // regardless of the size of the page.
   502  func (r *WifConfigsListResponse) GetTotal() (value int, ok bool) {
   503  	ok = r != nil && r.total != nil
   504  	if ok {
   505  		value = *r.total
   506  	}
   507  	return
   508  }