client

package
v0.0.0-...-85711f0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package client implements a set of common functionality that are used by DC/OS SDK commands to talk to schedulers built using the SDK or other DC/OS components (e.g. Cosmos). Cluster URL and other global values are pulled from the dcos-commons/cli/config package and populated by the values configured using the DC/OS CLI itself.

Index

Constants

This section is empty.

Variables

View Source
var PrintMessage = printMessage

PrintMessage is a placeholder function that wraps a call to fmt.Println(fmt.Sprintf()) to allow assertions against captured output.

View Source
var PrintMessageAndExit = printMessageAndExit

PrintMessageAndExit is a placeholder function that wraps a call to PrintMessage() before exiting to allow assertions against captured output.

Functions

func CheckHTTPResponse

func CheckHTTPResponse(response *http.Response) ([]byte, error)

CheckHTTPResponse checks the HTTP response

func CreateHTTPRawRequest

func CreateHTTPRawRequest(method string, url *url.URL, payload, accept, contentType string) *http.Request

CreateHTTPRawRequest creates an HTTP request

func CreateHTTPURLRequest

func CreateHTTPURLRequest(method string, url *url.URL, payload, accept, contentType string) *http.Request

CreateHTTPURLRequest creates a HTTP url request which includes cluster auth headers as needed.

func CreateServiceHTTPDataRequest

func CreateServiceHTTPDataRequest(method, urlPath, jsonPayload, contentType string) *http.Request

CreateServiceHTTPDataRequest creates a service HTTP data request

func CreateServiceHTTPJSONRequest

func CreateServiceHTTPJSONRequest(method, urlPath, jsonPayload string) *http.Request

CreateServiceHTTPJSONRequest creates a service HTTP JSON request

func CreateServiceHTTPQueryRequest

func CreateServiceHTTPQueryRequest(method, urlPath, urlQuery string) *http.Request

CreateServiceHTTPQueryRequest creates a service HTTP query request

func CreateServiceHTTPRequest

func CreateServiceHTTPRequest(method, urlPath string) *http.Request

CreateServiceHTTPRequest creates a service HTTP request

func CreateServiceURL

func CreateServiceURL(urlPath, urlQuery string) *url.URL

CreateServiceURL creates a service URL of the form http://clusterurl.com/service/<servicename>/<urlPath>[?urlQuery]

func CreateURL

func CreateURL(baseURL, urlPath, urlQuery string) *url.URL

CreateURL creates a URL of the form <baseURL>/<urlPath>[?urlQuery]

func GetDCOSURL

func GetDCOSURL() string

GetDCOSURL gets the DC/OS cluster URL in the form of "http://cluster-host.com"

func GetValueFromJSON

func GetValueFromJSON(jsonBytes map[string]interface{}, field string) ([]byte, error)

GetValueFromJSON retrieves the value of a specific field from an unmarshaled map[string]interface of JSON. If the field does not exist, this returns nil.

func GetValueFromJSONResponse

func GetValueFromJSONResponse(responseBytes []byte, field string) ([]byte, error)

GetValueFromJSONResponse is a utility function to unmarshal a []byte of JSON and fetch the value of a specific field from it.

func HTTPCosmosPostJSON

func HTTPCosmosPostJSON(urlPath, jsonPayload string) ([]byte, error)

HTTPCosmosPostJSON triggers a HTTP POST request containing jsonPayload to https://dcos.cluster/cosmos/service/<urlPath>

func HTTPQuery

func HTTPQuery(request *http.Request) *http.Response

HTTPQuery does a HTTP query

func HTTPServiceDelete

func HTTPServiceDelete(urlPath string) ([]byte, error)

HTTPServiceDelete triggers a HTTP DELETE request to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServiceDeleteData

func HTTPServiceDeleteData(urlPath, payload, contentType string) ([]byte, error)

HTTPServiceDeleteData triggers a HTTP DELETE request with a payload of contentType to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServiceDeleteJSON

func HTTPServiceDeleteJSON(urlPath, jsonPayload string) ([]byte, error)

HTTPServiceDeleteJSON triggers a HTTP DELETE request containing jsonPayload to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServiceDeleteQuery

func HTTPServiceDeleteQuery(urlPath, urlQuery string) ([]byte, error)

HTTPServiceDeleteQuery triggers a HTTP DELETE request with query parameters to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>?<urlQuery>

func HTTPServiceGet

func HTTPServiceGet(urlPath string) ([]byte, error)

HTTPServiceGet triggers a HTTP GET request to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServiceGetData

func HTTPServiceGetData(urlPath, payload, contentType string) ([]byte, error)

HTTPServiceGetData triggers a HTTP GET request with a payload of contentType to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServiceGetJSON

func HTTPServiceGetJSON(urlPath, jsonPayload string) ([]byte, error)

HTTPServiceGetJSON triggers a HTTP GET request containing jsonPayload to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServiceGetQuery

func HTTPServiceGetQuery(urlPath, urlQuery string) ([]byte, error)

HTTPServiceGetQuery triggers a HTTP GET request with query parameters to: <config.DcosURL>/service/<config.ServiceName><urlPath>?<urlQuery>

func HTTPServicePost

func HTTPServicePost(urlPath string) ([]byte, error)

HTTPServicePost triggers a HTTP POST request to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServicePostData

func HTTPServicePostData(urlPath, payload, contentType string) ([]byte, error)

HTTPServicePostData triggers a HTTP POST request with a payload of contentType to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServicePostJSON

func HTTPServicePostJSON(urlPath, jsonPayload string) ([]byte, error)

HTTPServicePostJSON triggers a HTTP POST request containing jsonPayload to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServicePostQuery

func HTTPServicePostQuery(urlPath, urlQuery string) ([]byte, error)

HTTPServicePostQuery triggers a HTTP POST request with query parameters to: <config.DcosURL>/service/<config.ServiceName><urlPath>?<urlQuery>

func HTTPServicePut

func HTTPServicePut(urlPath string) ([]byte, error)

HTTPServicePut triggers a HTTP PUT request to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServicePutData

func HTTPServicePutData(urlPath, payload, contentType string) ([]byte, error)

HTTPServicePutData triggers a HTTP PUT request with a payload of contentType to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServicePutJSON

func HTTPServicePutJSON(urlPath, jsonPayload string) ([]byte, error)

HTTPServicePutJSON triggers a HTTP PUT request containing jsonPayload to: <config.DcosURL>/service/<config.ServiceName>/<urlPath>

func HTTPServicePutQuery

func HTTPServicePutQuery(urlPath, urlQuery string) ([]byte, error)

HTTPServicePutQuery triggers a HTTP PUT request with query parameters to: <config.DcosURL>/service/<config.ServiceName><urlPath>?<urlQuery>

func JSONBytesToArray

func JSONBytesToArray(bytes []byte) ([]string, error)

JSONBytesToArray is a utility method for unmarshaling a JSON string array

func OptionalCLIConfigValue

func OptionalCLIConfigValue(name string) string

OptionalCLIConfigValue retrieves the CLI configuration for name. If no value can be retrieved, this returns an empty string.

func PrettyPrintSlice

func PrettyPrintSlice(slice []string) string

PrettyPrintSlice takes a slice (e.g. [0 1 2]), sorts it and returns a pretty printed string in the same style as a JSON string array (e.g. ["0", "1", "2"]).

func PrintJSONBytes

func PrintJSONBytes(responseBytes []byte)

PrintJSONBytes pretty prints responseBytes assuming it is valid JSON. If not valid, an error message will be printed and the original data will be printed.

func PrintResponseText

func PrintResponseText(body []byte)

PrintResponseText prints out a byte array as text.

func PrintVerbose

func PrintVerbose(format string, a ...interface{}) (int, error)

PrintVerbose prints a message using PrintMessage iff config.Verbose is enabled

func RequiredCLIConfigValue

func RequiredCLIConfigValue(name string, description string, errorInstruction string) string

RequiredCLIConfigValue gets config values from the DC/OS CLI

func RunCLICommand

func RunCLICommand(arg ...string) (string, error)

RunCLICommand runs a DC/OS CLI command

func SetCustomResponseCheck

func SetCustomResponseCheck(check responseCheck)

SetCustomResponseCheck sets a custom responseCheck that can be used for more advanced handling of HTTP responses.

func UnmarshalJSON

func UnmarshalJSON(jsonBytes []byte) (map[string]interface{}, error)

UnmarshalJSON unmarshals a []byte of JSON into a map[string]interface{} for easy handling of JSON responses that have variable fields.

Types

This section is empty.

Jump to

Keyboard shortcuts

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