discovery

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 1 Imported by: 0

README

discovery

Go Report Card Documentation license

Border0 service discovery framework and library.

Example: Discover EC2, ECS, and RDS Resources (In Parallel)

Assume that the following variables are defined as follows:

ctx := context.Background()
awsConfig := config.LoadDefaultConfig(ctx)
awsAccountId := "123456789012"

Then,

// initialize a new multiple upstream discoverer
discoverer := discoverers.NewMultipleUpstreamDiscoverer(
	discoverers.WithUpstreamDiscoverers(
		discoverers.NewAwsEc2Discoverer(awsConfig, awsAccountId),
		discoverers.NewAwsEcsDiscoverer(awsConfig, awsAccountId),
		discoverers.NewAwsRdsDiscoverer(awsConfig, awsAccountId),
		// ... docker, k8s, LAN, gcp compute, azure vms, etc ...
	),
)

// create channels for discovered resources and errors
resources := make(chan []discovery.Resource)
errors := make(chan error)

go func() {
	for _, batch := range resources {
		// do something with resources batch
	}
}()
go func() {
	for _, err := range errors {
		// do something with error
	}
}()

// run discoverer
discoverer.Discover(ctx, resources, errors)
Example: Discover EC2 Instances In Multiple AWS Regions (In Parallel)

Assume that the following variables are defined as follows:

ctx := context.Background()
awsConfig := config.LoadDefaultConfig(ctx)
awsAccountId := "123456789012"
awsRegions := []string{"us-east-1", "us-east-2", "us-west-2", "eu-west-1"}

Then,

// initialize a discoverer of the "AwsEc2" implementation per AWS region
ds := []discovery.Discoverer{}
for _, region := range awsRegions {
	awsConfig.Region = region
	ds = append(ds, discoverers.NewAwsEc2Discoverer(awsConfig, awsAccountId))
}

// initialize a new discoverer of the "MultipleUpstreamDiscoverer" implementation
// (which runs multiple other discoverers of any kind in parallel)
d := discoverers.NewMultipleUpstreamDiscoverer(discoverers.WithUpstreamDiscoverers(ds...))

// create channels for discovered resources and errors
resources := make(chan []discovery.Resource)
errors := make(chan error)

go func() {
	for _, batch := range resources {
		// do something with resources batch
	}
}()
go func() {
	for _, err := range errors {
		// do something with error
	}
}()

// run discoverer
d.Discover(ctx, resources, errors)

Documentation

Index

Constants

View Source
const (
	// ResourceTypeAwsEc2Instance is the resource type for AWS EC2 instances.
	ResourceTypeAwsEc2Instance = "aws_ec2_instance"

	// ResourceTypeAwsEcsCluster is the resource type for AWS ECS clusters.
	ResourceTypeAwsEcsCluster = "aws_ecs_cluster"

	// ResourceTypeAwsRdsInstnace is the resource type for AWS RDS instances.
	ResourceTypeAwsRdsInstance = "aws_rds_instance"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AwsBaseDetails

type AwsBaseDetails struct {
	AwsAccountId string `json:"aws_account_id"`
	AwsRegion    string `json:"aws_region"`
	AwsArn       string `json:"aws_arn"`
}

AwsBaseDetails represents the details of a discovered generic AWS resource.

type AwsEc2InstanceDetails

type AwsEc2InstanceDetails struct {
	AwsBaseDetails // extends

	InstanceId       string `json:"instance_id"`
	ImageId          string `json:"ami_id"`
	VpcId            string `json:"vpc_id"`
	SubnetId         string `json:"subnet_id"`
	PrivateDnsName   string `json:"private_dns_name"`
	PrivateIpAddress string `json:"private_ip_address"`
	PublicDnsName    string `json:"public_dns_name"`
	PublicIpAddress  string `json:"public_ip_address"`
	InstanceType     string `json:"instance_type"`
}

AwsEc2InstanceDetails represents the details of a discovered AWS EC2 instance.

type AwsEcsClusterDetails

type AwsEcsClusterDetails struct {
	AwsBaseDetails // extends

	ClusterName string   `json:"cluster_name"`
	Services    []string `json:"services"`
	Tasks       []string `json:"tasks"`
	Containers  []string `json:"containers"`
}

AwsEcsClusterDetails represents the details of a discovered AWS ECS cluster.

type AwsRdsInstanceDetails

type AwsRdsInstanceDetails struct {
	AwsBaseDetails // extends

	DBInstanceIdentifier string `json:"db_instance_identifier"`
	Engine               string `json:"engine"`
	EngineVersion        string `json:"engine_version"`
	VpcId                string `json:"vpc_id"`
	DBSubnetGroupName    string `json:"db_subnet_group_name"`
	EndpointAddress      string `json:"endpoint_address"`
	EndpointPort         int32  `json:"endpoint_port"`
}

AwsRdsInstanceDetails represents the details of a discovered AWS RDS instance.

type Discoverer

type Discoverer interface {
	Discover(context.Context, chan<- []Resource, chan<- error)
}

Discoverer represents an entity capable of discovering resources.

type Resource

type Resource struct {
	ResourceType string `json:"resource_type"`

	AwsEc2InstanceDetails *AwsEc2InstanceDetails `json:"aws_ec2_instance_details,omitempty"`
	AwsEcsClusterDetails  *AwsEcsClusterDetails  `json:"aws_ecs_cluster_details,omitempty"`
	AwsRdsInstanceDetails *AwsRdsInstanceDetails `json:"aws_rds_instance_details,omitempty"`
}

Resource represents a potential Border0 target.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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