Documentation ¶
Index ¶
- Constants
- Variables
- func ADateTimeInAYear(year int) *strfmt.DateTime
- func BoolPtr(p bool) *bool
- func BoolValue(v *bool) bool
- func ConvertStructToMap(in interface{}) (map[string]interface{}, error)
- func ConvertVarsMap(in map[string]interface{}) map[string][]byte
- func DateTimeToMetaV1Time(t *strfmt.DateTime) *metav1.Time
- func ExtractErrorMessage(resp *corev4.DetailedResponse, err error) error
- func FindResourceInstancesByName(client ClientSession, name string) (*rcv2.ResourceInstancesList, error)
- func FindResourceKeysByName(client ClientSession, name string) (*rcv2.ResourceKeysList, error)
- func Float64PtrToInt64Ptr(p *float64) *int64
- func GenerateTarget(in *rcv2.ResourceInstance) string
- func GetBearerFromAccessToken(aTok string) (string, error)
- func GetEtag(headers http.Header) string
- func GetEtagAnnotation(o metav1.Object) string
- func GetResourceGroupID(client ClientSession, rgName *string) (*string, error)
- func GetResourceGroupName(client ClientSession, rgID string) (string, error)
- func GetResourceInstanceTags(client ClientSession, crn string) ([]string, error)
- func GetResourcePlanID(client ClientSession, serviceName, planName string) (*string, error)
- func GetResourcePlanName(client ClientSession, serviceName, planID string) (*string, error)
- func GetServiceName(in *rcv2.ResourceInstance) string
- func Int64Ptr(p int64) *int64
- func Int64PtrToFloat64Ptr(p *int64) *float64
- func Int64Value(p *int64) int64
- func InterfaceToRawExtension(in interface{}) *runtime.RawExtension
- func IsResourceGone(err error) bool
- func IsResourceInactive(err error) bool
- func IsResourceNotFound(err error) bool
- func IsResourcePendingReclamation(err error) bool
- func IsResourceUnprocessable(err error) bool
- func MapToRawExtension(in map[string]interface{}) *runtime.RawExtension
- func ParseDateTime(dateTime string) strfmt.DateTime
- func ParseDateTimePtr(dateTime string) *strfmt.DateTime
- func ParseMetaV1Time(dateTime string) *metav1.Time
- func QueryResourceInstances(client ClientSession, queryOpts *rcv2.ListResourceInstancesOptions) (*rcv2.ResourceInstancesList, error)
- func QueryResourceKeys(client ClientSession, queryOpts *rcv2.ListResourceKeysOptions) (*rcv2.ResourceKeysList, error)
- func RandomInt(n int) int
- func RandomString(withMinLen bool) string
- func RawExtensionToInterface(in *runtime.RawExtension) interface{}
- func RawExtensionToMap(in *runtime.RawExtension) map[string]interface{}
- func ReturnConditionalDate(condition bool, val *strfmt.DateTime) *strfmt.DateTime
- func ReturnConditionalStr(condition bool, val string) *string
- func SetEtagAnnotation(o metav1.Object, name string)
- func StrPtr2Bytes(v *string) []byte
- func TagsDiff(desired, actual []string) (toAttach, toDetach []string)
- func UpdateResourceInstanceTags(client ClientSession, crn string, tags []string) error
- type ClientOptions
- type ClientSession
- type TemplateParser
Constants ¶
const ( // AccessTokenKey key for IBM Cloud API access token AccessTokenKey = "access_token" // RefreshTokenKey ...for the IBM Cloud API RefreshTokenKey = "refresh_token" // DefaultRegion is the default region for the IBM Cloud API DefaultRegion = "us-south" // DefaultICDEndpoint is the default endpoint for the ICD service DefaultICDEndpoint = "https://api.us-south.databases.cloud.ibm.com/v5/ibm" // COSServiceEndpoint endpoint on US region for COS service COSServiceEndpoint = "https://s3-api.us-geo.objectstorage.softlayer.net" // ETagAnnotation annotation name for ETag ETagAnnotation = "Etag" // ErrNewClient - ErrNewClient = "cannot create new Client" // ErrGetAuth - ErrGetAuth = "error getting auth info" // ErrGenObservation - ErrGenObservation = "error generating observation" // ErrManagedUpdateFailed - ErrManagedUpdateFailed = "cannot update custom resource" // ErrCheckUpToDate - ErrCheckUpToDate = "cannot determine if resource is up to date" // ErrBadRequest - ErrBadRequest = "error getting instance: Bad Request" // ErrGetConnDetails - ErrGetConnDetails = "error getting connection details" )
const (
FakeBearerToken = "Bearer mock-token"
)
A fake authentication token (WITH the "Bearer " prefix)
Variables ¶
var PcatTestHandler = func(planName string, planId string) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { _ = r.Body.Close() w.Header().Set("Content-Type", "application/json") planEntry := gcat.EntrySearchResult{ Resources: []gcat.CatalogEntry{ { Name: reference.ToPtrValue(planName), ID: reference.ToPtrValue(planId), }, }, } err := json.NewEncoder(w).Encode(planEntry) if err != nil { klog.Errorf("%s", err) } } }
PcatTestHandler handler to mock client SDK call to global catalog API for plans
var RgTestHandler = func(w http.ResponseWriter, r *http.Request) { _ = r.Body.Close() w.Header().Set("Content-Type", "application/json") rgl := rmgrv2.ResourceGroupList{ Resources: []rmgrv2.ResourceGroup{ { ID: reference.ToPtrValue(resourceGroupIDMockVal), Name: reference.ToPtrValue(resourceGroupNameMockVal), }, }, } err := json.NewEncoder(w).Encode(rgl) if err != nil { klog.Errorf("%s", err) } }
RgTestHandler handler to mock client SDK call to resource manager API
var SvcatTestHandler = func(serviceName string) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { _ = r.Body.Close() w.Header().Set("Content-Type", "application/json") catEntry := gcat.EntrySearchResult{ Resources: []gcat.CatalogEntry{ { Metadata: &gcat.CatalogEntryMetadata{ UI: &gcat.UIMetaData{ PrimaryOfferingID: reference.ToPtrValue(serviceName), }, }, }, }, } err := json.NewEncoder(w).Encode(catEntry) if err != nil { klog.Errorf("%s", err) } } }
SvcatTestHandler handler to mock client SDK call to global catalog API for services
var TagsTestHandler = func(w http.ResponseWriter, r *http.Request) { _ = r.Body.Close() w.Header().Set("Content-Type", "application/json") tags := gtagv1.TagList{ Items: []gtagv1.Tag{ { Name: reference.ToPtrValue("testString"), }, }, } err := json.NewEncoder(w).Encode(tags) if err != nil { klog.Errorf("%s", err) } }
TagsTestHandler handler to mock client SDK call to global tags API
Functions ¶
func ADateTimeInAYear ¶ added in v0.6.0
ADateTimeInAYear returns a (random, but fixed) date time in the given year
func BoolValue ¶
BoolValue converts the supplied bool pointer to an bool, returning false if the pointer is nil.
func ConvertStructToMap ¶
ConvertStructToMap - converts any struct to a map[string]interface{}
func ConvertVarsMap ¶
ConvertVarsMap connection vars map to format used in secret
func DateTimeToMetaV1Time ¶
DateTimeToMetaV1Time converts strfmt.DateTime to metav1.Time
func ExtractErrorMessage ¶ added in v0.1.2
func ExtractErrorMessage(resp *corev4.DetailedResponse, err error) error
ExtractErrorMessage extracts the content of an error message from the detailed response (if any) and appends it to the error returned by the SDK
func FindResourceInstancesByName ¶
func FindResourceInstancesByName(client ClientSession, name string) (*rcv2.ResourceInstancesList, error)
FindResourceInstancesByName finds resources instances matching name
func FindResourceKeysByName ¶
func FindResourceKeysByName(client ClientSession, name string) (*rcv2.ResourceKeysList, error)
FindResourceKeysByName finds resources instances matching name
func Float64PtrToInt64Ptr ¶ added in v0.1.2
Float64PtrToInt64Ptr converts a float64 pointer to an int64 pointer
func GenerateTarget ¶ added in v0.2.0
func GenerateTarget(in *rcv2.ResourceInstance) string
GenerateTarget generates Target from CRN
func GetBearerFromAccessToken ¶ added in v0.5.0
GetBearerFromAccessToken accepts only "good-lookng" tokens (ie which start with 'Bearer ') and returns the actual token
func GetEtagAnnotation ¶ added in v0.2.0
GetEtagAnnotation returns the etag annotation value on the resource.
func GetResourceGroupID ¶
func GetResourceGroupID(client ClientSession, rgName *string) (*string, error)
GetResourceGroupID gets a resource group ID from a resource group name or default
func GetResourceGroupName ¶
func GetResourceGroupName(client ClientSession, rgID string) (string, error)
GetResourceGroupName gets a resource group name from a resource group ID
func GetResourceInstanceTags ¶
func GetResourceInstanceTags(client ClientSession, crn string) ([]string, error)
GetResourceInstanceTags gets tags for a resource instance
func GetResourcePlanID ¶
func GetResourcePlanID(client ClientSession, serviceName, planName string) (*string, error)
GetResourcePlanID gets a resource plan ID from a service name and resource plan name for a given service
func GetResourcePlanName ¶
func GetResourcePlanName(client ClientSession, serviceName, planID string) (*string, error)
GetResourcePlanName gets a resource plan ID from a service name and resource plan name for a given service
func GetServiceName ¶
func GetServiceName(in *rcv2.ResourceInstance) string
GetServiceName gets ServiceName from Crn
func Int64PtrToFloat64Ptr ¶ added in v0.1.2
Int64PtrToFloat64Ptr converts a int64 pointer to an float64 pointer
func Int64Value ¶ added in v0.2.0
Int64Value converts the supplied int64 pointer to a value
func InterfaceToRawExtension ¶ added in v0.1.2
func InterfaceToRawExtension(in interface{}) *runtime.RawExtension
InterfaceToRawExtension - create a RawExtension from an Interface
func IsResourceGone ¶
IsResourceGone returns true if the resource is gone
func IsResourceInactive ¶
IsResourceInactive returns true if resource is inactive
func IsResourceNotFound ¶
IsResourceNotFound returns true if the SDK returns a not found error
func IsResourcePendingReclamation ¶
IsResourcePendingReclamation returns true if instance is being already deleted
func IsResourceUnprocessable ¶ added in v0.1.2
IsResourceUnprocessable returns true if resource is inactive
func MapToRawExtension ¶
func MapToRawExtension(in map[string]interface{}) *runtime.RawExtension
MapToRawExtension - create a RawExtension from a Map
func ParseDateTime ¶ added in v0.2.0
ParseDateTime - a wrapper around strfmt.DateTime used for tests generation
func ParseDateTimePtr ¶ added in v0.2.0
ParseDateTimePtr - a wrapper around strfmt.DateTime used for tests generation
func ParseMetaV1Time ¶ added in v0.2.0
ParseMetaV1Time - a wrapper around strfmt.DateTime used for tests generation
func QueryResourceInstances ¶
func QueryResourceInstances(client ClientSession, queryOpts *rcv2.ListResourceInstancesOptions) (*rcv2.ResourceInstancesList, error)
QueryResourceInstances finds resource instances based on query options
func QueryResourceKeys ¶
func QueryResourceKeys(client ClientSession, queryOpts *rcv2.ListResourceKeysOptions) (*rcv2.ResourceKeysList, error)
QueryResourceKeys finds resource instances based on query options
func RandomInt ¶ added in v0.6.0
RandomInt returns a random integer in [0, n)
(note that the seed is being taken care of)
func RandomString ¶ added in v0.6.0
RandomString returns a random string (of lenth <= 15)
Params
withMinLen - if true, the return value has a minimum size of 1 (we need to avoid the reference.ToPtrValue() returning nil
(note that the seed is being taken care of)
func RawExtensionToInterface ¶ added in v0.1.2
func RawExtensionToInterface(in *runtime.RawExtension) interface{}
RawExtensionToInterface - create an Interface from a RawExtension
func RawExtensionToMap ¶
func RawExtensionToMap(in *runtime.RawExtension) map[string]interface{}
RawExtensionToMap - create a Map from a RawExtension
func ReturnConditionalDate ¶ added in v0.6.0
ReturnConditionalDate returns the value of the 2nd parameter, if the value of the first one is true. O/w it returns nil
func ReturnConditionalStr ¶ added in v0.6.0
ReturnConditionalStr returns the value of the 2nd parameter, if the value of the first one is true. O/w it returns nil
func SetEtagAnnotation ¶ added in v0.2.0
SetEtagAnnotation sets the etag annotation of the resource.
func StrPtr2Bytes ¶
StrPtr2Bytes converts the supplied string pointer to a byte array and returns nil for nil pointer
func TagsDiff ¶
TagsDiff computes the difference between desired tags and actual tags and returns a list of tags to attach and to detach
func UpdateResourceInstanceTags ¶
func UpdateResourceInstanceTags(client ClientSession, crn string, tags []string) error
UpdateResourceInstanceTags update tags for the instance as needed
Types ¶
type ClientOptions ¶
type ClientOptions struct { ServiceName string URL string BearerToken string // This is contained in Authenticator (when it is of BearTokenAuthenticator type) - but we // seem to not be able to look it up via reflection. So separately for the controllers that need it... // Note that it should always be of the format 'Bearer <...>' RefreshToken string // not used every time.... Authenticator core.Authenticator }
ClientOptions provides info to initialize a client for the IBM Cloud APIs
func GetAuthInfo ¶
func GetAuthInfo(ctx context.Context, c client.Client, mg resource.Managed) (opts ClientOptions, err error)
GetAuthInfo returns the necessary authentication information that is necessary to use when the controller connects to cloud API in order to reconcile the managed resource.
type ClientSession ¶
type ClientSession interface { ResourceControllerV2() *rcv2.ResourceControllerV2 GlobalCatalogV1() *gcat.GlobalCatalogV1 ResourceManagerV2() *rmgrv2.ResourceManagerV2 GlobalTaggingV1() *gtagv1.GlobalTaggingV1 IbmCloudDatabasesV5() *icdv5.IbmCloudDatabasesV5 IamPolicyManagementV1() *iampmv1.IamPolicyManagementV1 IamAccessGroupsV2() *iamagv2.IamAccessGroupsV2 AdminrestV1() *arv1.AdminrestV1 CloudantV1() *cv1.CloudantV1 S3Client() *s3.S3 BucketConfigClient() *ibmBucketConfig.ResourceConfigurationV1 ClusterClientV2() ibmContainerV2.Clusters VPCClient() *vpcv1.VpcV1 }
ClientSession provides an interface for IBM Cloud APIs
func GetTestClient ¶ added in v0.6.0
func GetTestClient(serverURL string) (ClientSession, error)
GetTestClient creates a client appropriate for unit testing.
Params
serverURL - the test server url
Returns
the test client ready to go
func NewClient ¶
func NewClient(opts ClientOptions) (ClientSession, error)
NewClient returns an IBM API client. Should not be used for unit-testing (unless you know what you are doing - use GetTestClient(...) instead)
type TemplateParser ¶
TemplateParser handles go templating for connection variables
func NewTemplateParser ¶
func NewTemplateParser(vars map[string]string, obj map[string]interface{}) *TemplateParser
NewTemplateParser returns a new TemplateParserParser for an object obj to parse and a set of variables and templates vars.
func (*TemplateParser) Parse ¶
func (c *TemplateParser) Parse() (map[string]interface{}, error)
Parse parses the template, evaluates and store result