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
- Variables
- func AdjustKeysToLowercase(cloudInfo *model.CloudInfo)
- func AppendIfMissing(slice []string, i string) []string
- func ChangeIdString(name string) string
- func CheckConfig(id string) (bool, error)
- func CheckConnConfigAvailable(connConfigName string) (bool, error)
- func CheckElement(a string, list []string) bool
- func CheckNodeGroupsOnK8sCreation(providerName string) (*model.K8sClusterNodeGroupsOnCreation, error)
- func CheckNs(id string) (bool, error)
- func CheckSpiderReady() error
- func CheckString(name string) error
- func ConvertToMessage(inType string, inData string, obj interface{}) error
- func ConvertToOutput(outType string, obj interface{}) (string, error)
- func CopySrcToDest(src interface{}, dest interface{}) error
- func CreateNs(u *model.NsReq) (model.NsInfo, error)
- func DelAllNs() error
- func DelNs(id string) error
- func DeleteObject(key string) error
- func DeleteObjects(key string) error
- func EndRequestWithLog(c echo.Context, reqID string, err error, responseData interface{}) error
- func ExecuteHttpRequest[B any, T any](client *resty.Client, method string, url string, headers map[string]string, ...) error
- func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) (interface{}, error)
- func GenChildResourceKey(nsId string, resourceType string, parentResourceId string, resourceId string) string
- func GenConnectionKey(connectionId string) string
- func GenCredentialHolderKey(holderId string) string
- func GenMciKey(nsId string, mciId string, vmId string) string
- func GenMciPolicyKey(nsId string, mciId string, vmId string) string
- func GenMciSubGroupKey(nsId string, mciId string, groupId string) string
- func GenRandomPassword(length int) string
- func GenResourceKey(nsId string, resourceType string, resourceId string) string
- func GenUid() string
- func GenerateNewRandomString(n int) string
- func GetAvailableK8sClusterNodeImage(providerName string, regionName string) (*[]model.K8sClusterNodeImageDetailAvailable, error)
- func GetAvailableK8sClusterVersion(providerName string, regionName string) (*[]model.K8sClusterVersionDetailAvailable, error)
- func GetChildIdList(key string) []string
- func GetCloudInfo() (model.CloudInfo, error)
- func GetConfig(id string) (model.ConfigInfo, error)
- func GetConnConfig(ConnConfigName string) (model.ConnConfig, error)
- func GetConnConfigList(filterCredentialHolder string, filterVerified bool, ...) (model.ConnConfigList, error)
- func GetFuncName() string
- func GetK8sClusterInfo() (model.K8sClusterInfo, error)
- func GetNs(id string) (model.NsInfo, error)
- func GetObjectList(key string) []string
- func GetObjectValue(key string) (string, error)
- func GetProviderList() (*model.IdList, error)
- func GetPublicKeyForCredentialEncryption() (model.PublicKeyResponse, error)
- func GetRegion(ProviderName, RegionName string) (model.RegionDetail, error)
- func GetRegions(ProviderName string) (model.RegionList, error)
- func InitAllConfig() error
- func InitConfig(id string) error
- func ListConfig() ([]model.ConfigInfo, error)
- func ListConfigId() []string
- func ListNs() ([]model.NsInfo, error)
- func ListNsId() ([]string, error)
- func LookupKeyValueList(kvl []model.KeyValue, key string) string
- func NVL(str string, def string) string
- func NsValidation() echo.MiddlewareFunc
- func OpenSQL(path string) error
- func PrintCloudInfoTable(cloudInfo model.CloudInfo)
- func PrintCredentialInfo(credential model.Credential)
- func PrintJsonPretty(v interface{})
- func RandomSleep(from int, to int)
- func RegisterAllCloudInfo() error
- func RegisterCloudInfo(providerName string) error
- func RegisterConnectionConfig(connConfig model.ConnConfig) (model.ConnConfig, error)
- func RegisterCredential(req model.CredentialReq) (model.CredentialInfo, error)
- func RegisterRegionZone(providerName string, regionName string) error
- func RetrieveRegionListFromCsp() (model.RetrievedRegionList, error)
- func SelectDatabase(database string) error
- func SetUseBody(requestBody interface{}) bool
- func StartRequestWithLog(c echo.Context) (string, error)
- func ToLower(name string) string
- func UpdateConfig(u *model.ConfigReq) (model.ConfigInfo, error)
- func UpdateGlobalVariable(id string) error
- func UpdateNs(id string, u *model.NsReq) (model.NsInfo, error)
- func UpdateRequestProgress(reqID string, progressData interface{})
- type CacheItem
- type ProgressInfo
- type RequestDetails
- type RequestInfo
Constants ¶
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 )
const NoBody = "NOBODY"
NoBody is a constant for empty body
Variables ¶
var RequestMap = sync.Map{}
RequestMap is a map for request details
var RuntimeCloudInfo = model.CloudInfo{}
RuntimeCloudInfo is global variable for model.CloudInfo
var RuntimeConf = model.RuntimeConfig{}
RuntimeConf is global variable for cloud config
var RuntimeCredential = model.Credential{}
var RuntimeK8sClusterInfo = model.K8sClusterInfo{}
RuntimeK8sClusterInfo is global variable for model.K8sClusterInfo
var RuntimeLatancyMap = [][]string{}
RuntimeLatancyMap is global variable for LatancyMap
var RuntimeLatancyMapIndex = make(map[string]int)
RuntimeLatancyMapIndex is global variable for LatancyMap (index)
Functions ¶
func AdjustKeysToLowercase ¶ added in v0.8.7
AdjustKeysToLowercase adjusts the keys of nested maps to lowercase.
func AppendIfMissing ¶ added in v0.3.11
func ChangeIdString ¶ added in v0.5.4
ChangeIdString is func to change strings in id or name (special chars to -, to lower string )
func CheckConfig ¶ added in v0.3.1
func CheckConnConfigAvailable ¶ added in v0.8.8
CheckConnConfigAvailable is func to check if connection config is available by checking allkeypair list
func CheckElement ¶ added in v0.6.4
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 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
CheckString is func to check string by the given rule `[a-z]([-a-z0-9]*[a-z0-9])?`
func ConvertToMessage ¶
ConvertToMessage is func to change input data to gRPC message
func ConvertToOutput ¶
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 DeleteObject ¶ added in v0.3.3
DeleteObject is func to delete the object
func DeleteObjects ¶ added in v0.3.3
DeleteObjects is func to delete objects
func EndRequestWithLog ¶ added in v0.7.13
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
GenConnectionKey is func to generate a key for connection info
func GenCredentialHolderKey ¶ added in v0.8.9
GenCredentialHolderKey is func to generate a key for credentialHolder info
func GenMciPolicyKey ¶ added in v0.9.5
GenMciPolicyKey is func to generate Mci policy key
func GenMciSubGroupKey ¶ added in v0.9.5
GenMciSubGroupKey is func to generate a key from subGroupId used in keyValue store
func GenRandomPassword ¶ added in v0.7.1
GenRandomPassword is func to return a RandomPassword
func GenResourceKey ¶
GenResourceKey is func to generate a key from resource type and id
func GenerateNewRandomString ¶ added in v0.6.7
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 ¶
GetChildIdList is func to get child id list from given key
func GetCloudInfo ¶ added in v0.8.7
GetCloudInfo is func to get all cloud info from the asset
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 GetObjectList ¶ added in v0.3.3
GetObjectList is func to return IDs of each child objects that has the same key
func GetObjectValue ¶ added in v0.3.3
GetObjectValue is func to return the object value
func GetProviderList ¶ added in v0.8.9
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 ListConfig ¶
func ListConfig() ([]model.ConfigInfo, error)
func ListConfigId ¶
func ListConfigId() []string
func LookupKeyValueList ¶
LookupKeyValueList is func to lookup model.KeyValue list
func NsValidation ¶
func NsValidation() echo.MiddlewareFunc
func PrintCloudInfoTable ¶ added in v0.8.5
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
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
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
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 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
StartRequestWithLog initializes request tracking details
func ToLower ¶ added in v0.3.1
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 UpdateRequestProgress ¶ added in v0.8.13
func UpdateRequestProgress(reqID string, progressData interface{})
UpdateRequestProgress updates the handling status of the request.
Types ¶
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