restclient

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2024 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionProfile

type ConnectionProfile struct {
	// TODO: add certs in addition to basic authentication
	// TODO: Add Timeout (currently hardcoded to 10 seconds)
	Hostname              string
	Username              string
	Password              string
	ValidateCerts         bool
	MaxConcurrentRequests int
}

ConnectionProfile describes out to reach a cluster or svm

type Job

type Job struct {
	State   string
	Error   jobError
	Code    int
	Message string
}

Job is ONTAP API job data structure

type MockResponse

type MockResponse struct {
	ExpectedMethod string
	ExpectedURL    string
	StatusCode     int
	Response       RestResponse
	Err            error
}

MockResponse is used in Unit Testing to mock expected REST responses. It validate sthat the request matches ExpectedMethod and ExpectedURL, to return the other elements.

type RestClient

type RestClient struct {
	// contains filtered or unexported fields
}

RestClient to interact with the ONTAP REST API

func NewClient

func NewClient(ctx context.Context, cxProfile ConnectionProfile, tag string, jobCompletionTimeOut int) (*RestClient, error)

NewClient creates a new REST client and a supporting HTTP client

func NewMockedRestClient

func NewMockedRestClient(responses []MockResponse) (*RestClient, error)

NewMockedRestClient is used in Unit Testing to mock expected REST responses.

func (*RestClient) CallCreateMethod

func (r *RestClient) CallCreateMethod(baseURL string, query *RestQuery, body map[string]interface{}) (int, RestResponse, error)

CallCreateMethod returns response from POST results. An error is reported if an error is received.

func (*RestClient) CallDeleteMethod

func (r *RestClient) CallDeleteMethod(baseURL string, query *RestQuery, body map[string]interface{}) (int, RestResponse, error)

CallDeleteMethod returns response from DELETE results. An error is reported if an error is received.

func (*RestClient) CallUpdateMethod

func (r *RestClient) CallUpdateMethod(baseURL string, query *RestQuery, body map[string]interface{}) (int, RestResponse, error)

CallUpdateMethod returns response from PATCH results. An error is reported if an error is received.

func (*RestClient) Equals

func (r *RestClient) Equals(r2 *RestClient) (ok bool, firstDiff string)

Equals is a test function for Unit Testing

func (*RestClient) GetNilOrOneRecord

func (r *RestClient) GetNilOrOneRecord(baseURL string, query *RestQuery, body map[string]interface{}) (int, map[string]interface{}, error)

GetNilOrOneRecord returns nil if no record is found or a single record. An error is reported if multiple records are received.

func (*RestClient) GetZeroOrMoreRecords

func (r *RestClient) GetZeroOrMoreRecords(baseURL string, query *RestQuery, body map[string]interface{}) (int, []map[string]interface{}, error)

GetZeroOrMoreRecords returns a list of records.

func (*RestClient) NewQuery

func (r *RestClient) NewQuery() *RestQuery

NewQuery is used to provide query parameters. Set and Add functions are inherited from url.Values

func (*RestClient) Wait

func (r *RestClient) Wait(uuid string) (int, RestResponse, error)

Wait waits for job to finish.

type RestError

type RestError struct {
	Code    string
	Message string
	Target  string
}

RestError maps the REST error structure

type RestQuery

type RestQuery struct {
	url.Values
}

RestQuery is a wrapper around urlValues, and supports a Fields method in addition to Set, Add.

func (*RestQuery) Fields

func (q *RestQuery) Fields(fields []string)

Fields adds a list of fields to query

func (*RestQuery) SetValues

func (q *RestQuery) SetValues(keyValues map[string]interface{})

SetValues adds a set of key, value

type RestResponse

type RestResponse struct {
	NumRecords int `mapstructure:"num_records"`
	Records    []map[string]interface{}
	RestError  RestError `mapstructure:"error"`
	StatusCode int
	HTTPError  string
	ErrorType  string
	Job        map[string]interface{}
	Jobs       []map[string]interface{}
}

RestResponse to return a list of records (can be empty) and/or errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL