Documentation
¶
Index ¶
- Constants
- Variables
- func BoolPtr(literal bool) *bool
- func Float32Ptr(literal float32) *float32
- func Float64Ptr(literal float64) *float64
- func GetCurrentTime() int64
- func HasBadFirstOrLastChar(str string) bool
- func Int64Ptr(literal int64) *int64
- func IsJSONMimeType(mimeType string) bool
- func IsJSONPatchMimeType(mimeType string) bool
- func PrettyPrint(result interface{}, resultName string)
- func StringNilMapper(s *string) string
- func StringPtr(literal string) *string
- func SystemInfo() string
- func UserHomeDir() string
- func ValidateNotNil(object interface{}, errorMsg string) error
- func ValidateStruct(param interface{}, paramName string) error
- type Authenticator
- type BaseService
- func (service *BaseService) ConfigureService(serviceName string) error
- func (service *BaseService) DisableSSLVerification()
- func (service *BaseService) GetServiceURL() string
- func (service *BaseService) Request(req *http.Request, result interface{}) (detailedResponse *DetailedResponse, err error)
- func (service *BaseService) SetDefaultHeaders(headers http.Header)
- func (service *BaseService) SetHTTPClient(client *http.Client)
- func (service *BaseService) SetServiceURL(url string) error
- func (service *BaseService) SetURL(url string) errordeprecated
- func (service *BaseService) SetUserAgent(userAgentString string)
- type BasicAuthenticator
- type BearerTokenAuthenticator
- type CloudPakForDataAuthenticator
- type DetailedResponse
- func (response *DetailedResponse) GetHeaders() http.Header
- func (response *DetailedResponse) GetRawResult() []byte
- func (response *DetailedResponse) GetResult() interface{}
- func (response *DetailedResponse) GetResultAsMap() (map[string]interface{}, bool)
- func (response *DetailedResponse) GetStatusCode() int
- func (response *DetailedResponse) String() string
- type Error
- type Errors
- type FormData
- type IamAuthenticator
- type NoAuthAuthenticator
- type RequestBuilder
- func (requestBuilder *RequestBuilder) AddFormData(fieldName string, fileName string, contentType string, contents interface{}) *RequestBuilder
- func (requestBuilder *RequestBuilder) AddHeader(name string, value string) *RequestBuilder
- func (requestBuilder *RequestBuilder) AddQuery(name string, value string) *RequestBuilder
- func (requestBuilder *RequestBuilder) Build() (*http.Request, error)
- func (requestBuilder *RequestBuilder) ConstructHTTPURL(serviceURL string, pathSegments []string, pathParameters []string) (*RequestBuilder, error)
- func (requestBuilder *RequestBuilder) SetBodyContent(contentType string, jsonContent interface{}, jsonPatchContent interface{}, ...) (builder *RequestBuilder, err error)
- func (requestBuilder *RequestBuilder) SetBodyContentForMultipart(contentType string, content interface{}, writer io.Writer) error
- func (requestBuilder *RequestBuilder) SetBodyContentJSON(bodyContent interface{}) (*RequestBuilder, error)
- func (requestBuilder *RequestBuilder) SetBodyContentStream(bodyContent io.Reader) (*RequestBuilder, error)
- func (requestBuilder *RequestBuilder) SetBodyContentString(bodyContent string) (*RequestBuilder, error)
- type ServiceOptions
Constants ¶
const ( IBM_CREDENTIAL_FILE_ENVVAR = "IBM_CREDENTIALS_FILE" DEFAULT_CREDENTIAL_FILE_NAME = "ibm-credentials.env" )
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." )
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.
const ( POST = http.MethodPost GET = http.MethodGet DELETE = http.MethodDelete PUT = http.MethodPut PATCH = http.MethodPatch )
common HTTP methods
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
const (
PRE_AUTH_PATH = "/v1/preauth/validateAuth"
)
Constants for CP4D
Variables ¶
var Validate *validator.Validate
Validate single instance of Validate, it caches struct info
Functions ¶
func Float32Ptr ¶
Float32Ptr : return pointer to float32 literal
func Float64Ptr ¶
Float64Ptr : return pointer to float64 literal
func HasBadFirstOrLastChar ¶
HasBadFirstOrLastChar checks if the string starts with `{` or `"` or ends with `}` or `"`
func IsJSONMimeType ¶
IsJSONMimeType : Returns true iff the specified mimeType value represents a "JSON" mimetype.
func IsJSONPatchMimeType ¶
IsJSONPatchMimeType : Returns true iff the specified mimeType value represents a "JSON Patch" mimetype.
func PrettyPrint ¶ added in v0.2.2
func PrettyPrint(result interface{}, resultName string)
PrettyPrint print pretty
func StringNilMapper ¶
StringNilMapper - de-references the parameter 's' and returns the result, or "" if 's' is nil
func ValidateNotNil ¶
ValidateNotNil - returns the specified error if 'object' is nil, nil otherwise
func ValidateStruct ¶
ValidateStruct - validates 'param' (assumed to be a struct) according to the annotations attached to its fields
Types ¶
type Authenticator ¶ added in v0.5.0
type Authenticator interface { AuthenticationType() string Authenticate(*http.Request) error Validate() error }
Authenticator: each authenticator implements this set of methods.
func GetAuthenticatorFromEnvironment ¶ added in v0.5.0
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 { // The options related to the base service. Options *ServiceOptions // A set of "default" http headers to be included with each outbound request. // This can be set by the SDK user. 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 : This struct defines a common "service" object that is used by each generated service to manage requests and responses, perform authentication, etc.
func NewBaseService ¶
func NewBaseService(options *ServiceOptions, serviceName, displayName string) (*BaseService, error)
NewBaseService : This function will construct a new instance of the BaseService struct, while performing validation on input parameters and service options.
func (*BaseService) ConfigureService ¶ added in v1.1.0
func (service *BaseService) ConfigureService(serviceName string) error
func (*BaseService) DisableSSLVerification ¶
func (service *BaseService) DisableSSLVerification()
DisableSSLVerification skips SSL verification
func (*BaseService) GetServiceURL ¶ added in v0.8.0
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 performs the HTTP request
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 ¶ added in v0.8.0
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 ¶ added in v0.5.0
type BasicAuthenticator struct { // [Required] - the basic auth username and password. Username string Password string }
The BasicAuthenticator will perform authentication on outbound requests by adding a "Basic" type Authorization header that contains the base64-encoded username and password.
func NewBasicAuthenticator ¶ added in v0.5.0
func NewBasicAuthenticator(username string, password string) (*BasicAuthenticator, error)
NewBasicAuthenticator: Constructs a new BasicAuthenticator instance.
func (BasicAuthenticator) Authenticate ¶ added in v0.5.0
func (this BasicAuthenticator) Authenticate(request *http.Request) error
Authenticate: authenticates the specified request by adding an Authorizatin header.
func (BasicAuthenticator) AuthenticationType ¶ added in v0.5.0
func (BasicAuthenticator) AuthenticationType() string
func (BasicAuthenticator) Validate ¶ added in v0.5.0
func (this BasicAuthenticator) Validate() error
Validate: validates the configuration
type BearerTokenAuthenticator ¶ added in v0.5.0
type BearerTokenAuthenticator struct { // [Required] - the bearer token value to be used to authenticate request. BearerToken string }
The BearerTokenAuthenticator will authenticate requests by adding a "Bearer"-type Authorization header that contains the configured bearer token value.
func NewBearerTokenAuthenticator ¶ added in v0.5.0
func NewBearerTokenAuthenticator(bearerToken string) (*BearerTokenAuthenticator, error)
NewBearerTokenAuthenticator: Constructs a new BearerTokenAuthenticator instance.
func (BearerTokenAuthenticator) Authenticate ¶ added in v0.5.0
func (this BearerTokenAuthenticator) Authenticate(request *http.Request) error
Authenticate: authenticates the specified request by adding an Authorization header that contains the bearer token value.
func (BearerTokenAuthenticator) AuthenticationType ¶ added in v0.5.0
func (BearerTokenAuthenticator) AuthenticationType() string
func (BearerTokenAuthenticator) Validate ¶ added in v0.5.0
func (this BearerTokenAuthenticator) Validate() error
Validate: validates the configuration
type CloudPakForDataAuthenticator ¶ added in v0.5.0
type CloudPakForDataAuthenticator struct { // [Required] The URL representing the token server's endpoing. URL string // [Required] The username and password used to compute the basic auth Authorization header // to be sent with requests to the token server. Username string Password string // [Optional] A flag that indicates whether SSL hostname verification should be disabled or not. // Default: false 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 }
CloudPakForDataAuthenticator : This authenticator will automatically fetch an access token for the user-specified username and password. Outbound REST requests invoked by the BaseService are then authenticated by adding a Bearer-type Authorization header containing the access token.
func NewCloudPakForDataAuthenticator ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (authenticator CloudPakForDataAuthenticator) Authenticate(request *http.Request) error
Authenticate: performs the authentication on the specified Request by adding a Bearer-type Authorization header containing the access token fetched from the token server.
func (CloudPakForDataAuthenticator) AuthenticationType ¶ added in v0.5.0
func (CloudPakForDataAuthenticator) AuthenticationType() string
func (CloudPakForDataAuthenticator) Validate ¶ added in v0.5.0
func (authenticator CloudPakForDataAuthenticator) Validate() error
Validate: validates the configuration.
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 unmarshalled // into an object of the appropriate type (defined by the particular operation), and the Result field will contain // this response object. To retrieve this response object in its properly-typed form, use the // generated service's "Get<operation-name>Result()" method. // If there was an error while unmarshalling the JSON response body, then the RawResult field // will be set to the byte array containing the response body. // // 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 the application to read // the response data. // // If the operation was unsuccessful and the response body contains a JSON response, // this field will contain an instance of map[string]interface{} which is the result of unmarshalling the // response body as a "generic" JSON object. // If the JSON response for an unsuccessful operation could not be properly unmarshalled, 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 unmarshalling 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 : Each generated service method will return an instance of this struct.
func (*DetailedResponse) GetHeaders ¶
func (response *DetailedResponse) GetHeaders() http.Header
GetHeaders returns the headers
func (*DetailedResponse) GetRawResult ¶ added in v0.7.0
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 ¶ added in v0.7.0
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 ¶ added in v0.2.0
type Error struct {
Message string `json:"message,omitempty"`
}
Error : specifies the error
type Errors ¶ added in v0.2.0
type Errors struct {
Errors []Error `json:"errors,omitempty"`
}
Errors : a struct for errors array
type FormData ¶
type FormData struct {
// contains filtered or unexported fields
}
A FormData stores information for form data
type IamAuthenticator ¶ added in v0.5.0
type IamAuthenticator struct { // [Required] The apikey used to fetch the access token from the IAM token server. ApiKey string // [Optional] The URL representing the IAM token server's endpoint. // If not specified, a suitable default value is used. URL string // [Optional] The ClientId and ClientSecret fields are used to form a "basic auth" Authorization header // for interactions with the IAM token server. // If neither field is specified, then no Authorization header will be sent with token server requests. // These fields are optional, but must be specified together. // Default: "", "" ClientId string ClientSecret string // [Optional] A flag that indicates whether verificaton of the server's SSL certificate should be disabled or not. // Default: false 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 : This authenticator will automatically fetch an access token for the configured apikey. Outbound REST requests invoked by the BaseService are then authenticated by adding a Bearer-type Authorization header containing the access token.
func NewIamAuthenticator ¶ added in v0.5.0
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 ¶ added in v0.5.0
func (authenticator IamAuthenticator) Authenticate(request *http.Request) error
Authenticate: Performs the authentication on the specified Request by adding a Bearer-type Authorization header containing the access token fetched from the token server.
func (IamAuthenticator) AuthenticationType ¶ added in v0.5.0
func (IamAuthenticator) AuthenticationType() string
func (IamAuthenticator) Validate ¶ added in v0.5.0
func (this IamAuthenticator) Validate() error
Validate: validates the configuration of the IamAuthenticator instance.
type NoAuthAuthenticator ¶ added in v0.5.0
type NoAuthAuthenticator struct { }
func NewNoAuthAuthenticator ¶ added in v0.5.0
func NewNoAuthAuthenticator() (*NoAuthAuthenticator, error)
func (NoAuthAuthenticator) Authenticate ¶ added in v0.5.0
func (this NoAuthAuthenticator) Authenticate(request *http.Request) error
func (NoAuthAuthenticator) AuthenticationType ¶ added in v0.5.0
func (NoAuthAuthenticator) AuthenticationType() string
func (NoAuthAuthenticator) Validate ¶ added in v0.5.0
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 }
A RequestBuilder is an HTTP request to be sent to the service
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 makes an entry for Form data
func (*RequestBuilder) AddHeader ¶
func (requestBuilder *RequestBuilder) AddHeader(name string, value string) *RequestBuilder
AddHeader adds header name and value
func (*RequestBuilder) AddQuery ¶
func (requestBuilder *RequestBuilder) AddQuery(name string, value string) *RequestBuilder
AddQuery adds Query name and value
func (*RequestBuilder) Build ¶
func (requestBuilder *RequestBuilder) Build() (*http.Request, error)
Build the request
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 - set the body content from a JSON structure
func (*RequestBuilder) SetBodyContentStream ¶
func (requestBuilder *RequestBuilder) SetBodyContentStream(bodyContent io.Reader) (*RequestBuilder, error)
SetBodyContentStream - set the body content from an io.Reader instance
func (*RequestBuilder) SetBodyContentString ¶
func (requestBuilder *RequestBuilder) SetBodyContentString(bodyContent string) (*RequestBuilder, error)
SetBodyContentString - set 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 path for each operation to form the request URL. URL string // This field holds the authenticator for the service instance. // The authenticator will "authenticate" each outbound request by adding additional // information to the request, typically in the form of the "Authorization" http header. Authenticator Authenticator }
ServiceOptions : This struct contains the options supported by the BaseService methods.