Documentation
¶
Overview ¶
Package csp provides direct CSP (Cloud Service Provider) API call utilities. This bypasses CB-Spider for cases where direct SDK calls are more efficient or where CB-Spider does not provide the needed functionality.
Index ¶
- func ApplyCredentialKeyMap(provider string, kvList []model.KeyValue) map[string]any
- func BuildSecretPath(ctx context.Context, provider string) string
- func BuildSecretPathForHolder(holder, provider string) string
- func CheckAvailability(ctx context.Context, q model.AvailabilityQuery) model.AvailabilityResult
- func GetString(data map[string]any, key string) string
- func LogCSP(provider, msg string)
- func ReadOpenBaoSecret(ctx context.Context, path string) (map[string]any, error)
- func RegisterAvailabilityChecker(c AvailabilityChecker)
- func RegisterBatchTagHandler(platform string, handler BatchTagHandler)
- func RegisterBatchVMControlHandlers(provider string, h BatchVMControlHandlers)
- func RegisterBatchVMStatusHandler(provider string, fn BatchVMStatusFunc)
- func TryBatchUpsertTags(ctx context.Context, ...) (bool, error)
- func WriteOpenBaoSecret(ctx context.Context, path string, data map[string]any) error
- type AvailabilityChecker
- type BatchTagHandler
- type BatchVMControlFunc
- type BatchVMControlHandlers
- type BatchVMStatusFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyCredentialKeyMap ¶ added in v0.12.11
ApplyCredentialKeyMap transforms a credential key-value list using the CSP-specific key mapping. Keys not present in the map are passed through unchanged.
func BuildSecretPath ¶
BuildSecretPath builds the OpenBao secret path for a given CSP provider based on the credential holder from context. For "admin" holder: "secret/data/csp/{provider}" For other holders: "secret/data/users/{holder}/csp/{provider}"
func BuildSecretPathForHolder ¶ added in v0.12.11
BuildSecretPathForHolder builds the OpenBao secret path using holder and provider directly. Both holder and provider are lowercased to stay consistent with BuildSecretPath.
func CheckAvailability ¶ added in v0.12.7
func CheckAvailability(ctx context.Context, q model.AvailabilityQuery) model.AvailabilityResult
CheckAvailability dispatches to the registered checker for q.Provider and caches the result for availabilityTTL. Concurrent misses for the same (provider, region, instanceType, disk) are deduplicated via singleflight.
If no checker is registered for the provider, the function returns a "no-checker" result with Available=true so that callers can proceed. All checker errors are also turned into non-fatal "Available=true" results with the error captured in Reason; this is intentional to avoid blocking provisioning on pre-check failures.
func LogCSP ¶
func LogCSP(provider, msg string)
LogCSP logs a CSP-related message with consistent prefix.
func ReadOpenBaoSecret ¶
ReadOpenBaoSecret reads a secret from OpenBao at the given path and returns the data map. It validates that VaultToken is set and the secret exists. A context is used for request-scoped cancellation and timeout.
func RegisterAvailabilityChecker ¶ added in v0.12.7
func RegisterAvailabilityChecker(c AvailabilityChecker)
RegisterAvailabilityChecker registers a CSP-specific checker. It is safe to call from package init() functions.
func RegisterBatchTagHandler ¶
func RegisterBatchTagHandler(platform string, handler BatchTagHandler)
RegisterBatchTagHandler registers a batch tag upsert handler for a CSP. Called by CSP-specific packages during init().
func RegisterBatchVMControlHandlers ¶ added in v0.12.9
func RegisterBatchVMControlHandlers(provider string, h BatchVMControlHandlers)
RegisterBatchVMControlHandlers registers bulk lifecycle control functions for a CSP. Each CSP package calls this from its init() function.
func RegisterBatchVMStatusHandler ¶ added in v0.12.9
func RegisterBatchVMStatusHandler(provider string, fn BatchVMStatusFunc)
RegisterBatchVMStatusHandler registers a direct-SDK batch VM status function for a CSP. Each CSP package calls this from its init() function.
func TryBatchUpsertTags ¶
func TryBatchUpsertTags(ctx context.Context, providerName, region, zone, cspResourceId, resourceType string, tags map[string]string) (bool, error)
TryBatchUpsertTags attempts to upsert multiple tags on a CSP resource in a single API call. resourceType is the CB-Tumblebug label type (e.g., "node", "vNet", "sshKey"). region is the CSP region, zone is the availability zone (used by GCP; can be empty for others). Returns (true, nil) if successfully handled by a direct CSP batch API. Returns (false, nil) if no batch handler exists for this CSP (caller should fall back to Spider). Returns (false, err) if a batch handler exists but failed (caller should fall back to Spider).
func WriteOpenBaoSecret ¶ added in v0.12.11
WriteOpenBaoSecret writes key-value data to OpenBao at the given KV v2 path (upsert). ctx allows request-scoped cancellation and timeout, consistent with ReadOpenBaoSecret.
Types ¶
type AvailabilityChecker ¶ added in v0.12.7
type AvailabilityChecker interface {
// Provider returns the CSP identifier (must match model/csp constants).
Provider() string
// CheckInstance performs a pre-flight availability query for the given
// instance type in the given region. Implementations should populate
// Zones with per-zone disk-category availability when their CSP API
// supports it. Implementations should return non-fatal results: a true
// inability to determine availability should be returned as
// (result with Available=true, Reason="...") with err=nil so that
// provisioning is never blocked solely by a checker failure.
CheckInstance(ctx context.Context, q model.AvailabilityQuery) (model.AvailabilityResult, error)
}
AvailabilityChecker is implemented by CSP-specific packages and registered via Register at init() time.
type BatchTagHandler ¶
type BatchTagHandler func(ctx context.Context, region, zone, cspResourceId, resourceType string, tags map[string]string) error
BatchTagHandler defines the function signature for CSP-specific batch tag upsert. Returns error if the operation fails. The handler should set all given tags on the CSP resource identified by cspResourceId in a single API call. resourceType is the CB-Tumblebug label type (e.g., "node", "vNet", "sshKey"). region is the CSP region (e.g., "us-east-1"), zone is the availability zone (e.g., "us-east-1a").
type BatchVMControlFunc ¶ added in v0.12.9
type BatchVMControlFunc func(ctx context.Context, region string, instanceIds []string) (map[string]string, error)
BatchVMControlFunc sends a lifecycle control action to multiple instances in one SDK call. ctx must carry model.CtxKeyCredentialHolder for credential lookup. region is the CSP-native region identifier (e.g., "ap-northeast-2" for AWS). instanceIds are the CspResourceId values for each VM.
Returns a map of CspResourceId → transient TB status string (e.g., model.StatusSuspending). Missing keys mean the instance was not found or accepted; callers treat them as failed.
func GetBatchVMControlHandler ¶ added in v0.12.9
func GetBatchVMControlHandler(provider, action string) (BatchVMControlFunc, bool)
GetBatchVMControlHandler returns the bulk control function for the given provider and action. action is case-insensitive: "suspend", "resume", or "terminate".
type BatchVMControlHandlers ¶ added in v0.12.9
type BatchVMControlHandlers struct {
Suspend BatchVMControlFunc // e.g. AWS StopInstances
Resume BatchVMControlFunc // e.g. AWS StartInstances
Terminate BatchVMControlFunc // e.g. AWS TerminateInstances
}
BatchVMControlHandlers groups bulk lifecycle control functions for a CSP. Reboot is excluded — it is rare, order-sensitive, and not cost-effective to batch.
type BatchVMStatusFunc ¶ added in v0.12.9
type BatchVMStatusFunc func(ctx context.Context, region string, instanceIds []string) (map[string]string, error)
BatchVMStatusFunc queries a CSP directly for the statuses of the given resource IDs. ctx must carry model.CtxKeyCredentialHolder for credential lookup. region is the CSP-specific region identifier (e.g., "ap-northeast-2" for AWS). instanceIds are the CspResourceId values for each VM — format varies per CSP:
AWS / Alibaba: "i-0abc123def456"
Tencent: "ins-xxxxxxxx"
Azure: full ARM path "/subscriptions/{sub}/resourceGroups/{rg}/.../virtualMachines/{name}"
GCP: instance name (zone-scoped; region used for zone-prefix filtering)
Returns a map of CspResourceId → TB status string (model.StatusRunning, etc.). Missing keys mean the instance was not found; treat as model.StatusUndefined.
func GetBatchVMStatusHandler ¶ added in v0.12.9
func GetBatchVMStatusHandler(provider string) (BatchVMStatusFunc, bool)
GetBatchVMStatusHandler returns the registered BatchVMStatusFunc for the given provider.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package alibaba provides direct-SDK helpers for Alibaba Cloud that complement the cb-spider based flow of cb-tumblebug.
|
Package alibaba provides direct-SDK helpers for Alibaba Cloud that complement the cb-spider based flow of cb-tumblebug. |
|
Package azure provides direct Azure API call utilities for cases where CB-Spider is too slow or does not provide adequate functionality.
|
Package azure provides direct Azure API call utilities for cases where CB-Spider is too slow or does not provide adequate functionality. |