github.com/openshift-online/ocm-sdk-go@v0.1.473/servicelogs/v1/cluster_logs_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/servicelogs/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  // ClusterLogsClient is the client of the 'cluster_logs' resource.
    36  //
    37  // Manages the collection of cluster logs.
    38  type ClusterLogsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewClusterLogsClient creates a new client for the 'cluster_logs'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewClusterLogsClient(transport http.RoundTripper, path string) *ClusterLogsClient {
    47  	return &ClusterLogsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Creates a new log entry.
    56  func (c *ClusterLogsClient) Add() *ClusterLogsAddRequest {
    57  	return &ClusterLogsAddRequest{
    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 cluster logs.
    66  // Use this endpoint to list service logs (including private logs).
    67  // This endpoint is limited to users who allowed to view private logs.
    68  func (c *ClusterLogsClient) List() *ClusterLogsListRequest {
    69  	return &ClusterLogsListRequest{
    70  		transport: c.transport,
    71  		path:      c.path,
    72  	}
    73  }
    74  
    75  // LogEntry returns the target 'log_entry' resource for the given identifier.
    76  //
    77  // Reference to the service that manages a specific Log entry.
    78  func (c *ClusterLogsClient) LogEntry(id string) *LogEntryClient {
    79  	return NewLogEntryClient(
    80  		c.transport,
    81  		path.Join(c.path, id),
    82  	)
    83  }
    84  
    85  // ClusterLogsAddRequest is the request for the 'add' method.
    86  type ClusterLogsAddRequest struct {
    87  	transport http.RoundTripper
    88  	path      string
    89  	query     url.Values
    90  	header    http.Header
    91  	body      *LogEntry
    92  }
    93  
    94  // Parameter adds a query parameter.
    95  func (r *ClusterLogsAddRequest) Parameter(name string, value interface{}) *ClusterLogsAddRequest {
    96  	helpers.AddValue(&r.query, name, value)
    97  	return r
    98  }
    99  
   100  // Header adds a request header.
   101  func (r *ClusterLogsAddRequest) Header(name string, value interface{}) *ClusterLogsAddRequest {
   102  	helpers.AddHeader(&r.header, name, value)
   103  	return r
   104  }
   105  
   106  // Impersonate wraps requests on behalf of another user.
   107  // Note: Services that do not support this feature may silently ignore this call.
   108  func (r *ClusterLogsAddRequest) Impersonate(user string) *ClusterLogsAddRequest {
   109  	helpers.AddImpersonationHeader(&r.header, user)
   110  	return r
   111  }
   112  
   113  // Body sets the value of the 'body' parameter.
   114  //
   115  // Log entry data.
   116  func (r *ClusterLogsAddRequest) Body(value *LogEntry) *ClusterLogsAddRequest {
   117  	r.body = value
   118  	return r
   119  }
   120  
   121  // Send sends this request, waits for the response, and returns it.
   122  //
   123  // This is a potentially lengthy operation, as it requires network communication.
   124  // Consider using a context and the SendContext method.
   125  func (r *ClusterLogsAddRequest) Send() (result *ClusterLogsAddResponse, err error) {
   126  	return r.SendContext(context.Background())
   127  }
   128  
   129  // SendContext sends this request, waits for the response, and returns it.
   130  func (r *ClusterLogsAddRequest) SendContext(ctx context.Context) (result *ClusterLogsAddResponse, err error) {
   131  	query := helpers.CopyQuery(r.query)
   132  	header := helpers.CopyHeader(r.header)
   133  	buffer := &bytes.Buffer{}
   134  	err = writeClusterLogsAddRequest(r, buffer)
   135  	if err != nil {
   136  		return
   137  	}
   138  	uri := &url.URL{
   139  		Path:     r.path,
   140  		RawQuery: query.Encode(),
   141  	}
   142  	request := &http.Request{
   143  		Method: "POST",
   144  		URL:    uri,
   145  		Header: header,
   146  		Body:   io.NopCloser(buffer),
   147  	}
   148  	if ctx != nil {
   149  		request = request.WithContext(ctx)
   150  	}
   151  	response, err := r.transport.RoundTrip(request)
   152  	if err != nil {
   153  		return
   154  	}
   155  	defer response.Body.Close()
   156  	result = &ClusterLogsAddResponse{}
   157  	result.status = response.StatusCode
   158  	result.header = response.Header
   159  	reader := bufio.NewReader(response.Body)
   160  	_, err = reader.Peek(1)
   161  	if err == io.EOF {
   162  		err = nil
   163  		return
   164  	}
   165  	if result.status >= 400 {
   166  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   167  		if err != nil {
   168  			return
   169  		}
   170  		err = result.err
   171  		return
   172  	}
   173  	err = readClusterLogsAddResponse(result, reader)
   174  	if err != nil {
   175  		return
   176  	}
   177  	return
   178  }
   179  
   180  // ClusterLogsAddResponse is the response for the 'add' method.
   181  type ClusterLogsAddResponse struct {
   182  	status int
   183  	header http.Header
   184  	err    *errors.Error
   185  	body   *LogEntry
   186  }
   187  
   188  // Status returns the response status code.
   189  func (r *ClusterLogsAddResponse) Status() int {
   190  	if r == nil {
   191  		return 0
   192  	}
   193  	return r.status
   194  }
   195  
   196  // Header returns header of the response.
   197  func (r *ClusterLogsAddResponse) Header() http.Header {
   198  	if r == nil {
   199  		return nil
   200  	}
   201  	return r.header
   202  }
   203  
   204  // Error returns the response error.
   205  func (r *ClusterLogsAddResponse) Error() *errors.Error {
   206  	if r == nil {
   207  		return nil
   208  	}
   209  	return r.err
   210  }
   211  
   212  // Body returns the value of the 'body' parameter.
   213  //
   214  // Log entry data.
   215  func (r *ClusterLogsAddResponse) Body() *LogEntry {
   216  	if r == nil {
   217  		return nil
   218  	}
   219  	return r.body
   220  }
   221  
   222  // GetBody returns the value of the 'body' parameter and
   223  // a flag indicating if the parameter has a value.
   224  //
   225  // Log entry data.
   226  func (r *ClusterLogsAddResponse) GetBody() (value *LogEntry, ok bool) {
   227  	ok = r != nil && r.body != nil
   228  	if ok {
   229  		value = r.body
   230  	}
   231  	return
   232  }
   233  
   234  // ClusterLogsListRequest is the request for the 'list' method.
   235  type ClusterLogsListRequest struct {
   236  	transport http.RoundTripper
   237  	path      string
   238  	query     url.Values
   239  	header    http.Header
   240  	order     *string
   241  	page      *int
   242  	search    *string
   243  	size      *int
   244  }
   245  
   246  // Parameter adds a query parameter.
   247  func (r *ClusterLogsListRequest) Parameter(name string, value interface{}) *ClusterLogsListRequest {
   248  	helpers.AddValue(&r.query, name, value)
   249  	return r
   250  }
   251  
   252  // Header adds a request header.
   253  func (r *ClusterLogsListRequest) Header(name string, value interface{}) *ClusterLogsListRequest {
   254  	helpers.AddHeader(&r.header, name, value)
   255  	return r
   256  }
   257  
   258  // Impersonate wraps requests on behalf of another user.
   259  // Note: Services that do not support this feature may silently ignore this call.
   260  func (r *ClusterLogsListRequest) Impersonate(user string) *ClusterLogsListRequest {
   261  	helpers.AddImpersonationHeader(&r.header, user)
   262  	return r
   263  }
   264  
   265  // Order sets the value of the 'order' parameter.
   266  //
   267  // Order criteria.
   268  //
   269  // The syntax of this parameter is similar to the syntax of the _order by_ clause of
   270  // a SQL statement. For example, in order to sort the
   271  // cluster logs descending by name identifier the value should be:
   272  //
   273  // ```sql
   274  // name desc
   275  // ```
   276  //
   277  // If the parameter isn't provided, or if the value is empty, then the order of the
   278  // results is undefined.
   279  func (r *ClusterLogsListRequest) Order(value string) *ClusterLogsListRequest {
   280  	r.order = &value
   281  	return r
   282  }
   283  
   284  // Page sets the value of the 'page' parameter.
   285  //
   286  // Index of the requested page, where one corresponds to the first page.
   287  func (r *ClusterLogsListRequest) Page(value int) *ClusterLogsListRequest {
   288  	r.page = &value
   289  	return r
   290  }
   291  
   292  // Search sets the value of the 'search' parameter.
   293  //
   294  // Search criteria.
   295  //
   296  // The syntax of this parameter is similar to the syntax of the _where_ clause
   297  // of an SQL statement, but using the names of the attributes of the cluster logs
   298  // instead of the names of the columns of a table. For example, in order to
   299  // retrieve cluster logs with service_name starting with my:
   300  //
   301  // ```sql
   302  // service_name like 'my%'
   303  // ```
   304  //
   305  // If the parameter isn't provided, or if the value is empty, then all the
   306  // items that the user has permission to see will be returned.
   307  func (r *ClusterLogsListRequest) Search(value string) *ClusterLogsListRequest {
   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 *ClusterLogsListRequest) Size(value int) *ClusterLogsListRequest {
   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 *ClusterLogsListRequest) Send() (result *ClusterLogsListResponse, 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 *ClusterLogsListRequest) SendContext(ctx context.Context) (result *ClusterLogsListResponse, 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 = &ClusterLogsListResponse{}
   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 = readClusterLogsListResponse(result, reader)
   379  	if err != nil {
   380  		return
   381  	}
   382  	return
   383  }
   384  
   385  // ClusterLogsListResponse is the response for the 'list' method.
   386  type ClusterLogsListResponse struct {
   387  	status int
   388  	header http.Header
   389  	err    *errors.Error
   390  	items  *LogEntryList
   391  	page   *int
   392  	size   *int
   393  	total  *int
   394  }
   395  
   396  // Status returns the response status code.
   397  func (r *ClusterLogsListResponse) 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 *ClusterLogsListResponse) 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 *ClusterLogsListResponse) 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 Cluster logs.
   423  func (r *ClusterLogsListResponse) Items() *LogEntryList {
   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 Cluster logs.
   434  func (r *ClusterLogsListResponse) GetItems() (value *LogEntryList, 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 *ClusterLogsListResponse) 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 *ClusterLogsListResponse) 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 *ClusterLogsListResponse) 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 *ClusterLogsListResponse) 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 *ClusterLogsListResponse) 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 *ClusterLogsListResponse) GetTotal() (value int, ok bool) {
   503  	ok = r != nil && r.total != nil
   504  	if ok {
   505  		value = *r.total
   506  	}
   507  	return
   508  }