cloud

package
v1.54.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GCPCloud   = "gcp_project_numerical_id"
	AWSCloud   = "aws_account_id"
	AzureCloud = "azure_subscription_id"
)

Cloud provider constants

Variables

View Source
var (

	// ErrNotInCloud is returned when the code is not running in the respective cloud provider
	ErrNotInCloud = errors.New("not running in cloud provider")
)

Functions

func Detect added in v1.53.0

func Detect()

Detect runs the cloud detection logic and caches the result. Detectors are tried in registration order, and the first one that succeeds is used. Any error is ignored, and the next detector is tried.

func GetAWSAccountID added in v1.53.0

func GetAWSAccountID() (string, error)

GetAWSAccountID retrieves AWS account ID using STS.

func GetAzureSubscriptionID added in v1.53.0

func GetAzureSubscriptionID() (string, error)

GetAzureSubscriptionID retrieves the Azure Subscription ID using the armsubscriptions package.

func GetGCPProjectID added in v1.53.0

func GetGCPProjectID() (string, error)

GetGCPProjectID retrieves the GCP numerical project ID.

func GetHashedInformation added in v1.53.0

func GetHashedInformation() (string, string, bool)

GetHashedInformation returns the detected cloud type, cloud ID (hashed), and detection status.

func GetHashedInformationCached added in v1.53.0

func GetHashedInformationCached() (string, string, bool)

GetHashedInformationCached returns the detected cloud type, cloud ID (hashed), and detection status.

func RegisterDefaultDetectors added in v1.54.0

func RegisterDefaultDetectors()

RegisterDefaultDetectors registers the built-in cloud detectors

maintained the order: GCP first, then AWS, then Azure

func RegisterDetector added in v1.53.0

func RegisterDetector(name string, detector DetectorFunc)

RegisterDetector registers a new cloud detector with the given name

func Reset added in v1.53.0

func Reset()

Reset clears all registered detectors, mainly used for testing

Types

type DetectorFunc added in v1.53.0

type DetectorFunc func() (string, error)

DetectorFunc is a function type that detects a cloud provider and returns its ID

type MetadataProvider

type MetadataProvider struct{}

MetadataProvider collecting cloud environment metadata. Implements the stats.MetadataProvider interface

func NewMetadataProvider added in v1.53.0

func NewMetadataProvider() *MetadataProvider

NewMetadataProvider creates a new MetadataProvider

func (*MetadataProvider) GetMetadata

func (p *MetadataProvider) GetMetadata(ctx context.Context) (map[string]string, error)

GetMetadata returns cloud metadata information as a map It returns the detected cloud type and a hashed version of the cloud ID

Jump to

Keyboard shortcuts

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