github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/dns_domains_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  // DNSDomainsClient is the client of the 'DNS_domains' resource.
    36  //
    37  // Manages the collection of DNS domains.
    38  type DNSDomainsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewDNSDomainsClient creates a new client for the 'DNS_domains'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewDNSDomainsClient(transport http.RoundTripper, path string) *DNSDomainsClient {
    47  	return &DNSDomainsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Adds a DNS domain.
    56  func (c *DNSDomainsClient) Add() *DNSDomainsAddRequest {
    57  	return &DNSDomainsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // List creates a request for the 'list' method.
    64  func (c *DNSDomainsClient) List() *DNSDomainsListRequest {
    65  	return &DNSDomainsListRequest{
    66  		transport: c.transport,
    67  		path:      c.path,
    68  	}
    69  }
    70  
    71  // DNSDomain returns the target 'DNS_domain' resource for the given identifier.
    72  //
    73  // Reference to the resource that manages a specific DNS doamin.
    74  func (c *DNSDomainsClient) DNSDomain(id string) *DNSDomainClient {
    75  	return NewDNSDomainClient(
    76  		c.transport,
    77  		path.Join(c.path, id),
    78  	)
    79  }
    80  
    81  // DNSDomainsAddRequest is the request for the 'add' method.
    82  type DNSDomainsAddRequest struct {
    83  	transport http.RoundTripper
    84  	path      string
    85  	query     url.Values
    86  	header    http.Header
    87  	body      *DNSDomain
    88  }
    89  
    90  // Parameter adds a query parameter.
    91  func (r *DNSDomainsAddRequest) Parameter(name string, value interface{}) *DNSDomainsAddRequest {
    92  	helpers.AddValue(&r.query, name, value)
    93  	return r
    94  }
    95  
    96  // Header adds a request header.
    97  func (r *DNSDomainsAddRequest) Header(name string, value interface{}) *DNSDomainsAddRequest {
    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 *DNSDomainsAddRequest) Impersonate(user string) *DNSDomainsAddRequest {
   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 DNS domain.
   112  func (r *DNSDomainsAddRequest) Body(value *DNSDomain) *DNSDomainsAddRequest {
   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 *DNSDomainsAddRequest) Send() (result *DNSDomainsAddResponse, 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 *DNSDomainsAddRequest) SendContext(ctx context.Context) (result *DNSDomainsAddResponse, err error) {
   127  	query := helpers.CopyQuery(r.query)
   128  	header := helpers.CopyHeader(r.header)
   129  	buffer := &bytes.Buffer{}
   130  	err = writeDNSDomainsAddRequest(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 = &DNSDomainsAddResponse{}
   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 = readDNSDomainsAddResponse(result, reader)
   170  	if err != nil {
   171  		return
   172  	}
   173  	return
   174  }
   175  
   176  // DNSDomainsAddResponse is the response for the 'add' method.
   177  type DNSDomainsAddResponse struct {
   178  	status int
   179  	header http.Header
   180  	err    *errors.Error
   181  	body   *DNSDomain
   182  }
   183  
   184  // Status returns the response status code.
   185  func (r *DNSDomainsAddResponse) 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 *DNSDomainsAddResponse) 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 *DNSDomainsAddResponse) 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 DNS domain.
   211  func (r *DNSDomainsAddResponse) Body() *DNSDomain {
   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 DNS domain.
   222  func (r *DNSDomainsAddResponse) GetBody() (value *DNSDomain, ok bool) {
   223  	ok = r != nil && r.body != nil
   224  	if ok {
   225  		value = r.body
   226  	}
   227  	return
   228  }
   229  
   230  // DNSDomainsListRequest is the request for the 'list' method.
   231  type DNSDomainsListRequest 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 *DNSDomainsListRequest) Parameter(name string, value interface{}) *DNSDomainsListRequest {
   243  	helpers.AddValue(&r.query, name, value)
   244  	return r
   245  }
   246  
   247  // Header adds a request header.
   248  func (r *DNSDomainsListRequest) Header(name string, value interface{}) *DNSDomainsListRequest {
   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 *DNSDomainsListRequest) Impersonate(user string) *DNSDomainsListRequest {
   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 *DNSDomainsListRequest) Page(value int) *DNSDomainsListRequest {
   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 dns domain instead of
   274  // the names of the columns of a table. For example, in order to retrieve all the
   275  // dns domains with a ID starting with `02a5` should be:
   276  //
   277  // ```sql
   278  // id like '02a5%'
   279  // ```
   280  //
   281  // If the parameter isn't provided, or if the value is empty, then all the
   282  // dns domains that the user has permission to see will be returned.
   283  func (r *DNSDomainsListRequest) Search(value string) *DNSDomainsListRequest {
   284  	r.search = &value
   285  	return r
   286  }
   287  
   288  // Size sets the value of the 'size' parameter.
   289  //
   290  // Maximum number of items that will be contained in the returned page.
   291  func (r *DNSDomainsListRequest) Size(value int) *DNSDomainsListRequest {
   292  	r.size = &value
   293  	return r
   294  }
   295  
   296  // Send sends this request, waits for the response, and returns it.
   297  //
   298  // This is a potentially lengthy operation, as it requires network communication.
   299  // Consider using a context and the SendContext method.
   300  func (r *DNSDomainsListRequest) Send() (result *DNSDomainsListResponse, err error) {
   301  	return r.SendContext(context.Background())
   302  }
   303  
   304  // SendContext sends this request, waits for the response, and returns it.
   305  func (r *DNSDomainsListRequest) SendContext(ctx context.Context) (result *DNSDomainsListResponse, err error) {
   306  	query := helpers.CopyQuery(r.query)
   307  	if r.page != nil {
   308  		helpers.AddValue(&query, "page", *r.page)
   309  	}
   310  	if r.search != nil {
   311  		helpers.AddValue(&query, "search", *r.search)
   312  	}
   313  	if r.size != nil {
   314  		helpers.AddValue(&query, "size", *r.size)
   315  	}
   316  	header := helpers.CopyHeader(r.header)
   317  	uri := &url.URL{
   318  		Path:     r.path,
   319  		RawQuery: query.Encode(),
   320  	}
   321  	request := &http.Request{
   322  		Method: "GET",
   323  		URL:    uri,
   324  		Header: header,
   325  	}
   326  	if ctx != nil {
   327  		request = request.WithContext(ctx)
   328  	}
   329  	response, err := r.transport.RoundTrip(request)
   330  	if err != nil {
   331  		return
   332  	}
   333  	defer response.Body.Close()
   334  	result = &DNSDomainsListResponse{}
   335  	result.status = response.StatusCode
   336  	result.header = response.Header
   337  	reader := bufio.NewReader(response.Body)
   338  	_, err = reader.Peek(1)
   339  	if err == io.EOF {
   340  		err = nil
   341  		return
   342  	}
   343  	if result.status >= 400 {
   344  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   345  		if err != nil {
   346  			return
   347  		}
   348  		err = result.err
   349  		return
   350  	}
   351  	err = readDNSDomainsListResponse(result, reader)
   352  	if err != nil {
   353  		return
   354  	}
   355  	return
   356  }
   357  
   358  // DNSDomainsListResponse is the response for the 'list' method.
   359  type DNSDomainsListResponse struct {
   360  	status int
   361  	header http.Header
   362  	err    *errors.Error
   363  	items  *DNSDomainList
   364  	page   *int
   365  	size   *int
   366  	total  *int
   367  }
   368  
   369  // Status returns the response status code.
   370  func (r *DNSDomainsListResponse) Status() int {
   371  	if r == nil {
   372  		return 0
   373  	}
   374  	return r.status
   375  }
   376  
   377  // Header returns header of the response.
   378  func (r *DNSDomainsListResponse) Header() http.Header {
   379  	if r == nil {
   380  		return nil
   381  	}
   382  	return r.header
   383  }
   384  
   385  // Error returns the response error.
   386  func (r *DNSDomainsListResponse) Error() *errors.Error {
   387  	if r == nil {
   388  		return nil
   389  	}
   390  	return r.err
   391  }
   392  
   393  // Items returns the value of the 'items' parameter.
   394  //
   395  // Retrieved a list of DNS domains.
   396  func (r *DNSDomainsListResponse) Items() *DNSDomainList {
   397  	if r == nil {
   398  		return nil
   399  	}
   400  	return r.items
   401  }
   402  
   403  // GetItems returns the value of the 'items' parameter and
   404  // a flag indicating if the parameter has a value.
   405  //
   406  // Retrieved a list of DNS domains.
   407  func (r *DNSDomainsListResponse) GetItems() (value *DNSDomainList, ok bool) {
   408  	ok = r != nil && r.items != nil
   409  	if ok {
   410  		value = r.items
   411  	}
   412  	return
   413  }
   414  
   415  // Page returns the value of the 'page' parameter.
   416  //
   417  // Index of the requested page, where one corresponds to the first page.
   418  func (r *DNSDomainsListResponse) Page() int {
   419  	if r != nil && r.page != nil {
   420  		return *r.page
   421  	}
   422  	return 0
   423  }
   424  
   425  // GetPage returns the value of the 'page' parameter and
   426  // a flag indicating if the parameter has a value.
   427  //
   428  // Index of the requested page, where one corresponds to the first page.
   429  func (r *DNSDomainsListResponse) GetPage() (value int, ok bool) {
   430  	ok = r != nil && r.page != nil
   431  	if ok {
   432  		value = *r.page
   433  	}
   434  	return
   435  }
   436  
   437  // Size returns the value of the 'size' parameter.
   438  //
   439  // Maximum number of items that will be contained in the returned page.
   440  func (r *DNSDomainsListResponse) Size() int {
   441  	if r != nil && r.size != nil {
   442  		return *r.size
   443  	}
   444  	return 0
   445  }
   446  
   447  // GetSize returns the value of the 'size' parameter and
   448  // a flag indicating if the parameter has a value.
   449  //
   450  // Maximum number of items that will be contained in the returned page.
   451  func (r *DNSDomainsListResponse) GetSize() (value int, ok bool) {
   452  	ok = r != nil && r.size != nil
   453  	if ok {
   454  		value = *r.size
   455  	}
   456  	return
   457  }
   458  
   459  // Total returns the value of the 'total' parameter.
   460  //
   461  // Total number of items of the collection.
   462  func (r *DNSDomainsListResponse) Total() int {
   463  	if r != nil && r.total != nil {
   464  		return *r.total
   465  	}
   466  	return 0
   467  }
   468  
   469  // GetTotal returns the value of the 'total' parameter and
   470  // a flag indicating if the parameter has a value.
   471  //
   472  // Total number of items of the collection.
   473  func (r *DNSDomainsListResponse) GetTotal() (value int, ok bool) {
   474  	ok = r != nil && r.total != nil
   475  	if ok {
   476  		value = *r.total
   477  	}
   478  	return
   479  }