Documentation
¶
Overview ¶
Package common provides supporting functions and structs used by service packages
Index ¶
- Constants
- func Bool(value bool) *bool
- func CloseBodyIfValid(httpResponse *http.Response)
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func Float32(value float32) *float32
- func Float64(value float64) *float64
- func GetBodyHash(request *http.Request) (hashString string, err error)
- func HTTPRequestMarshaller(requestStruct interface{}, httpRequest *http.Request) (err error)
- func IfDebug(fn func())
- func Int(value int) *int
- func IsConfigurationProviderValid(conf ConfigurationProvider) (ok bool, err error)
- func Logf(format string, v ...interface{})
- func Logln(v ...interface{})
- func MakeDefaultHTTPRequest(method, path string) (httpRequest http.Request)
- func MakeDefaultHTTPRequestWithTaggedStruct(method, path string, requestStruct interface{}) (httpRequest http.Request, err error)
- func PointerString(datastruct interface{}) (representation string)
- func PrivateKeyFromBytes(pemData []byte, password *string) (key *rsa.PrivateKey, e error)
- func String(value string) *string
- func Uint(value uint) *uint
- func UnmarshalResponse(httpResponse *http.Response, responseStruct interface{}) (err error)
- func UnmarshalResponseWithPolymorphicBody(httpResponse *http.Response, responseStruct interface{}, ...) (err error)
- func Version() string
- type BaseClient
- type ConfigurationProvider
- func ComposingConfigurationProvider(providers []ConfigurationProvider) (ConfigurationProvider, error)
- func ConfigurationProviderEnvironmentVariables(environmentVariablePrefix, privateKeyPassword string) ConfigurationProvider
- func ConfigurationProviderFromFile(configFilePath, privateKeyPassword string) (ConfigurationProvider, error)
- func ConfigurationProviderFromFileWithProfile(configFilePath, profile, privateKeyPassword string) (ConfigurationProvider, error)
- func DefaultConfigProvider() ConfigurationProvider
- func NewRawConfigurationProvider(tenancy, user, region, fingerprint, privateKey string, ...) ConfigurationProvider
- type HTTPRequestDispatcher
- type HTTPRequestSigner
- type KeyProvider
- type PolymorphicJSONUnmarshaler
- type Region
- type RequestInterceptor
- type SDKTime
- type ServiceError
- type SignerBodyHashPredicate
Constants ¶
const (
// DefaultHostURLTemplate The default url template for service hosts
DefaultHostURLTemplate = "%s.%s.oraclecloud.com"
)
Variables ¶
This section is empty.
Functions ¶
func CloseBodyIfValid ¶
CloseBodyIfValid closes the body of an http response if the response and the body are valid
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf logs v with the provided format if debug mode is set
func Debugln ¶
func Debugln(v ...interface{})
Debugln logs v appending a new line if debug mode is set
func GetBodyHash ¶
GetBodyHash creates a base64 string from the hash of body the request
func HTTPRequestMarshaller ¶
HTTPRequestMarshaller marshals a structure to an http request using tag values in the struct The marshaller tag should like the following
type A struct { ANumber string `contributesTo="query" name="number"` TheBody `contributesTo="body"` }
where the contributesTo tag can be: header, path, query, body and the 'name' tag is the name of the value used in the http request(not applicable for path) If path is specified as part of the tag, the values are appened to the url path in the order they appear in the structure The current implementation only supports primitive types, except for the body tag, which needs a struct type. The body of a request will be marshaled using the tags of the structure
func IsConfigurationProviderValid ¶
func IsConfigurationProviderValid(conf ConfigurationProvider) (ok bool, err error)
IsConfigurationProviderValid Tests all parts of the configuration provider do not return an error
func MakeDefaultHTTPRequest ¶
MakeDefaultHTTPRequest creates the basic http request with the necessary headers set
func MakeDefaultHTTPRequestWithTaggedStruct ¶
func MakeDefaultHTTPRequestWithTaggedStruct(method, path string, requestStruct interface{}) (httpRequest http.Request, err error)
MakeDefaultHTTPRequestWithTaggedStruct creates an http request from an struct with tagged fields, see HTTPRequestMarshaller for more information
func PointerString ¶
func PointerString(datastruct interface{}) (representation string)
PointerString prints the values of pointers in a struct Producing a human friendly string for an struct with pointers. useful when debugging the values of a struct
func PrivateKeyFromBytes ¶
func PrivateKeyFromBytes(pemData []byte, password *string) (key *rsa.PrivateKey, e error)
PrivateKeyFromBytes is a helper function that will produce a RSA private key from bytes.
func UnmarshalResponse ¶
UnmarshalResponse hydrates the fields of a struct with the values of a http response, guided by the field tags. The directive tag is "presentIn" and it can be either
- "header": Will look for the header tagged as "name" in the headers of the struct and set it value to that
- "body": It will try to marshal the body from a json string to a struct tagged with 'presentIn: "body"'.
Further this method will consume the body it should be safe to close it after this function Notice the current implementation only supports native types:int, strings, floats, bool as the field types
func UnmarshalResponseWithPolymorphicBody ¶
func UnmarshalResponseWithPolymorphicBody(httpResponse *http.Response, responseStruct interface{}, unmarshaler PolymorphicJSONUnmarshaler) (err error)
UnmarshalResponseWithPolymorphicBody similar to UnmarshalResponse but assumes the body of the response contains polymorphic json. This function will use the unmarshaler argument to unmarshal json content
Types ¶
type BaseClient ¶
type BaseClient struct { //HTTPClient performs the http network operations HTTPClient HTTPRequestDispatcher //Signer performs auth operation Signer HTTPRequestSigner //A request interceptor can be used to customize the request before signing and dispatching Interceptor RequestInterceptor //The host of the service Host string //The user agent UserAgent string //Base path for all operations of this client BasePath string }
BaseClient struct implements all basic operations to call oci web services.
func DefaultBaseClientWithSigner ¶
func DefaultBaseClientWithSigner(signer HTTPRequestSigner) BaseClient
DefaultBaseClientWithSigner creates a default base client with a given signer
func NewClientWithConfig ¶
func NewClientWithConfig(configProvider ConfigurationProvider) (client BaseClient, err error)
NewClientWithConfig Create a new client with a configuration provider, the configuration provider will be used for the default signer as well as reading the region This function does not check for valid regions to implement forward compatibility
type ConfigurationProvider ¶
type ConfigurationProvider interface { KeyProvider TenancyOCID() (string, error) UserOCID() (string, error) KeyFingerprint() (string, error) Region() (string, error) }
ConfigurationProvider wraps information about the account owner
func ComposingConfigurationProvider ¶
func ComposingConfigurationProvider(providers []ConfigurationProvider) (ConfigurationProvider, error)
ComposingConfigurationProvider creates a composing configuration provider with the given slice of configuration providers A composing provider will return the configuration of the first provider that has the required property if no provider has the property it will return an error.
func ConfigurationProviderEnvironmentVariables ¶
func ConfigurationProviderEnvironmentVariables(environmentVariablePrefix, privateKeyPassword string) ConfigurationProvider
ConfigurationProviderEnvironmentVariables creates a ConfigurationProvider from a uniform set of environment variables starting with a prefix The env variables should look like: [prefix]_private_key_path, [prefix]_tenancy_ocid, [prefix]_user_ocid, [prefix]_fingerprint [prefix]_region
func ConfigurationProviderFromFile ¶
func ConfigurationProviderFromFile(configFilePath, privateKeyPassword string) (ConfigurationProvider, error)
ConfigurationProviderFromFile creates a configuration provider from a configuration file by reading the "DEFAULT" profile
func ConfigurationProviderFromFileWithProfile ¶
func ConfigurationProviderFromFileWithProfile(configFilePath, profile, privateKeyPassword string) (ConfigurationProvider, error)
ConfigurationProviderFromFileWithProfile creates a configuration provider from a configuration file and the given profile
func DefaultConfigProvider ¶
func DefaultConfigProvider() ConfigurationProvider
DefaultConfigProvider returns the default config provider. The default config provider will look for configurations in 3 places: file in $HOME/.oci/config, HOME/.obmcs/config and variables names starting with the string TF_VAR. If the same configuration is found in multiple places the provider will prefer the first one.
func NewRawConfigurationProvider ¶
func NewRawConfigurationProvider(tenancy, user, region, fingerprint, privateKey string, privateKeyPassphrase *string) ConfigurationProvider
NewRawConfigurationProvider will create a rawConfigurationProvider
type HTTPRequestDispatcher ¶
HTTPRequestDispatcher wraps the execution of a http request, it is generally implemented by http.Client.Do, but can be customized for testing
type HTTPRequestSigner ¶
HTTPRequestSigner the interface to sign a request
func DefaultRequestSigner ¶
func DefaultRequestSigner(provider KeyProvider) HTTPRequestSigner
DefaultRequestSigner creates a signer with default parameters.
func RequestSigner ¶
func RequestSigner(provider KeyProvider, genericHeaders, bodyHeaders []string) HTTPRequestSigner
RequestSigner creates a signer that utilizes the specified headers for signing and the default predicate for using the body of the request as part of the signature
func RequestSignerWithBodyHashingPredicate ¶
func RequestSignerWithBodyHashingPredicate(provider KeyProvider, genericHeaders, bodyHeaders []string, shouldHashBody SignerBodyHashPredicate) HTTPRequestSigner
RequestSignerWithBodyHashingPredicate creates a signer that utilizes the specified headers for signing, as well as a predicate for using the body of the request and bodyHeaders parameter as part of the signature
type KeyProvider ¶
type KeyProvider interface { PrivateRSAKey() (*rsa.PrivateKey, error) KeyID() (string, error) }
KeyProvider interface that wraps information about the key's account owner
type PolymorphicJSONUnmarshaler ¶
type PolymorphicJSONUnmarshaler interface {
UnmarshalPolymorphicJSON(data []byte) (interface{}, error)
}
PolymorphicJSONUnmarshaler is the interface to unmarshal polymorphic json payloads
type Region ¶
type Region string
Region type for regions
func StringToRegion ¶
StringToRegion convert a string to Region type
type RequestInterceptor ¶
RequestInterceptor function used to customize the request before calling the underlying service
type SDKTime ¶
SDKTime a time struct, which renders to/from json using RFC339
func (*SDKTime) MarshalJSON ¶
MarshalJSON marshals to JSON
func (*SDKTime) UnmarshalJSON ¶
UnmarshalJSON unmarshals from json
type ServiceError ¶
type ServiceError interface { // The http status code of the error GetHTTPStatusCode() int // The human-readable error string as sent by the service GetMessage() string // A short error code that defines the error, meant for programmatic parsing. // See https://docs.us-phoenix-1.oraclecloud.com/Content/API/References/apierrors.htm GetCode() string }
ServiceError models all potential errors generated the service call
func IsServiceError ¶
func IsServiceError(err error) (failure ServiceError, ok bool)
IsServiceError returns false if the error is not service side, otherwise true additionally it returns an interface representing the ServiceError
type SignerBodyHashPredicate ¶
SignerBodyHashPredicate a function that allows to disable/enable body hashing of requests and headers associated with body content