github.com/openshift-online/ocm-sdk-go@v0.1.473/clustersmgmt/v1/network_verifications_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  // NetworkVerificationsClient is the client of the 'network_verifications' resource.
    36  //
    37  // Manages the collection of subnet network verifications.
    38  type NetworkVerificationsClient struct {
    39  	transport http.RoundTripper
    40  	path      string
    41  }
    42  
    43  // NewNetworkVerificationsClient creates a new client for the 'network_verifications'
    44  // resource using the given transport to send the requests and receive the
    45  // responses.
    46  func NewNetworkVerificationsClient(transport http.RoundTripper, path string) *NetworkVerificationsClient {
    47  	return &NetworkVerificationsClient{
    48  		transport: transport,
    49  		path:      path,
    50  	}
    51  }
    52  
    53  // Add creates a request for the 'add' method.
    54  //
    55  // Creates an entry for a network verification for each subnet supplied setting then to initial state.
    56  func (c *NetworkVerificationsClient) Add() *NetworkVerificationsAddRequest {
    57  	return &NetworkVerificationsAddRequest{
    58  		transport: c.transport,
    59  		path:      c.path,
    60  	}
    61  }
    62  
    63  // NetworkVerification returns the target 'network_verification' resource for the given identifier.
    64  //
    65  // Reference to the service that manages a specific network verification.
    66  func (c *NetworkVerificationsClient) NetworkVerification(id string) *NetworkVerificationClient {
    67  	return NewNetworkVerificationClient(
    68  		c.transport,
    69  		path.Join(c.path, id),
    70  	)
    71  }
    72  
    73  // NetworkVerificationsAddRequest is the request for the 'add' method.
    74  type NetworkVerificationsAddRequest struct {
    75  	transport http.RoundTripper
    76  	path      string
    77  	query     url.Values
    78  	header    http.Header
    79  	body      *NetworkVerification
    80  }
    81  
    82  // Parameter adds a query parameter.
    83  func (r *NetworkVerificationsAddRequest) Parameter(name string, value interface{}) *NetworkVerificationsAddRequest {
    84  	helpers.AddValue(&r.query, name, value)
    85  	return r
    86  }
    87  
    88  // Header adds a request header.
    89  func (r *NetworkVerificationsAddRequest) Header(name string, value interface{}) *NetworkVerificationsAddRequest {
    90  	helpers.AddHeader(&r.header, name, value)
    91  	return r
    92  }
    93  
    94  // Impersonate wraps requests on behalf of another user.
    95  // Note: Services that do not support this feature may silently ignore this call.
    96  func (r *NetworkVerificationsAddRequest) Impersonate(user string) *NetworkVerificationsAddRequest {
    97  	helpers.AddImpersonationHeader(&r.header, user)
    98  	return r
    99  }
   100  
   101  // Body sets the value of the 'body' parameter.
   102  func (r *NetworkVerificationsAddRequest) Body(value *NetworkVerification) *NetworkVerificationsAddRequest {
   103  	r.body = value
   104  	return r
   105  }
   106  
   107  // Send sends this request, waits for the response, and returns it.
   108  //
   109  // This is a potentially lengthy operation, as it requires network communication.
   110  // Consider using a context and the SendContext method.
   111  func (r *NetworkVerificationsAddRequest) Send() (result *NetworkVerificationsAddResponse, err error) {
   112  	return r.SendContext(context.Background())
   113  }
   114  
   115  // SendContext sends this request, waits for the response, and returns it.
   116  func (r *NetworkVerificationsAddRequest) SendContext(ctx context.Context) (result *NetworkVerificationsAddResponse, err error) {
   117  	query := helpers.CopyQuery(r.query)
   118  	header := helpers.CopyHeader(r.header)
   119  	buffer := &bytes.Buffer{}
   120  	err = writeNetworkVerificationsAddRequest(r, buffer)
   121  	if err != nil {
   122  		return
   123  	}
   124  	uri := &url.URL{
   125  		Path:     r.path,
   126  		RawQuery: query.Encode(),
   127  	}
   128  	request := &http.Request{
   129  		Method: "POST",
   130  		URL:    uri,
   131  		Header: header,
   132  		Body:   io.NopCloser(buffer),
   133  	}
   134  	if ctx != nil {
   135  		request = request.WithContext(ctx)
   136  	}
   137  	response, err := r.transport.RoundTrip(request)
   138  	if err != nil {
   139  		return
   140  	}
   141  	defer response.Body.Close()
   142  	result = &NetworkVerificationsAddResponse{}
   143  	result.status = response.StatusCode
   144  	result.header = response.Header
   145  	reader := bufio.NewReader(response.Body)
   146  	_, err = reader.Peek(1)
   147  	if err == io.EOF {
   148  		err = nil
   149  		return
   150  	}
   151  	if result.status >= 400 {
   152  		result.err, err = errors.UnmarshalErrorStatus(reader, result.status)
   153  		if err != nil {
   154  			return
   155  		}
   156  		err = result.err
   157  		return
   158  	}
   159  	err = readNetworkVerificationsAddResponse(result, reader)
   160  	if err != nil {
   161  		return
   162  	}
   163  	return
   164  }
   165  
   166  // NetworkVerificationsAddResponse is the response for the 'add' method.
   167  type NetworkVerificationsAddResponse struct {
   168  	status int
   169  	header http.Header
   170  	err    *errors.Error
   171  	body   *NetworkVerification
   172  }
   173  
   174  // Status returns the response status code.
   175  func (r *NetworkVerificationsAddResponse) Status() int {
   176  	if r == nil {
   177  		return 0
   178  	}
   179  	return r.status
   180  }
   181  
   182  // Header returns header of the response.
   183  func (r *NetworkVerificationsAddResponse) Header() http.Header {
   184  	if r == nil {
   185  		return nil
   186  	}
   187  	return r.header
   188  }
   189  
   190  // Error returns the response error.
   191  func (r *NetworkVerificationsAddResponse) Error() *errors.Error {
   192  	if r == nil {
   193  		return nil
   194  	}
   195  	return r.err
   196  }
   197  
   198  // Body returns the value of the 'body' parameter.
   199  func (r *NetworkVerificationsAddResponse) Body() *NetworkVerification {
   200  	if r == nil {
   201  		return nil
   202  	}
   203  	return r.body
   204  }
   205  
   206  // GetBody returns the value of the 'body' parameter and
   207  // a flag indicating if the parameter has a value.
   208  func (r *NetworkVerificationsAddResponse) GetBody() (value *NetworkVerification, ok bool) {
   209  	ok = r != nil && r.body != nil
   210  	if ok {
   211  		value = r.body
   212  	}
   213  	return
   214  }