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