common

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 32 Imported by: 1

Documentation

Overview

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Package common is to include common methods for managing multi-cloud infra

Index

Constants

View Source
const (
	// VeryShortDuration is a duration for very short-term cache
	VeryShortDuration = 1 * time.Second
	// ShortDuration is a duration for short-term cache
	ShortDuration = 2 * time.Second
	// MediumDuration is a duration for medium-term cache
	MediumDuration = 5 * time.Second
	// LongDuration is a duration for long-term cache
	LongDuration = 10 * time.Second
)
View Source
const NoBody = "NOBODY"

NoBody is a constant for empty body

Variables

View Source
var RequestMap = sync.Map{}

RequestMap is a map for request details

View Source
var RuntimeCloudInfo = model.CloudInfo{}

RuntimeCloudInfo is global variable for model.CloudInfo

View Source
var RuntimeConf = model.RuntimeConfig{}

RuntimeConf is global variable for cloud config

View Source
var RuntimeCredential = model.Credential{}
View Source
var RuntimeK8sClusterInfo = model.K8sClusterInfo{}

RuntimeK8sClusterInfo is global variable for model.K8sClusterInfo

View Source
var RuntimeLatancyMap = [][]string{}

RuntimeLatancyMap is global variable for LatancyMap

View Source
var RuntimeLatancyMapIndex = make(map[string]int)

RuntimeLatancyMapIndex is global variable for LatancyMap (index)

Functions

func AdjustKeysToLowercase added in v0.8.7

func AdjustKeysToLowercase(cloudInfo *model.CloudInfo)

AdjustKeysToLowercase adjusts the keys of nested maps to lowercase.

func AppendIfMissing added in v0.3.11

func AppendIfMissing(slice []string, i string) []string

func ChangeIdString added in v0.5.4

func ChangeIdString(name string) string

ChangeIdString is func to change strings in id or name (special chars to -, to lower string )

func CheckConfig added in v0.3.1

func CheckConfig(id string) (bool, error)

func CheckConnConfigAvailable added in v0.8.8

func CheckConnConfigAvailable(connConfigName string) (bool, error)

CheckConnConfigAvailable is func to check if connection config is available by checking allkeypair list

func CheckElement added in v0.6.4

func CheckElement(a string, list []string) bool

func CheckNodeGroupsOnK8sCreation added in v0.9.5

func CheckNodeGroupsOnK8sCreation(providerName string) (*model.K8sClusterNodeGroupsOnCreation, error)

CheckNodeGroupsOnK8sCreation is func to check whether nodegroups are required during the k8scluster creation

func CheckNs added in v0.3.1

func CheckNs(id string) (bool, error)

func CheckSpiderReady added in v0.8.8

func CheckSpiderReady() error

CheckSpiderStatus is func to check if CB-Spider is ready

func CheckString added in v0.3.7

func CheckString(name string) error

CheckString is func to check string by the given rule `[a-z]([-a-z0-9]*[a-z0-9])?`

func ConvertToMessage

func ConvertToMessage(inType string, inData string, obj interface{}) error

ConvertToMessage is func to change input data to gRPC message

func ConvertToOutput

func ConvertToOutput(outType string, obj interface{}) (string, error)

ConvertToOutput is func to convert gRPC message to print format

func CopySrcToDest

func CopySrcToDest(src interface{}, dest interface{}) error

CopySrcToDest is func to copy data from source to target

func CreateNs

func CreateNs(u *model.NsReq) (model.NsInfo, error)

func DelAllNs

func DelAllNs() error

func DelNs

func DelNs(id string) error

func DeleteObject added in v0.3.3

func DeleteObject(key string) error

DeleteObject is func to delete the object

func DeleteObjects added in v0.3.3

func DeleteObjects(key string) error

DeleteObjects is func to delete objects

func EndRequestWithLog added in v0.7.13

func EndRequestWithLog(c echo.Context, reqID string, err error, responseData interface{}) error

EndRequestWithLog updates the request details and sends the final response.

func ExecuteHttpRequest added in v0.7.5

func ExecuteHttpRequest[B any, T any](
	client *resty.Client,
	method string,
	url string,
	headers map[string]string,
	useBody bool,
	body *B,
	result *T,
	cacheDuration time.Duration,
) error

ExecuteHttpRequest performs the HTTP request and fills the result (var requestBody interface{} = nil for empty body)

func ForwardRequestToAny added in v0.8.1

func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) (interface{}, error)

ForwardRequestToAny forwards the given request to the specified path

func GenChildResourceKey added in v0.4.10

func GenChildResourceKey(nsId string, resourceType string, parentResourceId string, resourceId string) string

GenChildResourceKey is func to generate a key from resource type and id

func GenConnectionKey added in v0.8.8

func GenConnectionKey(connectionId string) string

GenConnectionKey is func to generate a key for connection info

func GenCredentialHolderKey added in v0.8.9

func GenCredentialHolderKey(holderId string) string

GenCredentialHolderKey is func to generate a key for credentialHolder info

func GenMciKey added in v0.9.5

func GenMciKey(nsId string, mciId string, vmId string) string

GenMciKey is func to generate a key used in keyValue store

func GenMciPolicyKey added in v0.9.5

func GenMciPolicyKey(nsId string, mciId string, vmId string) string

GenMciPolicyKey is func to generate Mci policy key

func GenMciSubGroupKey added in v0.9.5

func GenMciSubGroupKey(nsId string, mciId string, groupId string) string

GenMciSubGroupKey is func to generate a key from subGroupId used in keyValue store

func GenRandomPassword added in v0.7.1

func GenRandomPassword(length int) string

GenRandomPassword is func to return a RandomPassword

func GenResourceKey

func GenResourceKey(nsId string, resourceType string, resourceId string) string

GenResourceKey is func to generate a key from resource type and id

func GenUid added in v0.4.10

func GenUid() string

GenUid is func to return a uid string

func GenerateNewRandomString added in v0.6.7

func GenerateNewRandomString(n int) string

generate a random string (from CB-MCKS source code)

func GetAvailableK8sClusterNodeImage added in v0.8.14

func GetAvailableK8sClusterNodeImage(providerName string, regionName string) (*[]model.K8sClusterNodeImageDetailAvailable, error)

GetAvailableK8sClusterNodeImage is func to get available kubernetes cluster node images for provider and region from model.K8sClusterInfo

func GetAvailableK8sClusterVersion added in v0.8.14

func GetAvailableK8sClusterVersion(providerName string, regionName string) (*[]model.K8sClusterVersionDetailAvailable, error)

GetAvailableK8sClusterVersion is func to get available kubernetes cluster versions for provider and region from model.K8sClusterInfo

func GetChildIdList

func GetChildIdList(key string) []string

GetChildIdList is func to get child id list from given key

func GetCloudInfo added in v0.8.7

func GetCloudInfo() (model.CloudInfo, error)

GetCloudInfo is func to get all cloud info from the asset

func GetConfig

func GetConfig(id string) (model.ConfigInfo, error)

func GetConnConfig

func GetConnConfig(ConnConfigName string) (model.ConnConfig, error)

GetConnConfig is func to get connection config

func GetConnConfigList

func GetConnConfigList(filterCredentialHolder string, filterVerified bool, filterRegionRepresentative bool) (model.ConnConfigList, error)

GetConnConfigList is func to list filtered connection configs

func GetFuncName added in v0.5.4

func GetFuncName() string

GetFuncName is func to get the name of the running function

func GetK8sClusterInfo added in v0.8.14

func GetK8sClusterInfo() (model.K8sClusterInfo, error)

GetK8sClusterInfo is func to get all kubernetes cluster info from the asset

func GetNs

func GetNs(id string) (model.NsInfo, error)

func GetObjectList added in v0.3.3

func GetObjectList(key string) []string

GetObjectList is func to return IDs of each child objects that has the same key

func GetObjectValue added in v0.3.3

func GetObjectValue(key string) (string, error)

GetObjectValue is func to return the object value

func GetProviderList added in v0.8.9

func GetProviderList() (*model.IdList, error)

GetProviderList is func to list all cloud providers

func GetPublicKeyForCredentialEncryption added in v0.9.7

func GetPublicKeyForCredentialEncryption() (model.PublicKeyResponse, error)

GetPublicKeyForCredentialEncryption generates an RSA key pair, stores the private key in memory, and returns the public key along with its token ID.

func GetRegion

func GetRegion(ProviderName, RegionName string) (model.RegionDetail, error)

GetRegion is func to get regionInfo with the native region name

func GetRegions added in v0.9.10

func GetRegions(ProviderName string) (model.RegionList, error)

GetRegions is func to get regionInfo list

func InitAllConfig added in v0.3.9

func InitAllConfig() error

func InitConfig added in v0.3.9

func InitConfig(id string) error

func ListConfig

func ListConfig() ([]model.ConfigInfo, error)

func ListConfigId

func ListConfigId() []string

func ListNs

func ListNs() ([]model.NsInfo, error)

func ListNsId

func ListNsId() ([]string, error)

func LookupKeyValueList

func LookupKeyValueList(kvl []model.KeyValue, key string) string

LookupKeyValueList is func to lookup model.KeyValue list

func NVL

func NVL(str string, def string) string

NVL is func for null value logic

func NsValidation

func NsValidation() echo.MiddlewareFunc

func OpenSQL

func OpenSQL(path string) error

func PrintCloudInfoTable added in v0.8.5

func PrintCloudInfoTable(cloudInfo model.CloudInfo)

PrintCloudInfoTable prints model.CloudInfo in table format

func PrintCredentialInfo added in v0.8.8

func PrintCredentialInfo(credential model.Credential)

PrintCredentialInfo prints model.Credential information in table format

func PrintJsonPretty

func PrintJsonPretty(v interface{})

PrintJsonPretty is func to print JSON pretty with indent

func RandomSleep added in v0.4.10

func RandomSleep(from int, to int)

RandomSleep is func to make a caller waits for during random time seconds (random value within x~y)

func RegisterAllCloudInfo added in v0.8.8

func RegisterAllCloudInfo() error

RegisterAllCloudInfo is func to register all cloud info from asset to CB-Spider

func RegisterCloudInfo added in v0.8.8

func RegisterCloudInfo(providerName string) error

RegisterCloudInfo is func to register cloud info from asset to CB-Spider

func RegisterConnectionConfig added in v0.8.8

func RegisterConnectionConfig(connConfig model.ConnConfig) (model.ConnConfig, error)

RegisterConnectionConfig is func to register connection config to CB-Spider

func RegisterCredential added in v0.8.8

func RegisterCredential(req model.CredentialReq) (model.CredentialInfo, error)

RegisterCredential is func to register credential and all related connection configs

func RegisterRegionZone added in v0.8.8

func RegisterRegionZone(providerName string, regionName string) error

RegisterRegionZone is func to register all regions to CB-Spider

func RetrieveRegionListFromCsp added in v0.9.10

func RetrieveRegionListFromCsp() (model.RetrievedRegionList, error)

RetrieveRegionListFromCsp is func to retrieve region list

func SelectDatabase

func SelectDatabase(database string) error

func SetUseBody added in v0.7.6

func SetUseBody(requestBody interface{}) bool

SetUseBody returns false if the given body is NoBody

func StartRequestWithLog added in v0.7.13

func StartRequestWithLog(c echo.Context) (string, error)

StartRequestWithLog initializes request tracking details

func ToLower added in v0.3.1

func ToLower(name string) string

ToLower is func to change strings (_ to -, " " to -, to lower string ) (deprecated soon)

func UpdateConfig

func UpdateConfig(u *model.ConfigReq) (model.ConfigInfo, error)

func UpdateGlobalVariable added in v0.3.9

func UpdateGlobalVariable(id string) error

func UpdateNs added in v0.5.5

func UpdateNs(id string, u *model.NsReq) (model.NsInfo, error)

UpdateNs is func to update namespace info

func UpdateRequestProgress added in v0.8.13

func UpdateRequestProgress(reqID string, progressData interface{})

UpdateRequestProgress updates the handling status of the request.

Types

type CacheItem added in v0.7.5

type CacheItem[T any] struct {
	Response  T
	ExpiresAt time.Time
}

CacheItem is a struct to store cached item

type ProgressInfo added in v0.8.13

type ProgressInfo struct {
	Title string      `json:"title"`
	Info  interface{} `json:"info"`
	Time  time.Time   `json:"time"`
}

ProgressInfo contains the progress information of a request.

type RequestDetails added in v0.7.13

type RequestDetails struct {
	StartTime     time.Time   `json:"startTime"`     // The time when the request was received by the server.
	EndTime       time.Time   `json:"endTime"`       // The time when the request was fully processed.
	Status        string      `json:"status"`        // The current status of the request (e.g., "Handling", "Error", "Success").
	RequestInfo   RequestInfo `json:"requestInfo"`   // Extracted information about the request.
	ResponseData  interface{} `json:"responseData"`  // The data sent back in response to the request.
	ErrorResponse string      `json:"errorResponse"` // A message describing any error that occurred during request processing.
}

RequestDetails contains detailed information about an HTTP request and its processing status.

type RequestInfo added in v0.7.13

type RequestInfo struct {
	Method string            `json:"method"`         // HTTP method (GET, POST, etc.), indicating the request's action type.
	URL    string            `json:"url"`            // The URL the request is made to.
	Header map[string]string `json:"header"`         // Key-value pairs of the request headers.
	Body   interface{}       `json:"body,omitempty"` // Optional: request body
}

RequestInfo stores the essential details of an HTTP request.

func ExtractRequestInfo added in v0.7.13

func ExtractRequestInfo(r *http.Request) RequestInfo

ExtractRequestInfo extracts necessary information from http.Request

Directories

Path Synopsis
Package label is to handle label selector for resources
Package label is to handle label selector for resources

Jump to

Keyboard shortcuts

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