utils

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ResourceEntity identifies resources
	ResourceEntity = "Resource"

	// DataSourceEntity identifies data sources
	DataSourceEntity = "Data Source"

	// TestEntity identifies tests
	TestEntity = "Test"
)

Entities

View Source
const (
	// GCPCredentialsEnv env variable name for gcp provider/storage config/releases
	GCPCredentialsEnv = "GOOGLE_APPLICATION_CREDENTIALS"
	// GCSCredentialsJSON field name to denote in Json request
	GCSCredentialsJSON = "GCS_CREDENTIALS_JSON"

	// AWSAccessKeyEnv env variable name for aws provider/storage config/releases
	AWSAccessKeyEnv = "AWS_ACCESS_KEY_ID"
	// AWSSecretAccessKeyEnv env variable name for aws provider/storage config/releases
	AWSSecretAccessKeyEnv = "AWS_SECRET_ACCESS_KEY"

	// AzureSubscriptionIDEnv env variable name for azure provider
	AzureSubscriptionIDEnv = "AZURE_SUBSCRIPTION_ID"
	// AzureRGEnv env variable name for azure provider
	AzureRGEnv = "AZURE_RG"
	// AzureTenantIDEnv env variable name for azure provider
	AzureTenantIDEnv = "AZURE_TENANT_ID"
	// AzureClientIDEnv env variable name for azure provider
	AzureClientIDEnv = "AZURE_CLIENT_ID"
	// AzureClientSecretEnv env variable name for azure provider
	AzureClientSecretEnv = "AZURE_CLIENT_SECRET"
	// AzureNetworkSubscriptionIDEnv env variable name for azure provider
	AzureNetworkSubscriptionIDEnv = "AZURE_NETWORK_SUBSCRIPTION_ID"
	// AzureNetworkRGEnv env variable name for azure provider
	AzureNetworkRGEnv = "AZURE_NETWORK_RG"

	// AzureStorageSasTokenEnv env variable name azure storage config
	AzureStorageSasTokenEnv = "AZURE_STORAGE_SAS_TOKEN"
)

Environment variable fields

View Source
const (

	// YBAAllowUniverseMinVersion specifies minimum version
	// required to use Universe resource via YBA Terraform
	YBAAllowUniverseMinVersion = "2.17.1.0-b371"

	// YBAAllowBackupMinVersion specifies minimum version
	// required to use Scheduled Backup resource via YBA Terraform
	YBAAllowBackupMinVersion = "2.18.1.0-b20"

	// YBAAllowEditProviderMinVersion specifies minimum version
	// required to Edit a Provider (onprem or cloud) resource
	// via YBA Terraform
	YBAAllowEditProviderMinVersion = "2.18.0.0-b65"

	// YBAAllowFailureSubTaskListMinVersion specifies minimum version
	// required to fetch failed subtask message from YugabyteDB Anywhere
	YBAAllowFailureSubTaskListMinVersion = "2.18.1.0-b68"
)

Minimum YugabyteDB Anywhere versions to support operation

Variables

View Source
var (
	// PendingTaskStates lists incomplete task states
	PendingTaskStates = []string{"Created", "Initializing", "Running"}
	// SuccessTaskStates lists successful task states
	SuccessTaskStates = []string{"Success"}
)

Functions

func AwsCredentialsFromEnv

func AwsCredentialsFromEnv() (awsCreds.Value, error)

AwsCredentialsFromEnv retrives values of "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" from env variables

func AzureStorageCredentialsFromEnv

func AzureStorageCredentialsFromEnv() (string, error)

AzureStorageCredentialsFromEnv retrives value of "AZURE_STORAGE_SAS_TOKEN" from env variables

func CheckValidYBAVersion

func CheckValidYBAVersion(ctx context.Context, c *client.APIClient, versions []string) (bool,
	string, error)

CheckValidYBAVersion allows operation if version is higher than listed versions

func CompareYbVersions

func CompareYbVersions(v1 string, v2 string) (int, error)

CompareYbVersions returns -1 if version1 < version2, 0 if version1 = version2, 1 if version1 > version2

func ConvertMsToUnit

func ConvertMsToUnit(value int64, unit string) float64

ConvertMsToUnit converts time from milliseconds to unit

func ConvertUnitToMs

func ConvertUnitToMs(value float64, unit string) int64

ConvertUnitToMs converts time from unit to milliseconds

func CreateSingletonList

func CreateSingletonList(in interface{}) []interface{}

CreateSingletonList returns a list of single entry from an interface

func ErrorFromHTTPResponse

func ErrorFromHTTPResponse(resp *http.Response, apiError error, entity, entityName,
	operation string) error

ErrorFromHTTPResponse extracts the error message from the HTTP response of the API

func ErrorFromResponseBody added in v0.1.6

func ErrorFromResponseBody(errorBlock YbaStructuredError) string

ErrorFromResponseBody is a function to extract error interfaces into string

func FileExist

func FileExist(filePath string) error

FileExist checks if file in the given path exists

func GcpGetCredentialsAsMap

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

GcpGetCredentialsAsMap returns the GCE JSON file contents as a map

func GcpGetCredentialsAsString

func GcpGetCredentialsAsString() (string, error)

GcpGetCredentialsAsString returns the GCE JSON file contents as a string

func GetBoolPointer

func GetBoolPointer(in bool) *bool

GetBoolPointer returns a pointer to bool value

func GetFloat64Pointer

func GetFloat64Pointer(in float64) *float64

GetFloat64Pointer returns a pointer to float64 type

func GetInt32Pointer

func GetInt32Pointer(in int32) *int32

GetInt32Pointer returns a pointer to int32 value

func GetInt64Pointer

func GetInt64Pointer(in int64) *int64

GetInt64Pointer returns a pointer to int64 value

func GetMsFromDurationString

func GetMsFromDurationString(duration string) (int64, string, bool, error)

GetMsFromDurationString retrieves the ms notation of the duration mentioned in the input string return value string holds the unit calculated from time.Duration Throws error on improper duration format

func GetStringPointer

func GetStringPointer(in string) *string

GetStringPointer returns a pointer to string value

func GetUnitOfTimeFromDuration

func GetUnitOfTimeFromDuration(duration time.Duration) string

GetUnitOfTimeFromDuration takes time.Duration as input and caluclates the unit specified in that duration

func GetUniversesForProvider

func GetUniversesForProvider(ctx context.Context, c *client.APIClient, cUUID, pUUID,
	universeName string) ([]client.UniverseResp, bool, error)

GetUniversesForProvider fetches the list of universes corresponding to a particular provider. Currently edit operations are blocked if universes exists. For the current scenario, only on prem providers are editable, but to accomodate future changes to cloud provider resource, defining in the utils class

func IsVersionAllowed added in v0.1.6

func IsVersionAllowed(currentVersion, restrictedVersion string) (bool, error)

IsVersionAllowed checks if a current version (>= Min version) is equal to the restricted version for the operation. Used in cases where certain preview build errors are not resolved and need to be blocked on YugabyteDB Anywhere Terraform provider

func MapFromSingletonList

func MapFromSingletonList(in []interface{}) map[string]interface{}

MapFromSingletonList returns a map of string -> interface from a slice of interface

func MapListFromInterfaceList

func MapListFromInterfaceList(in []interface{}) []map[string]interface{}

MapListFromInterfaceList returns a map of string -> interface from a slice of interface

func ObfuscateString added in v0.1.10

func ObfuscateString(s string, n int) string

ObfuscateString masks sensitive strings in the state file

func ReadSSHPrivateKey

func ReadSSHPrivateKey(filePath string) (*string, error)

ReadSSHPrivateKey retrives private key file contents from env variable

func StringMap

func StringMap(in map[string]interface{}) *map[string]string

StringMap accepts a string -> interface map and returns pointer to string -> string map

func StringSlice

func StringSlice(in []interface{}) *[]string

StringSlice accepts array of interface and returns a pointer to slice of string

func WaitForTask

func WaitForTask(ctx context.Context, tUUID string, cUUID string, c *client.APIClient,
	timeout time.Duration) error

WaitForTask waits for State change for a YBA task

func YBARestrictBackupVersions added in v0.1.6

func YBARestrictBackupVersions() []string

YBARestrictBackupVersions are certain YugabyteDB Anywhere versions >= min version for backups that would not support the operation

func YBARestrictFailedSubtasksVersions added in v0.1.6

func YBARestrictFailedSubtasksVersions() []string

YBARestrictFailedSubtasksVersions are certain YugabyteDB Anywhere versions >= min version for of fetching failed subtask lists that would not support the operation

Types

type AzureCredentials

type AzureCredentials struct {
	TenantID       string `json:"tenant_id"`
	SubscriptionID string `json:"subscription_id"`
	ClientSecret   string `json:"client_secret"`
	ClientID       string `json:"client_id"`
	ResourceGroup  string `json:"resource_group"`
}

AzureCredentials required for cloud provider

func AzureCredentialsFromEnv

func AzureCredentialsFromEnv() (AzureCredentials, error)

AzureCredentialsFromEnv retrives azure credentials from env variables

type GCPCredentials

type GCPCredentials struct {
	AuthProviderX509CertURL string `json:"auth_provider_x509_cert_url,omitempty"`
	AuthURI                 string `json:"auth_uri,omitempty"`
	ClientEmail             string `json:"client_email"`
	ClientID                string `json:"client_id"`
	ClientX509CertURL       string `json:"client_x509_cert_url"`
	PrivateKey              string `json:"private_key"`
	PrivateKeyID            string `json:"private_key_id"`
	ProjectID               string `json:"project_id"`
	TokenURI                string `json:"token_uri,omitempty"`
	Type                    string `json:"type"`
}

GCPCredentials is a struct to hold values retrieved by parsing the GCE credentials json file

type YbaStructuredError added in v0.1.6

type YbaStructuredError struct {
	// User-visible unstructured error message
	Error *interface{} `json:"error,omitempty"`
	// Method for HTTP call that resulted in this error
	HTTPMethod *string `json:"httpMethod,omitempty"`
	// URI for HTTP request that resulted in this error
	RequestURI *string `json:"requestUri,omitempty"`
	// Mostly set to false to indicate failure
	Success *bool `json:"success,omitempty"`
}

YbaStructuredError is a structure mimicking YBPError, with error being an interface{} to accomodate errors thrown as YBPStructuredError

Jump to

Keyboard shortcuts

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