clients

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	FakeBearerToken = "Bearer mock-token"
)

A fake authentication token (WITH the "Bearer " prefix)

Variables

View Source
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

View Source
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

View Source
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

View Source
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

func ADateTimeInAYear(year int) *strfmt.DateTime

ADateTimeInAYear returns a (random, but fixed) date time in the given year

func BoolPtr

func BoolPtr(p bool) *bool

BoolPtr converts the supplied bool to a pointer to that bool

func BoolValue

func BoolValue(v *bool) bool

BoolValue converts the supplied bool pointer to an bool, returning false if the pointer is nil.

func ConvertStructToMap

func ConvertStructToMap(in interface{}) (map[string]interface{}, error)

ConvertStructToMap - converts any struct to a map[string]interface{}

func ConvertVarsMap

func ConvertVarsMap(in map[string]interface{}) map[string][]byte

ConvertVarsMap connection vars map to format used in secret

func DateTimeToMetaV1Time

func DateTimeToMetaV1Time(t *strfmt.DateTime) *metav1.Time

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

func Float64PtrToInt64Ptr(p *float64) *int64

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

func GetBearerFromAccessToken(aTok string) (string, error)

GetBearerFromAccessToken accepts only "good-lookng" tokens (ie which start with 'Bearer ') and returns the actual token

func GetEtag added in v0.2.0

func GetEtag(headers http.Header) string

GetEtag gets the Etag from a detailed response

func GetEtagAnnotation added in v0.2.0

func GetEtagAnnotation(o metav1.Object) string

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 Int64Ptr

func Int64Ptr(p int64) *int64

Int64Ptr converts the supplied int64 to a pointer to that int64.

func Int64PtrToFloat64Ptr added in v0.1.2

func Int64PtrToFloat64Ptr(p *int64) *float64

Int64PtrToFloat64Ptr converts a int64 pointer to an float64 pointer

func Int64Value added in v0.2.0

func Int64Value(p *int64) int64

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

func IsResourceGone(err error) bool

IsResourceGone returns true if the resource is gone

func IsResourceInactive

func IsResourceInactive(err error) bool

IsResourceInactive returns true if resource is inactive

func IsResourceNotFound

func IsResourceNotFound(err error) bool

IsResourceNotFound returns true if the SDK returns a not found error

func IsResourcePendingReclamation

func IsResourcePendingReclamation(err error) bool

IsResourcePendingReclamation returns true if instance is being already deleted

func IsResourceUnprocessable added in v0.1.2

func IsResourceUnprocessable(err error) bool

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

func ParseDateTime(dateTime string) strfmt.DateTime

ParseDateTime - a wrapper around strfmt.DateTime used for tests generation

func ParseDateTimePtr added in v0.2.0

func ParseDateTimePtr(dateTime string) *strfmt.DateTime

ParseDateTimePtr - a wrapper around strfmt.DateTime used for tests generation

func ParseMetaV1Time added in v0.2.0

func ParseMetaV1Time(dateTime string) *metav1.Time

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

func RandomInt(n int) int

RandomInt returns a random integer in [0, n)

(note that the seed is being taken care of)

func RandomString added in v0.6.0

func RandomString(withMinLen bool) string

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

func ReturnConditionalDate(condition bool, val *strfmt.DateTime) *strfmt.DateTime

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

func ReturnConditionalStr(condition bool, val string) *string

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

func SetEtagAnnotation(o metav1.Object, name string)

SetEtagAnnotation sets the etag annotation of the resource.

func StrPtr2Bytes

func StrPtr2Bytes(v *string) []byte

StrPtr2Bytes converts the supplied string pointer to a byte array and returns nil for nil pointer

func TagsDiff

func TagsDiff(desired, actual []string) (toAttach, toDetach []string)

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

type TemplateParser struct {
	Vars map[string]string
	Obj  map[string]interface{}
}

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

Jump to

Keyboard shortcuts

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