csp

package
v0.12.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSecretPath

func BuildSecretPath(ctx context.Context, provider string) string

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 CheckAvailability added in v0.12.7

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 GetString

func GetString(data map[string]interface{}, key string) string

GetString safely extracts a string value from a map.

func LogCSP

func LogCSP(provider, msg string)

LogCSP logs a CSP-related message with consistent prefix.

func ReadOpenBaoSecret

func ReadOpenBaoSecret(ctx context.Context, path string) (map[string]interface{}, error)

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 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).

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").

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.

Jump to

Keyboard shortcuts

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