resourcediscovery

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package resourcediscovery is a cross-service inventory engine. It reads from existing service drivers (compute, networking, storage, database, serverless) and returns a normalized view of every resource a provider holds, with tags resolved per service.

The engine follows the topology package as a precedent: it owns no state, constructs from driver interfaces, and is query-driven. It is the foundation for the SDK-compat handlers in the AWS Resource Explorer + Resource Groups Tagging API, Azure Resource Graph, and GCP Cloud Asset Inventory packages.

Index

Constants

View Source
const (
	ProviderAWS   = "aws"
	ProviderAzure = "azure"
	ProviderGCP   = "gcp"
)

Provider name constants used for routing per-provider ARN construction.

View Source
const (
	ServiceCompute    = "compute"
	ServiceNetworking = "networking"
	ServiceStorage    = "storage"
	ServiceDatabase   = "database"
	ServiceServerless = "serverless"
)

Service name constants embedded in Resource.Service. These are the portable-API service identifiers, not provider-specific names. Callers translate to per-provider service names at the SDK boundary.

View Source
const (
	TypeInstance      = "Instance"
	TypeVPC           = "VPC"
	TypeSubnet        = "Subnet"
	TypeSecurityGroup = "SecurityGroup"
	TypeBucket        = "Bucket"
	TypeTable         = "Table"
	TypeFunction      = "Function"
)

Resource type constants emitted by the walkers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Drivers

type Drivers struct {
	Compute    computedriver.Compute
	Networking netdriver.Networking
	Storage    storagedriver.Bucket
	Database   dbdriver.Database
	Serverless serverlessdriver.Serverless
}

Drivers bundles the per-service drivers the engine reads from. Any field may be nil — the matching walker is skipped in that case. This keeps the engine usable in partial test wirings and during the staged rollout of per-service walkers in later phases.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine walks all configured service drivers and returns a normalized cross-service resource inventory.

func New

func New(provider, accountID, region string, drivers *Drivers) *Engine

New constructs an Engine. provider is one of "aws", "azure", "gcp". accountID is the AWS account ID, Azure subscription ID, or GCP project ID; it is embedded in the ARN/URN of each returned Resource. region is the default region used when a driver does not carry per-resource regions. drivers is passed by pointer because the struct is wider than the gocritic hugeParam threshold; passing nil for any field skips that walker.

func (*Engine) AccountID

func (e *Engine) AccountID() string

AccountID returns the AWS account ID, Azure subscription ID, or GCP project ID the engine was constructed with. Exposed so handlers built on top of the engine (Resource Explorer, Resource Graph, Cloud Asset Inventory) don't have to ask their callers to supply the same value a second time when wiring up the server.

func (*Engine) GetTagKeys

func (e *Engine) GetTagKeys(ctx context.Context) ([]string, error)

GetTagKeys returns the deduplicated, sorted set of tag keys present on any resource across the engine's drivers.

func (*Engine) GetTagValues

func (e *Engine) GetTagValues(ctx context.Context, key string) ([]string, error)

GetTagValues returns the deduplicated, sorted set of values seen for the given tag key across every resource.

func (*Engine) List

func (e *Engine) List(ctx context.Context, q Query) ([]Resource, error)

List walks every configured driver and returns resources matching q. Filtering happens after collection — walkers always return their full set so tag/region resolution is consistent regardless of query shape.

func (*Engine) ListAll

func (e *Engine) ListAll(ctx context.Context) ([]Resource, error)

ListAll walks every configured driver and returns the merged inventory. Nil drivers are skipped silently. The first walker error short-circuits the rest.

func (*Engine) Region

func (e *Engine) Region() string

Region returns the default region the engine was constructed with.

func (*Engine) SearchByTag

func (e *Engine) SearchByTag(ctx context.Context, key, value string) ([]Resource, error)

SearchByTag returns every resource carrying tag key. If value is non-empty, the tag's value must also match exactly.

func (*Engine) TagResourceByARN

func (e *Engine) TagResourceByARN(ctx context.Context, arn string, tags map[string]string) error

TagResourceByARN merges tags into the resource identified by arn. The arn is parsed to determine the underlying service and resource type, then dispatched to the matching driver's tag-mutation method.

Supported in Phase 2:

  • AWS S3 bucket: arn:aws:s3:::name
  • AWS DynamoDB table: arn:aws:dynamodb:region:account:table/name
  • AWS VPC/Subnet/SecurityGroup: arn:aws:ec2:region:account:{vpc,subnet,security-group}/id

Returns InvalidArgument for unsupported services (lambda, ec2 instance, etc.) or unparseable ARNs.

func (*Engine) UntagResourceByARN

func (e *Engine) UntagResourceByARN(ctx context.Context, arn string, keys []string) error

UntagResourceByARN removes the given tag keys from the resource identified by arn. ARN parsing rules match TagResourceByARN.

type Query

type Query struct {
	Services []string
	Type     string
	Region   string
	Tags     map[string]string
}

Query filters a list operation. All non-empty fields must match. Tags match on key presence and (if value is non-empty) equality.

Services is an any-of set: a resource matches if its Service is in the slice. An empty/nil slice means "no service filter". This shape supports cases like AWS's "ec2" which spans both compute and networking — the caller can pass Services: []string{"compute", "networking"}.

type Resource

type Resource struct {
	Provider  string
	Service   string
	Type      string
	ID        string
	ARN       string
	Region    string
	Tags      map[string]string
	CreatedAt time.Time
}

Resource is the normalized cross-cloud resource shape. Every walker emits resources in this form so callers can filter, search, and tag-query uniformly regardless of provider or service.

Jump to

Keyboard shortcuts

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