core

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: Apache-2.0 Imports: 26 Imported by: 23

Documentation

Overview

Package core contains functionality used by Go SDK's generated by the IBM OpenAPI 3 SDK Generator (openapi-sdkgen). Authenticators

The go-sdk-core project supports the following types of authentication:

Basic Authentication
Bearer Token
Identity and Access Management (IAM)
Cloud Pak for Data
No Authentication

The authentication types that are appropriate for a particular service may vary from service to service. Each authentication type is implemented as an Authenticator for consumption by a service. To read more about authenticators and how to use them see here: https://github.com/IBM/go-sdk-core/blob/master/Authentication.md

Services

Services are the API clients generated by the IBM OpenAPI 3 SDK Generator. These services make use of the code within the core package BaseService instances to perform service operations.

Index

Constants

View Source
const (
	// IBM_CREDENTIAL_FILE_ENVVAR is the environment key used to find the path to
	// a credentials file.
	IBM_CREDENTIAL_FILE_ENVVAR = "IBM_CREDENTIALS_FILE"

	// DEFAULT_CREDENTIAL_FILE_NAME is the default filename for a credentials file.
	// It is used when "IBM_CREDENTIALS_FILE" is not specified. The filename will
	// be searched for within the program's working directory, and then the OS's
	// current user directory.
	DEFAULT_CREDENTIAL_FILE_NAME = "ibm-credentials.env"
)
View Source
const (
	// Supported authentication types.
	AUTHTYPE_BASIC        = "basic"
	AUTHTYPE_BEARER_TOKEN = "bearerToken"
	AUTHTYPE_NOAUTH       = "noAuth"
	AUTHTYPE_IAM          = "iam"
	AUTHTYPE_CP4D         = "cp4d"

	// Service client properties.
	PROPNAME_SVC_URL         = "URL"
	PROPNAME_SVC_DISABLE_SSL = "DISABLE_SSL"

	// Authenticator properties.
	PROPNAME_AUTH_TYPE        = "AUTH_TYPE"
	PROPNAME_USERNAME         = "USERNAME"
	PROPNAME_PASSWORD         = "PASSWORD"
	PROPNAME_BEARER_TOKEN     = "BEARER_TOKEN"
	PROPNAME_AUTH_URL         = "AUTH_URL"
	PROPNAME_AUTH_DISABLE_SSL = "AUTH_DISABLE_SSL"
	PROPNAME_APIKEY           = "APIKEY"
	PROPNAME_CLIENT_ID        = "CLIENT_ID"
	PROPNAME_CLIENT_SECRET    = "CLIENT_SECRET"

	// SSL error
	SSL_CERTIFICATION_ERROR = "x509: certificate"

	// Common error messages.
	ERRORMSG_PROP_MISSING            = "The %s property is required but was not specified."
	ERRORMSG_PROP_INVALID            = "The %s property is invalid. Please remove any surrounding {, }, or \" characters."
	ERRORMSG_NO_AUTHENTICATOR        = "Authentication information was not properly configured."
	ERRORMSG_AUTHTYPE_UNKNOWN        = "Unrecognized authentication type: %s"
	ERRORMSG_PROPS_MAP_NIL           = "The 'properties' map cannot be nil."
	ERRORMSG_SSL_VERIFICATION_FAILED = "The connection failed because the SSL certificate is not valid. To use a " +
		"self-signed certificate, disable verification of the server's SSL certificate " +
		"by invoking the DisableSSLVerification() function on your service instance " +
		"and/or use the DisableSSLVerification option of the authenticator."
)
View Source
const (
	DEFAULT_IAM_URL             = "https://iam.cloud.ibm.com/identity/token"
	DEFAULT_CONTENT_TYPE        = "application/x-www-form-urlencoded"
	REQUEST_TOKEN_GRANT_TYPE    = "urn:ibm:params:oauth:grant-type:apikey"
	REQUEST_TOKEN_RESPONSE_TYPE = "cloud_iam"
)

IamAuthenticator-related constants.

View Source
const (
	POST   = http.MethodPost
	GET    = http.MethodGet
	DELETE = http.MethodDelete
	PUT    = http.MethodPut
	PATCH  = http.MethodPatch
	HEAD   = http.MethodHead
)

common HTTP methods

View Source
const (
	Accept                  = "Accept"
	APPLICATION_JSON        = "application/json"
	CONTENT_DISPOSITION     = "Content-Disposition"
	CONTENT_TYPE            = "Content-Type"
	FORM_URL_ENCODED_HEADER = "application/x-www-form-urlencoded"

	ERRORMSG_SERVICE_URL_MISSING = "The service URL is required."
	ERRORMSG_SERVICE_URL_INVALID = "There was an error parsing the service URL: %s"
)

common headers

View Source
const (
	PRE_AUTH_PATH = "/v1/preauth/validateAuth"
)

Constants for CP4D

Variables

Validate is a shared validator instance used to perform validation of structs.

Functions

func BoolPtr

func BoolPtr(literal bool) *bool

BoolPtr returns a pointer to boolean literal.

func CopyMap

func CopyMap(m map[string]interface{}) map[string]interface{}

CopyMap returns a shallow copy of the specified map. The returned map contains a copy of the mappings found in the original map, but uses values from the original map.

func Float32Ptr

func Float32Ptr(literal float32) *float32

Float32Ptr returns a pointer to float32 literal.

func Float64Ptr

func Float64Ptr(literal float64) *float64

Float64Ptr returns a pointer to float64 literal.

func GetCurrentTime

func GetCurrentTime() int64

GetCurrentTime returns the current Unix time.

func HasBadFirstOrLastChar

func HasBadFirstOrLastChar(str string) bool

HasBadFirstOrLastChar checks if the string starts with `{` or `"` or ends with `}` or `"`.

func Int64Ptr

func Int64Ptr(literal int64) *int64

Int64Ptr returns a pointer to int64 literal.

func IsJSONMimeType

func IsJSONMimeType(mimeType string) bool

IsJSONMimeType Returns true iff the specified mimeType value represents a "JSON" mimetype.

func IsJSONPatchMimeType

func IsJSONPatchMimeType(mimeType string) bool

IsJSONPatchMimeType returns true iff the specified mimeType value represents a "JSON Patch" mimetype.

func PrettyPrint

func PrettyPrint(result interface{}, resultName string)

PrettyPrint print pretty.

func StringNilMapper

func StringNilMapper(s *string) string

StringNilMapper de-references the parameter 's' and returns the result, or "" if 's' is nil.

func StringPtr

func StringPtr(literal string) *string

StringPtr returns a pointer to string literal.

func SystemInfo

func SystemInfo() string

SystemInfo returns the system information.

func UnmarshalAny added in v3.2.0

func UnmarshalAny(m map[string]interface{}, propertyName string) (result interface{}, err error)

UnmarshalAny retrieves the specified property from the map and returns it as a generic value (i.e. interface{}), or nil if the property wasn't found in the map.

func UnmarshalAnyMap added in v3.3.0

func UnmarshalAnyMap(m map[string]interface{}, propertyName string) (result map[string]interface{}, err error)

UnmarshalAnyMap retrieves the specified property from the map "m" and returns it as a map[string]interface{}, or nil if the property wasn't found in the map.

func UnmarshalAnyMapSlice added in v3.3.0

func UnmarshalAnyMapSlice(m map[string]interface{}, propertyName string) (slice []map[string]interface{}, err error)

UnmarshalAnyMapSlice retrieves the specified property from the map "m" and returns it as a []map[string]interface{}, or nil if the property wasn't found in the map.

func UnmarshalAnySlice added in v3.2.0

func UnmarshalAnySlice(m map[string]interface{}, propertyName string) (slice []interface{}, err error)

UnmarshalAnySlice retrieves the specified property from the map and returns it as a slice of generic values (i.e. []interface{}), or nil if the property wasn't found in the map.

func UnmarshalBool

func UnmarshalBool(m map[string]interface{}, propertyName string) (result *bool, err error)

UnmarshalBool retrieves the specified property from the map and returns it as a bool or nil if the property wasn't found in the map.

func UnmarshalBoolMap added in v3.3.0

func UnmarshalBoolMap(m map[string]interface{}, propertyName string) (result map[string]bool, err error)

UnmarshalBoolMap retrieves the specified property from the map "m" and returns it as a map[string]bool, or nil if the property wasn't found in the map.

func UnmarshalBoolMapSlice added in v3.3.0

func UnmarshalBoolMapSlice(m map[string]interface{}, propertyName string) (slice []map[string]bool, err error)

UnmarshalBoolMapSlice retrieves the specified property from the map "m" and returns it as a []map[string]bool, or nil if the property wasn't found in the map.

func UnmarshalBoolSlice

func UnmarshalBoolSlice(m map[string]interface{}, propertyName string) (slice []bool, err error)

UnmarshalBoolSlice retrieves the specified property from the map and returns it as a bool slice or nil if the property wasn't found in the map.

func UnmarshalByteArray

func UnmarshalByteArray(m map[string]interface{}, propertyName string) (result *[]byte, err error)

UnmarshalByteArray retrieves the specified property from the map and returns it as a byte array or nil if the property wasn't found in the map.

func UnmarshalByteArrayMap added in v3.3.0

func UnmarshalByteArrayMap(m map[string]interface{}, propertyName string) (result map[string][]byte, err error)

UnmarshalByteArrayMap retrieves the specified property from the map "m" and returns it as a map[string][]byte, or nil if the property wasn't found in the map.

func UnmarshalByteArrayMapSlice added in v3.3.0

func UnmarshalByteArrayMapSlice(m map[string]interface{}, propertyName string) (slice []map[string][]byte, err error)

UnmarshalByteArrayMapSlice retrieves the specified property from the map "m" and returns it as a []map[string][]byte, or nil if the property wasn't found in the map.

func UnmarshalByteArraySlice

func UnmarshalByteArraySlice(m map[string]interface{}, propertyName string) (slice [][]byte, err error)

UnmarshalByteArraySlice retrieves the specified property from the map and returns it as a byte array slice or nil if the property wasn't found in the map.

func UnmarshalDate

func UnmarshalDate(m map[string]interface{}, propertyName string) (result *strfmt.Date, err error)

UnmarshalDate retrieves the specified property from the map and returns it as a Date or nil if the property wasn't found in the map.

func UnmarshalDateMap added in v3.3.0

func UnmarshalDateMap(m map[string]interface{}, propertyName string) (result map[string]strfmt.Date, err error)

UnmarshalDateMap retrieves the specified property from the map "m" and returns it as a map[string]strfmt.Date, or nil if the property wasn't found in the map.

func UnmarshalDateMapSlice added in v3.3.0

func UnmarshalDateMapSlice(m map[string]interface{}, propertyName string) (slice []map[string]strfmt.Date, err error)

UnmarshalDateMapSlice retrieves the specified property from the map "m" and returns it as a []map[string]strfmt.Date, or nil if the property wasn't found in the map.

func UnmarshalDateSlice

func UnmarshalDateSlice(m map[string]interface{}, propertyName string) (slice []strfmt.Date, err error)

UnmarshalDateSlice retrieves the specified property from the map and returns it as a Date slice or nil if the property wasn't found in the map.

func UnmarshalDateTime

func UnmarshalDateTime(m map[string]interface{}, propertyName string) (result *strfmt.DateTime, err error)

UnmarshalDateTime retrieves the specified property from the map and returns it as a DateTime or nil if the property wasn't found in the map.

func UnmarshalDateTimeMap added in v3.3.0

func UnmarshalDateTimeMap(m map[string]interface{}, propertyName string) (result map[string]strfmt.DateTime, err error)

UnmarshalDateTimeMap retrieves the specified property from the map "m" and returns it as a map[string]strfmt.DateTime, or nil if the property wasn't found in the map.

func UnmarshalDateTimeMapSlice added in v3.3.0

func UnmarshalDateTimeMapSlice(m map[string]interface{}, propertyName string) (slice []map[string]strfmt.DateTime, err error)

UnmarshalDateTimeMapSlice retrieves the specified property from the map "m" and returns it as a []map[string]strfmt.DateTime, or nil if the property wasn't found in the map.

func UnmarshalDateTimeSlice

func UnmarshalDateTimeSlice(m map[string]interface{}, propertyName string) (slice []strfmt.DateTime, err error)

UnmarshalDateTimeSlice retrieves the specified property from the map and returns it as a DateTime slice or nil if the property wasn't found in the map.

func UnmarshalFloat32

func UnmarshalFloat32(m map[string]interface{}, propertyName string) (result *float32, err error)

UnmarshalFloat32 retrieves the specified property from the map and returns it as a float32 or nil if the property wasn't found in the map.

func UnmarshalFloat32Map added in v3.3.0

func UnmarshalFloat32Map(m map[string]interface{}, propertyName string) (result map[string]float32, err error)

UnmarshalFloat32Map retrieves the specified property from the map "m" and returns it as a map[string]float32, or nil if the property wasn't found in the map.

func UnmarshalFloat32MapSlice added in v3.3.0

func UnmarshalFloat32MapSlice(m map[string]interface{}, propertyName string) (slice []map[string]float32, err error)

UnmarshalFloat32MapSlice retrieves the specified property from the map "m" and returns it as a []map[string]float32, or nil if the property wasn't found in the map.

func UnmarshalFloat32Slice

func UnmarshalFloat32Slice(m map[string]interface{}, propertyName string) (slice []float32, err error)

UnmarshalFloat32Slice retrieves the specified property from the map and returns it as a float32 slice or nil if the property wasn't found in the map.

func UnmarshalFloat64

func UnmarshalFloat64(m map[string]interface{}, propertyName string) (result *float64, err error)

UnmarshalFloat64 retrieves the specified property from the map and returns it as a float64 or nil if the property wasn't found in the map.

func UnmarshalFloat64Map added in v3.3.0

func UnmarshalFloat64Map(m map[string]interface{}, propertyName string) (result map[string]float64, err error)

UnmarshalFloat64Map retrieves the specified property from the map "m" and returns it as a map[string]float64, or nil if the property wasn't found in the map.

func UnmarshalFloat64MapSlice added in v3.3.0

func UnmarshalFloat64MapSlice(m map[string]interface{}, propertyName string) (slice []map[string]float64, err error)

UnmarshalFloat64MapSlice retrieves the specified property from the map "m" and returns it as a []map[string]float64, or nil if the property wasn't found in the map.

func UnmarshalFloat64Slice

func UnmarshalFloat64Slice(m map[string]interface{}, propertyName string) (slice []float64, err error)

UnmarshalFloat64Slice retrieves the specified property from the map and returns it as a float64 slice or nil if the property wasn't found in the map.

func UnmarshalInt64

func UnmarshalInt64(m map[string]interface{}, propertyName string) (result *int64, err error)

UnmarshalInt64 retrieves the specified property from the map and returns it as an int64 or nil if the property wasn't found in the map.

func UnmarshalInt64Map added in v3.3.0

func UnmarshalInt64Map(m map[string]interface{}, propertyName string) (result map[string]int64, err error)

UnmarshalInt64Map retrieves the specified property from the map "m" and returns it as a map[string]int64, or nil if the property wasn't found in the map.

func UnmarshalInt64MapSlice added in v3.3.0

func UnmarshalInt64MapSlice(m map[string]interface{}, propertyName string) (slice []map[string]int64, err error)

UnmarshalInt64MapSlice retrieves the specified property from the map "m" and returns it as a []map[string]int64, or nil if the property wasn't found in the map.

func UnmarshalInt64Slice

func UnmarshalInt64Slice(m map[string]interface{}, propertyName string) (slice []int64, err error)

UnmarshalInt64Slice retrieves the specified property from the map and returns it as an int64 slice or nil if the property wasn't found in the map.

func UnmarshalObject

func UnmarshalObject(m map[string]interface{}, propertyName string) (result map[string]interface{}, err error)

UnmarshalObject retrieves the specified property from the map and returns it as a generic object (i.e. map[string]interface{}), or nil if the property wasn't found in the map.

func UnmarshalObjectSlice

func UnmarshalObjectSlice(m map[string]interface{}, propertyName string) (slice []map[string]interface{}, err error)

UnmarshalObjectSlice retrieves the specified property from the map and returns it as a slice of generic objects (i.e. []map[string]interface{}), or nil if the property wasn't found in the map.

func UnmarshalString

func UnmarshalString(m map[string]interface{}, propertyName string) (result *string, err error)

UnmarshalString retrieves the specified property from the map and returns it as a string or nil if the property wasn't found in the map.

func UnmarshalStringMap added in v3.3.0

func UnmarshalStringMap(m map[string]interface{}, propertyName string) (result map[string]string, err error)

UnmarshalStringMap retrieves the specified property from the map "m" and returns it as a map[string]string, or nil if the property wasn't found in the map.

func UnmarshalStringMapSlice added in v3.3.0

func UnmarshalStringMapSlice(m map[string]interface{}, propertyName string) (slice []map[string]string, err error)

UnmarshalStringMapSlice retrieves the specified property from the map "m" and returns it as a []map[string]string, or nil if the property wasn't found in the map.

func UnmarshalStringSlice

func UnmarshalStringSlice(m map[string]interface{}, propertyName string) (slice []string, err error)

UnmarshalStringSlice retrieves the specified property from the map and returns it as a string slice or nil if the property wasn't found in the map.

func UnmarshalUUID

func UnmarshalUUID(m map[string]interface{}, propertyName string) (result *strfmt.UUID, err error)

UnmarshalUUID retrieves the specified property from the map and returns it as a UUID or nil if the property wasn't found in the map.

func UnmarshalUUIDMap added in v3.3.0

func UnmarshalUUIDMap(m map[string]interface{}, propertyName string) (result map[string]strfmt.UUID, err error)

UnmarshalUUIDMap retrieves the specified property from the map "m" and returns it as a map[string]strfmt.UUID, or nil if the property wasn't found in the map.

func UnmarshalUUIDMapSlice added in v3.3.0

func UnmarshalUUIDMapSlice(m map[string]interface{}, propertyName string) (slice []map[string]strfmt.UUID, err error)

UnmarshalUUIDMapSlice retrieves the specified property from the map "m" and returns it as a []map[string]strfmt.UUID, or nil if the property wasn't found in the map.

func UnmarshalUUIDSlice

func UnmarshalUUIDSlice(m map[string]interface{}, propertyName string) (slice []strfmt.UUID, err error)

UnmarshalUUIDSlice retrieves the specified property from the map and returns it as a UUID slice or nil if the property wasn't found in the map.

func UserHomeDir

func UserHomeDir() string

UserHomeDir returns the user home directory.

func ValidateNotNil

func ValidateNotNil(object interface{}, errorMsg string) error

ValidateNotNil returns the specified error if 'object' is nil, nil otherwise.

func ValidateStruct

func ValidateStruct(param interface{}, paramName string) error

ValidateStruct validates 'param' (assumed to be a struct) according to the annotations attached to its fields.

Types

type Authenticator

type Authenticator interface {
	AuthenticationType() string
	Authenticate(*http.Request) error
	Validate() error
}

Authenticator describes the set of methods implemented by each authenticator.

func GetAuthenticatorFromEnvironment

func GetAuthenticatorFromEnvironment(credentialKey string) (authenticator Authenticator, err error)

GetAuthenticatorFromEnvironment instantiates an Authenticator using service properties retrieved from external config sources.

type BaseService

type BaseService struct {

	// Configuration values for a service.
	Options *ServiceOptions

	// A set of "default" http headers to be included with each outbound request.
	DefaultHeaders http.Header

	// The HTTP Client used to send requests and receive responses.
	Client *http.Client

	// The value to be used for the "User-Agent" HTTP header that is added to each
	// outbound request. If this value is not set, then a default value will be
	// used for the header.
	UserAgent string
}

BaseService implements the common functionality shared by generated services to manage requests and responses, authenticate outbound requests, etc.

func NewBaseService

func NewBaseService(options *ServiceOptions) (*BaseService, error)

NewBaseService constructs a new instance of BaseService. Validation on input parameters and service options will be performed before instance creation.

func (*BaseService) ConfigureService

func (service *BaseService) ConfigureService(serviceName string) error

ConfigureService updates the service with external configuration values.

func (*BaseService) DisableSSLVerification

func (service *BaseService) DisableSSLVerification()

DisableSSLVerification skips SSL verification.

func (*BaseService) GetServiceURL

func (service *BaseService) GetServiceURL() string

GetServiceURL returns the service URL.

func (*BaseService) Request

func (service *BaseService) Request(req *http.Request, result interface{}) (detailedResponse *DetailedResponse, err error)

Request invokes the specified HTTP request and returns the response.

func (*BaseService) SetDefaultHeaders

func (service *BaseService) SetDefaultHeaders(headers http.Header)

SetDefaultHeaders sets HTTP headers to be sent in every request.

func (*BaseService) SetHTTPClient

func (service *BaseService) SetHTTPClient(client *http.Client)

SetHTTPClient updates the client handling the requests.

func (*BaseService) SetServiceURL

func (service *BaseService) SetServiceURL(url string) error

SetServiceURL sets the service URL.

func (*BaseService) SetURL deprecated

func (service *BaseService) SetURL(url string) error

SetURL sets the service URL.

Deprecated: use SetServiceURL instead.

func (*BaseService) SetUserAgent

func (service *BaseService) SetUserAgent(userAgentString string)

SetUserAgent sets the user agent value.

type BasicAuthenticator

type BasicAuthenticator struct {
	// Username is the user-supplied basic auth username [required].
	Username string
	// Password is the user-supplied basic auth password [required].
	Password string
}

BasicAuthenticator takes a user-supplied username and password, and adds them to requests via an Authorization header of the form:

Authorization: Basic <encoded username and password>

func NewBasicAuthenticator

func NewBasicAuthenticator(username string, password string) (*BasicAuthenticator, error)

NewBasicAuthenticator constructs a new BasicAuthenticator instance.

func (*BasicAuthenticator) Authenticate

func (this *BasicAuthenticator) Authenticate(request *http.Request) error

Authenticate adds basic authentication information to a request.

Basic Authorization will be added to the request's headers in the form:

Authorization: Basic <encoded username and password>

func (BasicAuthenticator) AuthenticationType

func (BasicAuthenticator) AuthenticationType() string

AuthenticationType returns the authentication type for this authenticator.

func (BasicAuthenticator) Validate

func (this BasicAuthenticator) Validate() error

Validate the authenticator's configuration.

Ensures the username and password are not Nil. Additionally, ensures they do not contain invalid characters.

type BearerTokenAuthenticator

type BearerTokenAuthenticator struct {

	// The bearer token value to be used to authenticate request [required].
	BearerToken string
}

BearerTokenAuthenticator will take a user-supplied bearer token and adds it to requests via an Authorization header of the form:

Authorization: Bearer <bearer-token>

func NewBearerTokenAuthenticator

func NewBearerTokenAuthenticator(bearerToken string) (*BearerTokenAuthenticator, error)

NewBearerTokenAuthenticator constructs a new BearerTokenAuthenticator instance.

func (*BearerTokenAuthenticator) Authenticate

func (this *BearerTokenAuthenticator) Authenticate(request *http.Request) error

Authenticate adds bearer authentication information to the request.

The bearer token will be added to the request's headers in the form:

Authorization: Bearer <bearer-token>

func (BearerTokenAuthenticator) AuthenticationType

func (BearerTokenAuthenticator) AuthenticationType() string

AuthenticationType returns the authentication type for this authenticator.

func (BearerTokenAuthenticator) Validate

func (this BearerTokenAuthenticator) Validate() error

Validate the authenticator's configuration.

Ensures the bearer token is not Nil.

type CloudPakForDataAuthenticator

type CloudPakForDataAuthenticator struct {
	// The URL representing the Cloud Pak for Data token service endpoint [required].
	URL string

	// The username used to obtain a bearer token [required].
	Username string

	// The password used to obtain a bearer token [required].
	Password string

	// A flag that indicates whether verification of the server's SSL certificate
	// should be disabled; defaults to false [optional].
	DisableSSLVerification bool

	// Default headers to be sent with every CP4D token request [optional].
	Headers map[string]string

	// The http.Client object used to invoke token server requests [optional]. If
	// not specified, a suitable default Client will be constructed.
	Client *http.Client
	// contains filtered or unexported fields
}

CloudPakForDataAuthenticator uses a username and password pair to obtain a suitable bearer token, and adds the bearer token to requests via an Authorization header of the form:

Authorization: Bearer <bearer-token>

func NewCloudPakForDataAuthenticator

func NewCloudPakForDataAuthenticator(url string, username string, password string,
	disableSSLVerification bool, headers map[string]string) (*CloudPakForDataAuthenticator, error)

NewCloudPakForDataAuthenticator constructs a new CloudPakForDataAuthenticator instance.

func (*CloudPakForDataAuthenticator) Authenticate

func (authenticator *CloudPakForDataAuthenticator) Authenticate(request *http.Request) error

Authenticate adds the bearer token (obtained from the token server) to the specified request.

The CP4D bearer token will be added to the request's headers in the form:

Authorization: Bearer <bearer-token>

func (CloudPakForDataAuthenticator) AuthenticationType

func (CloudPakForDataAuthenticator) AuthenticationType() string

AuthenticationType returns the authentication type for this authenticator.

func (CloudPakForDataAuthenticator) Validate

func (authenticator CloudPakForDataAuthenticator) Validate() error

Validate the authenticator's configuration.

Ensures the username, password, and url are not Nil. Additionally, ensures they do not contain invalid characters.

type DetailedResponse

type DetailedResponse struct {

	// The HTTP status code associated with the response.
	StatusCode int

	// The HTTP headers contained in the response.
	Headers http.Header

	// Result - this field will contain the result of the operation (obtained from the response body).
	//
	// If the operation was successful and the response body contains a JSON response, it is un-marshalled
	// into an object of the appropriate type (defined by the particular operation), and the Result field will contain
	// this response object.  If there was an error while un-marshalling the JSON response body, then the RawResult field
	// will be set to the byte array containing the response body.
	//
	// Alternatively, if the generated SDK code passes in a result object which is an io.ReadCloser instance,
	// the JSON un-marshalling step is bypassed and the response body is simply returned in the Result field.
	// This scenario would occur in a situation where the SDK would like to provide a streaming model for large JSON
	// objects.
	//
	// If the operation was successful and the response body contains a non-JSON response,
	// the Result field will be an instance of io.ReadCloser that can be used by generated SDK code
	// (or the application) to read the response data.
	//
	// If the operation was unsuccessful and the response body contains a JSON error response,
	// this field will contain an instance of map[string]interface{} which is the result of un-marshalling the
	// response body as a "generic" JSON object.
	// If the JSON response for an unsuccessful operation could not be properly un-marshalled, then the
	// RawResult field will contain the raw response body.
	Result interface{}

	// This field will contain the raw response body as a byte array under these conditions:
	// 1) there was a problem un-marshalling a JSON response body -
	// either for a successful or unsuccessful operation.
	// 2) the operation was unsuccessful, and the response body contains a non-JSON response.
	RawResult []byte
}

DetailedResponse holds the response information received from the server.

func (*DetailedResponse) GetHeaders

func (response *DetailedResponse) GetHeaders() http.Header

GetHeaders returns the headers

func (*DetailedResponse) GetRawResult

func (response *DetailedResponse) GetRawResult() []byte

GetRawResult returns the raw response body as a byte array.

func (*DetailedResponse) GetResult

func (response *DetailedResponse) GetResult() interface{}

GetResult returns the result from the service

func (*DetailedResponse) GetResultAsMap

func (response *DetailedResponse) GetResultAsMap() (map[string]interface{}, bool)

GetResultAsMap returns the result as a map (generic JSON object), if the DetailedResponse.Result field contains an instance of a map.

func (*DetailedResponse) GetStatusCode

func (response *DetailedResponse) GetStatusCode() int

GetStatusCode returns the HTTP status code

func (*DetailedResponse) String

func (response *DetailedResponse) String() string

type Error

type Error struct {
	Message string `json:"message,omitempty"`
}

Error is a struct used to represent a single error received in an operation response.

type Errors

type Errors struct {
	Errors []Error `json:"errors,omitempty"`
}

Errors is a struct used to hold an array of errors received in an operation response.

type FormData

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

FormData stores information for form data.

type IamAuthenticator

type IamAuthenticator struct {

	// The apikey used to fetch the bearer token from the IAM token server
	// [required].
	ApiKey string

	// The URL representing the IAM token server's endpoint; If not specified,
	// a suitable default value will be used [optional].
	URL string

	// If neither field is specified, then no Authorization header will be sent
	// with token server requests [optional]. These fields are optional, but must
	// be specified together.
	ClientId string

	// If neither field is specified, then no Authorization header will be sent
	// with token server requests [optional]. These fields are optional, but must
	// be specified together.
	ClientSecret string

	// A flag that indicates whether verification of the server's SSL certificate
	// should be disabled; defaults to false [optional].
	DisableSSLVerification bool

	// [Optional] A set of key/value pairs that will be sent as HTTP headers in requests
	// made to the token server.
	Headers map[string]string

	// [Optional] The http.Client object used to invoke token server requests.
	// If not specified by the user, a suitable default Client will be constructed.
	Client *http.Client
	// contains filtered or unexported fields
}

IamAuthenticator uses an apikey to obtain a suitable bearer token value, and adds the bearer token to requests via an Authorization header of the form:

Authorization: Bearer <bearer-token>

func NewIamAuthenticator

func NewIamAuthenticator(apikey string, url string, clientId string, clientSecret string,
	disableSSLVerification bool, headers map[string]string) (*IamAuthenticator, error)

NewIamAuthenticator constructs a new IamAuthenticator instance.

func (*IamAuthenticator) Authenticate

func (authenticator *IamAuthenticator) Authenticate(request *http.Request) error

Authenticate adds IAM authentication information to the request.

The IAM bearer token will be added to the request's headers in the form:

Authorization: Bearer <bearer-token>

func (IamAuthenticator) AuthenticationType

func (IamAuthenticator) AuthenticationType() string

AuthenticationType returns the authentication type for this authenticator.

func (IamAuthenticator) Validate

func (this IamAuthenticator) Validate() error

Validate the authenticator's configuration.

Ensures the ApiKey is valid, and the ClientId and ClientSecret pair are mutually inclusive.

type NoAuthAuthenticator

type NoAuthAuthenticator struct {
}

NoAuthAuthenticator is simply a placeholder implementation of the Authenticator interface that performs no authentication. This might be useful in testing/debugging situations.

func NewNoAuthAuthenticator

func NewNoAuthAuthenticator() (*NoAuthAuthenticator, error)

func (*NoAuthAuthenticator) Authenticate

func (this *NoAuthAuthenticator) Authenticate(request *http.Request) error

func (NoAuthAuthenticator) AuthenticationType

func (NoAuthAuthenticator) AuthenticationType() string

func (NoAuthAuthenticator) Validate

func (NoAuthAuthenticator) Validate() error

type RequestBuilder

type RequestBuilder struct {
	Method string
	URL    *url.URL
	Header http.Header
	Body   io.Reader
	Query  map[string][]string
	Form   map[string][]FormData
}

RequestBuilder is used to build an HTTP Request instance.

func NewRequestBuilder

func NewRequestBuilder(method string) *RequestBuilder

NewRequestBuilder initiates a new request.

func (*RequestBuilder) AddFormData

func (requestBuilder *RequestBuilder) AddFormData(fieldName string, fileName string, contentType string,
	contents interface{}) *RequestBuilder

AddFormData adds a new mime part (constructed from the input parameters) to the request's multi-part form.

func (*RequestBuilder) AddHeader

func (requestBuilder *RequestBuilder) AddHeader(name string, value string) *RequestBuilder

AddHeader adds a header name and value to the request.

func (*RequestBuilder) AddQuery

func (requestBuilder *RequestBuilder) AddQuery(name string, value string) *RequestBuilder

AddQuery adds a query parameter name and value to the request.

func (*RequestBuilder) Build

func (requestBuilder *RequestBuilder) Build() (*http.Request, error)

Build builds an HTTP Request object from this RequestBuilder instance.

func (*RequestBuilder) ConstructHTTPURL

func (requestBuilder *RequestBuilder) ConstructHTTPURL(serviceURL string, pathSegments []string, pathParameters []string) (*RequestBuilder, error)

ConstructHTTPURL creates a properly-encoded URL with path parameters. This function returns an error if the serviceURL is "" or is an invalid URL string (e.g. ":<badscheme>").

func (*RequestBuilder) SetBodyContent

func (requestBuilder *RequestBuilder) SetBodyContent(contentType string, jsonContent interface{}, jsonPatchContent interface{},
	nonJSONContent interface{}) (builder *RequestBuilder, err error)

SetBodyContent sets the body content from one of three different sources.

func (*RequestBuilder) SetBodyContentForMultipart

func (requestBuilder *RequestBuilder) SetBodyContentForMultipart(contentType string, content interface{}, writer io.Writer) error

SetBodyContentForMultipart sets the body content for a part in a multi-part form.

func (*RequestBuilder) SetBodyContentJSON

func (requestBuilder *RequestBuilder) SetBodyContentJSON(bodyContent interface{}) (*RequestBuilder, error)

SetBodyContentJSON sets the body content from a JSON structure.

func (*RequestBuilder) SetBodyContentStream

func (requestBuilder *RequestBuilder) SetBodyContentStream(bodyContent io.Reader) (*RequestBuilder, error)

SetBodyContentStream sets the body content from an io.Reader instance.

func (*RequestBuilder) SetBodyContentString

func (requestBuilder *RequestBuilder) SetBodyContentString(bodyContent string) (*RequestBuilder, error)

SetBodyContentString sets the body content from a string.

type ServiceOptions

type ServiceOptions struct {
	// This is the base URL associated with the service instance. This value will
	// be combined with the paths for each operation to form the request URL
	// [required].
	URL string

	// Authenticator holds the authenticator implementation to be used by the
	// service instance to authenticate outbound requests, typically by adding the
	// HTTP "Authorization" header.
	Authenticator Authenticator
}

ServiceOptions is a struct of configuration values for a service.

Jump to

Keyboard shortcuts

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