discover

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FromCache = "cache"
	FromAWS   = "aws"
)

Where a region came from.

View Source
const (
	AccountStarted = "started"
	AccountDone    = "done"
)

Account states of an AccountEvent.

View Source
const (
	KindRDSInstance = "rds-instance"
	KindRDSCluster  = "rds-cluster"
)

The kinds of a standalone workload's resource beyond the backend kinds (KindInstance, KindASG, KindECS).

View Source
const (
	KindInstance = "instance"
	KindASG      = "asg"
	KindECS      = "ecs"
	KindK8s      = "k8s"
)

Backend kinds of a candidate.

View Source
const (
	Managed    = "managed"
	Eligible   = "eligible"
	Ineligible = "ineligible"
)

Eligibility of a candidate.

View Source
const KindStandalone = "standalone"

KindStandalone is a standalone candidate's kind (an HTTP candidate has none).

View Source
const PhaseDiscovery = "discovery"

PhaseDiscovery is the Phase of the events discovery emits (Node's phases are discovery, requests and uptime).

View Source
const RefreshDiscovery = "discovery"

Refresh values: --refresh discovery scans everything again.

Variables

View Source
var ResourceKindText = map[string]string{
	KindInstance: "instance", KindASG: "Auto Scaling group", KindECS: "ECS service",
	KindRDSInstance: "RDS instance", KindRDSCluster: "RDS cluster",
}

ResourceKindText is each resource kind as the router's texts say it.

Functions

func AllWith added in v0.16.0

AllWith is All with the regions' standalone parts (o.Standalone), in the same order: a region that failed has none.

func ClusterOf

func ClusterOf(serviceArn string) string

ClusterOf is the ECS cluster of a service ARN (arn:aws:ecs:<region>:<account>:service/<cluster>/<service>); the old format (service/<service>) is in the default cluster.

func DescribeCriterion

func DescribeCriterion(c Criterion) string

DescribeCriterion says what the criterion sets ("account 111111111111, region eu-west-1"), for reasons and lint messages.

func GlobMatches

func GlobMatches(pattern, value string) bool

GlobMatches reports whether value matches a pattern with * wildcards, ignoring case.

func IsAccountID added in v0.6.0

func IsAccountID(s string) bool

IsAccountID tells whether s is an AWS account id: 12 digits.

func LBDimension

func LBDimension(arn string) string

LBDimension is the CloudWatch LoadBalancer dimension of a load balancer ARN.

func Matches

func Matches(c Criterion, a Account, r ScannedRule, _ OrgInventory) bool

Matches reports whether the criterion matches a scanned rule of an account: every dimension it sets must match.

func RegionWith added in v0.16.0

func RegionWith(ctx context.Context, ports RegionPorts, where Where, standalone bool) (RegionDiscovery, *StandaloneRegion, error)

RegionWith is Region, with the standalone scan when standalone (ports.Standalone; nil: a scan without it): its part is then the region's standalone resources described (nil when not standalone).

func ResourceTagsMatch

func ResourceTagsMatch(wanted, tags map[string][]string) bool

ResourceTagsMatch: each wanted key on the load balancer, the target group or the rule, with one of the values (none: any value).

func TGDimension

func TGDimension(arn string) string

TGDimension is the CloudWatch TargetGroup dimension of a target group ARN.

func WorkloadIDOf added in v0.16.0

func WorkloadIDOf(arn string) string

WorkloadIDOf is the router's workload id of a resource: the first 16 hex characters of the SHA-256 of its ARN.

Types

type ASGInstance

type ASGInstance struct {
	InstanceId string `json:"InstanceId,omitempty"`
}

ASGInstance is an instance of an Auto Scaling group.

type Account

type Account struct {
	ID     string            `json:"id"`
	Name   string            `json:"name"`
	OUPath []string          `json:"ouPath"` // root first, parent last
	Tags   map[string]string `json:"tags"`
}

Account is an active account of the organization.

type AccountEvent

type AccountEvent struct {
	Account string `json:"account"`
	State   string `json:"state"` // started or done
	Regions int    `json:"regions"`
	Error   string `json:"error,omitempty"`
}

AccountEvent is an account of the discovery phase: started once its regions are known, done after the last (Error: its regions could not be listed, or its credentials not obtained).

type AccountPlan

type AccountPlan struct {
	Account string `json:"account"`
	Scan    bool   `json:"scan"`
	Reason  string `json:"reason"`
}

AccountPlan says whether an account is scanned.

func ScanAccounts

func ScanAccounts(cfg Config, inv OrgInventory) []AccountPlan

ScanAccounts says, for each account of the inventory, whether it is scanned.

type Action

type Action struct {
	Type           string         `json:"Type,omitempty"`
	Order          int            `json:"Order,omitempty"`
	TargetGroupArn string         `json:"TargetGroupArn,omitempty"`
	ForwardConfig  *ForwardConfig `json:"ForwardConfig,omitempty"`
}

Action is a rule's action.

type AllOptions

type AllOptions struct {
	// Accounts in the organization's order; Unreachable says whether an account
	// was listed apart as refusing its role (asked when it fails; nil: none).
	Accounts    []Target
	Unreachable func(account string) bool
	// Regions is --regions, used as given (never cached as an account's enabled
	// regions); nil: each account's enabled ones (RegionsOf).
	Regions   []string
	RegionsOf func(ctx context.Context, account string, creds *aws.Credentials) ([]string, error)
	PortsOf   func(ctx context.Context, account, region string, creds *aws.Credentials) (RegionPorts, error)
	Cache     *cache.Cache
	// Refresh is "discovery" (scan everything again), "metrics" or "".
	Refresh string
	Now     func() time.Time
	// Progress and AccountProgress are called one at a time (a mutex), though
	// accounts run at once.
	Progress        func(ProgressEvent)
	AccountProgress func(AccountEvent)
	// Concurrency is the accounts discovered at once (--parallel; 5 when < 1).
	Concurrency int
	// Standalone: the standalone scan too (--standalone on), its part kept in a file of its own
	// (standalone/<account>-<region>.json); off, nothing of it is read or written.
	Standalone bool
}

AllOptions are the inputs of All.

type AutoScalingGroup

type AutoScalingGroup struct {
	AutoScalingGroupName string        `json:"AutoScalingGroupName,omitempty"`
	AutoScalingGroupARN  string        `json:"AutoScalingGroupARN,omitempty"`
	TargetGroupARNs      []string      `json:"TargetGroupARNs,omitempty"`
	Tags                 []Tag         `json:"Tags,omitempty"`
	DesiredCapacity      int           `json:"DesiredCapacity,omitempty"`
	Instances            []ASGInstance `json:"Instances,omitempty"`
}

AutoScalingGroup is the part of a group the scan reads.

type AutoScalingPort

type AutoScalingPort interface {
	DescribeAutoScalingGroups(ctx context.Context, in DescribeAutoScalingGroupsInput) (DescribeAutoScalingGroupsOutput, error)
}

AutoScalingPort is the Auto Scaling API.

type Backend

type Backend struct {
	Kind       string                `json:"kind"`
	ID         string                `json:"id"`
	ARN        string                `json:"arn,omitempty"` // from 2026-10-05 scans
	Kubernetes *kubernetes.Candidate `json:"kubernetes,omitempty"`
}

Backend is the backend behind a target group: an instance, an Auto Scaling group, an ECS service or a Kubernetes owner (Kubernetes then says how).

type CloudWatchPort

type CloudWatchPort interface {
	GetMetricData(ctx context.Context, in GetMetricDataInput) (GetMetricDataOutput, error)
}

CloudWatchPort is the metrics API.

type Condition

type Condition struct {
	Field             string
	Values            []string
	HostHeaderConfig  *ValuesConfig
	PathPatternConfig *ValuesConfig
	Raw               string
}

Condition is a rule's condition. Raw keeps its JSON, as Node's JSON.stringify gives it for a field the scan does not know.

func (Condition) MarshalJSON

func (c Condition) MarshalJSON() ([]byte, error)

MarshalJSON writes the condition as it was read.

func (*Condition) UnmarshalJSON

func (c *Condition) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a condition and keeps its JSON.

type Config

type Config struct {
	Version        int         `json:"version"`
	Mode           string      `json:"mode"`
	Regions        []string    `json:"regions"`
	RefreshHours   int         `json:"refreshHours"`
	GlobalExcludes []Criterion `json:"globalExcludes"`
	Filters        []Filter    `json:"filters"`
}

Config is the discovery configuration the perimeter reads.

type Criterion

type Criterion struct {
	Note          string   `json:"note,omitempty"`
	AccountIDs    []string `json:"accountIds,omitempty"`
	OUIDs         []string `json:"ouIds,omitempty"`
	AccountTags   TagWants `json:"accountTags,omitempty"`
	Regions       []string `json:"regions,omitempty"`
	LoadBalancers []string `json:"loadBalancers,omitempty"`
	Hosts         []string `json:"hosts,omitempty"`
	ResourceTags  TagWants `json:"resourceTags,omitempty"`
	BackendKinds  []string `json:"backendKinds,omitempty"`
	TargetGroups  []string `json:"targetGroups,omitempty"`
	Label         string   `json:"label,omitempty"`
}

Criterion selects accounts, regions and resources; every dimension it sets must match. A nil slice or TagWants is a dimension it does not set.

type Database

type Database struct {
	Kind         string              `json:"kind"` // rds-instance or rds-cluster
	ID           string              `json:"id"`
	Status       string              `json:"status"`
	AllowedFrom  []string            `json:"allowedFrom"`
	Tags         map[string][]string `json:"tags"`
	Stopped      []stopped.Item      `json:"stopped"`
	NotStoppable string              `json:"notStoppable,omitempty"`
}

Database is a companion database candidate of the region.

type Decision

type Decision struct {
	Scope  string `json:"scope"` // in, out or excluded
	Reason string `json:"reason"`
}

Decision is whether a rule is in the perimeter, and why.

func Decide

func Decide(cfg Config, a Account, r ScannedRule, inv OrgInventory) Decision

Decide says whether a rule is in the perimeter: global excludes win, then any filter including it without excluding it.

type DefaultSignal added in v0.16.0

type DefaultSignal struct {
	Signal string       `json:"signal"` // cpu or metric
	Below  float64      `json:"below"`
	Metric SignalMetric `json:"metric"`
}

DefaultSignal is a built-in idle signal of a standalone resource: its metric is idle under Below.

func DefaultSignals added in v0.16.0

func DefaultSignals(backend Backend) []DefaultSignal

DefaultSignals are a candidate's default signals, by its own resource's kind (a candidate lists no companion yet): CPU under 5 % for an instance, a group and an ECS service; a database's connections under 1.

type DescribeAutoScalingGroupsInput

type DescribeAutoScalingGroupsInput struct {
	NextToken             string   `json:"NextToken,omitempty"`
	AutoScalingGroupNames []string `json:"AutoScalingGroupNames,omitempty"`
}

DescribeAutoScalingGroupsInput is a page of Auto Scaling groups.

type DescribeAutoScalingGroupsOutput

type DescribeAutoScalingGroupsOutput struct {
	AutoScalingGroups []AutoScalingGroup `json:"AutoScalingGroups,omitempty"`
	NextToken         string             `json:"NextToken,omitempty"`
}

DescribeAutoScalingGroupsOutput is its answer.

type DescribeInstancesInput

type DescribeInstancesInput struct {
	InstanceIds []string `json:"InstanceIds,omitempty"`
	NextToken   string   `json:"NextToken,omitempty"`
}

DescribeInstancesInput asks instances by id, or, without ids, a page of every instance of the region (the standalone scan).

type DescribeInstancesOutput

type DescribeInstancesOutput struct {
	Reservations []Reservation `json:"Reservations,omitempty"`
	NextToken    string        `json:"NextToken,omitempty"`
}

DescribeInstancesOutput is its answer.

type DescribeListenersInput

type DescribeListenersInput struct {
	LoadBalancerArn string `json:"LoadBalancerArn"`
	Marker          string `json:"Marker,omitempty"`
}

DescribeListenersInput is a page of a load balancer's listeners.

type DescribeListenersOutput

type DescribeListenersOutput struct {
	Listeners  []Listener `json:"Listeners,omitempty"`
	NextMarker string     `json:"NextMarker,omitempty"`
}

DescribeListenersOutput is its answer.

type DescribeLoadBalancersInput

type DescribeLoadBalancersInput struct {
	Marker string `json:"Marker,omitempty"`
}

DescribeLoadBalancersInput is a page of load balancers.

type DescribeLoadBalancersOutput

type DescribeLoadBalancersOutput struct {
	LoadBalancers []LoadBalancer `json:"LoadBalancers,omitempty"`
	NextMarker    string         `json:"NextMarker,omitempty"`
}

DescribeLoadBalancersOutput is its answer.

type DescribeRulesInput

type DescribeRulesInput struct {
	ListenerArn string   `json:"ListenerArn,omitempty"`
	Marker      string   `json:"Marker,omitempty"`
	RuleArns    []string `json:"RuleArns,omitempty"` // rules by ARN (a managed workload's waker)
}

DescribeRulesInput is a page of a listener's rules.

type DescribeRulesOutput

type DescribeRulesOutput struct {
	Rules      []Rule `json:"Rules,omitempty"`
	NextMarker string `json:"NextMarker,omitempty"`
}

DescribeRulesOutput is its answer.

type DescribeSecurityGroupsInput

type DescribeSecurityGroupsInput struct {
	GroupIds []string `json:"GroupIds"`
}

DescribeSecurityGroupsInput asks security groups by id.

type DescribeSecurityGroupsOutput

type DescribeSecurityGroupsOutput struct {
	SecurityGroups []SecurityGroup `json:"SecurityGroups,omitempty"`
}

DescribeSecurityGroupsOutput is its answer.

type DescribeServicesInput

type DescribeServicesInput struct {
	Cluster  string   `json:"cluster"`
	Services []string `json:"services"`
	Include  []string `json:"include,omitempty"`
}

DescribeServicesInput asks up to 10 services of a cluster; Include ["TAGS"] asks their tags too (the standalone scan).

type DescribeServicesOutput

type DescribeServicesOutput struct {
	Services []Service `json:"services,omitempty"`
}

DescribeServicesOutput is its answer.

type DescribeTagsInput

type DescribeTagsInput struct {
	ResourceArns []string `json:"ResourceArns"`
}

DescribeTagsInput asks the tags of up to 20 resources.

type DescribeTagsOutput

type DescribeTagsOutput struct {
	TagDescriptions []TagDescription `json:"TagDescriptions,omitempty"`
}

DescribeTagsOutput is its answer.

type DescribeTargetGroupsInput

type DescribeTargetGroupsInput struct {
	Marker          string   `json:"Marker,omitempty"`
	TargetGroupArns []string `json:"TargetGroupArns,omitempty"`
}

DescribeTargetGroupsInput is a page of target groups.

type DescribeTargetGroupsOutput

type DescribeTargetGroupsOutput struct {
	TargetGroups []TargetGroup `json:"TargetGroups,omitempty"`
	NextMarker   string        `json:"NextMarker,omitempty"`
}

DescribeTargetGroupsOutput is its answer.

type DescribeTargetHealthInput

type DescribeTargetHealthInput struct {
	TargetGroupArn string `json:"TargetGroupArn"`
}

DescribeTargetHealthInput asks a target group's targets.

type DescribeTargetHealthOutput

type DescribeTargetHealthOutput struct {
	TargetHealthDescriptions []TargetHealthDescription `json:"TargetHealthDescriptions,omitempty"`
}

DescribeTargetHealthOutput is its answer.

type Dimension

type Dimension struct {
	Name  string `json:"Name"`
	Value string `json:"Value"`
}

Dimension is a CloudWatch metric dimension.

type EC2Port

type EC2Port interface {
	DescribeInstances(ctx context.Context, in DescribeInstancesInput) (DescribeInstancesOutput, error)
}

EC2Port is read where the region has EKS clusters (their nodes), and by the standalone scan (every instance).

type ECSPort

type ECSPort interface {
	ListClusters(ctx context.Context, in ListClustersInput) (ListClustersOutput, error)
	ListServices(ctx context.Context, in ListServicesInput) (ListServicesOutput, error)
	DescribeServices(ctx context.Context, in DescribeServicesInput) (DescribeServicesOutput, error)
}

ECSPort is the ECS API.

type ELBv2Port

ELBv2Port is the load balancers API.

type FailedRead added in v0.16.0

type FailedRead struct {
	IDs   []string `json:"ids"`
	Error string   `json:"error"`
}

FailedRead is a batch of candidates CloudWatch failed for, with the error as one line ("<name>: <message>").

type Filter

type Filter struct {
	Name    string      `json:"name"`
	Include []Criterion `json:"include"`
	Exclude []Criterion `json:"exclude"`
}

Filter includes what any of its includes match, minus its own excludes.

type ForwardConfig

type ForwardConfig struct {
	TargetGroups []ForwardTarget `json:"TargetGroups,omitempty"`
}

ForwardConfig is a forward action's target groups (nil: the action's own).

type ForwardTarget

type ForwardTarget struct {
	TargetGroupArn string `json:"TargetGroupArn,omitempty"`
	Weight         *int   `json:"Weight,omitempty"`
}

ForwardTarget is a target group of a forward action, with its weight (absent: 1).

type GetMetricDataInput

type GetMetricDataInput struct {
	StartTime         time.Time
	EndTime           time.Time
	MetricDataQueries []MetricDataQuery
	ScanBy            string
	NextToken         string
}

GetMetricDataInput is a GetMetricData call. Its times are written as Node's toISOString does (2026-10-12T08:00:00.000Z). ScanBy "TimestampAscending": the oldest values first (the standalone idle share's).

func (GetMetricDataInput) MarshalJSON

func (in GetMetricDataInput) MarshalJSON() ([]byte, error)

MarshalJSON writes the input with its times as ISO strings.

type GetMetricDataOutput

type GetMetricDataOutput struct {
	MetricDataResults []MetricDataResult `json:"MetricDataResults,omitempty"`
	NextToken         string             `json:"NextToken,omitempty"`
}

GetMetricDataOutput is its answer.

type IdleShares added in v0.16.0

type IdleShares struct {
	Shares map[string]*int `json:"shares"`
	Failed []FailedRead    `json:"failed"`
}

IdleShares are the candidates read, by id, with their idle hours of the week (nil: no point at all), and the batches CloudWatch failed for.

func StandaloneIdle added in v0.16.0

func StandaloneIdle(ctx context.Context, cw CloudWatchPort, candidates []StandaloneRule, now time.Time) IdleShares

StandaloneIdle reads the idle share of the candidates over the week before now: one GetMetricData call (and its pages) a batch of at most 500 queries, a candidate's signals in one batch.

type IneligibleRule

type IneligibleRule struct {
	LoadBalancer string   `json:"loadBalancer"`
	TargetGroup  *string  `json:"targetGroup"`
	Hosts        []string `json:"hosts"`
	Reason       string   `json:"reason"`
}

IneligibleRule is a rule that is not a workload, and why.

type Instance

type Instance struct {
	InstanceID        string         `json:"InstanceId,omitempty"`
	State             *InstanceState `json:"State,omitempty"`
	RootDeviceType    string         `json:"RootDeviceType,omitempty"`
	InstanceLifecycle string         `json:"InstanceLifecycle,omitempty"`
	Tags              []Tag          `json:"Tags,omitempty"`
}

Instance is an instance with its tags, and what the standalone scan reads of it.

type InstanceState added in v0.16.0

type InstanceState struct {
	Name string `json:"Name,omitempty"`
}

InstanceState is an instance's state.

type InventoryProgress added in v0.2.0

type InventoryProgress struct {
	Read, Found, Accounts int
}

InventoryProgress is the inventory's walk so far: the organizational units read (their accounts and children listed), of those found (the root included), and the active accounts found.

type IpPermission

type IpPermission struct {
	UserIdGroupPairs []UserIdGroupPair `json:"UserIdGroupPairs,omitempty"`
}

IpPermission is an ingress rule.

type ListAccountsForParentInput

type ListAccountsForParentInput struct {
	ParentID  string `json:"ParentId"`
	NextToken string `json:"NextToken,omitempty"`
}

ListAccountsForParentInput is a page of a parent's accounts.

type ListAccountsForParentOutput

type ListAccountsForParentOutput struct {
	Accounts  []OrgAccount `json:"Accounts,omitempty"`
	NextToken string       `json:"NextToken,omitempty"`
}

ListAccountsForParentOutput is its answer.

type ListClustersInput

type ListClustersInput struct {
	NextToken string `json:"nextToken,omitempty"`
}

ListClustersInput is a page of ECS clusters.

type ListClustersOutput

type ListClustersOutput struct {
	ClusterArns []string `json:"clusterArns,omitempty"`
	NextToken   string   `json:"nextToken,omitempty"`
}

ListClustersOutput is its answer.

type ListOrganizationalUnitsForParentInput

type ListOrganizationalUnitsForParentInput struct {
	ParentID  string `json:"ParentId"`
	NextToken string `json:"NextToken,omitempty"`
}

ListOrganizationalUnitsForParentInput is a page of a parent's OUs.

type ListOrganizationalUnitsForParentOutput

type ListOrganizationalUnitsForParentOutput struct {
	OrganizationalUnits []OrganizationalUnit `json:"OrganizationalUnits,omitempty"`
	NextToken           string               `json:"NextToken,omitempty"`
}

ListOrganizationalUnitsForParentOutput is its answer.

type ListRootsInput

type ListRootsInput struct {
	NextToken string `json:"NextToken,omitempty"`
}

ListRootsInput is a page of the organization's roots.

type ListRootsOutput

type ListRootsOutput struct {
	Roots     []Root `json:"Roots,omitempty"`
	NextToken string `json:"NextToken,omitempty"`
}

ListRootsOutput is its answer.

type ListServicesInput

type ListServicesInput struct {
	Cluster   string `json:"cluster"`
	NextToken string `json:"nextToken,omitempty"`
}

ListServicesInput is a page of a cluster's services.

type ListServicesOutput

type ListServicesOutput struct {
	ServiceArns []string `json:"serviceArns,omitempty"`
	NextToken   string   `json:"nextToken,omitempty"`
}

ListServicesOutput is its answer.

type ListTagsForResourceInput

type ListTagsForResourceInput struct {
	ResourceID string `json:"ResourceId"`
	NextToken  string `json:"NextToken,omitempty"`
}

ListTagsForResourceInput is a page of an account's tags.

type ListTagsForResourceOutput

type ListTagsForResourceOutput struct {
	Tags      []Tag  `json:"Tags,omitempty"`
	NextToken string `json:"NextToken,omitempty"`
}

ListTagsForResourceOutput is its answer.

type Listener

type Listener struct {
	ListenerArn string `json:"ListenerArn,omitempty"`
	Port        int    `json:"Port,omitempty"`
	Protocol    string `json:"Protocol,omitempty"`
}

Listener is an ELBv2 listener.

type LoadBalancer

type LoadBalancer struct {
	LoadBalancerArn  string `json:"LoadBalancerArn,omitempty"`
	LoadBalancerName string `json:"LoadBalancerName,omitempty"`
	Type             string `json:"Type,omitempty"`
}

LoadBalancer is the part of an ELBv2 load balancer the scan reads.

type Metric

type Metric struct {
	Namespace  string      `json:"Namespace"`
	MetricName string      `json:"MetricName"`
	Dimensions []Dimension `json:"Dimensions"`
}

Metric names a CloudWatch metric.

type MetricDataQuery

type MetricDataQuery struct {
	ID         string     `json:"Id"`
	ReturnData bool       `json:"ReturnData"`
	MetricStat MetricStat `json:"MetricStat"`
}

MetricDataQuery is one query of GetMetricData.

type MetricDataResult

type MetricDataResult struct {
	ID         string          `json:"Id,omitempty"`
	Timestamps []time.Time     `json:"Timestamps,omitempty"`
	Values     []float64       `json:"Values,omitempty"`
	StatusCode string          `json:"StatusCode,omitempty"`
	Messages   []MetricMessage `json:"Messages,omitempty"`
}

MetricDataResult is the values of one query, with their timestamps side by side, and its status (a result CloudWatch could not read has no values).

type MetricMessage added in v0.16.0

type MetricMessage struct {
	Code  string `json:"Code,omitempty"`
	Value string `json:"Value,omitempty"`
}

MetricMessage is a message of a result (why CloudWatch could not read a metric).

type MetricStat

type MetricStat struct {
	Metric Metric `json:"Metric"`
	Period int    `json:"Period"`
	Stat   string `json:"Stat"`
}

MetricStat is a metric with its period and statistic.

type OU

type OU struct {
	Name   string  `json:"name"`
	Parent *string `json:"parent"`
}

OU is an organizational unit (the root included, with a nil parent).

type OrgAccount

type OrgAccount struct {
	ID     string `json:"Id,omitempty"`
	Name   string `json:"Name,omitempty"`
	State  string `json:"State,omitempty"`
	Status string `json:"Status,omitempty"`
}

OrgAccount is an account of the organization; State replaces the deprecated Status.

type OrgInventory

type OrgInventory struct {
	Accounts []Account     `json:"accounts"`
	OUs      map[string]OU `json:"ous"`
}

OrgInventory is the organization's accounts and OU tree.

func LoadInventory

func LoadInventory(ctx context.Context, org OrganizationsPort, tags bool) (OrgInventory, error)

LoadInventory reads the organization's OU tree and its active accounts, each with its OU path from the root; with tags, their tags too.

func LoadInventoryProgress added in v0.2.0

func LoadInventoryProgress(ctx context.Context, org OrganizationsPort, tags bool, progress func(InventoryProgress)) (OrgInventory, error)

LoadInventoryProgress is LoadInventory saying how far it is after each organizational unit (progress nil: silent).

type OrganizationalUnit

type OrganizationalUnit struct {
	ID   string `json:"Id,omitempty"`
	Name string `json:"Name,omitempty"`
}

OrganizationalUnit is an OU.

type OrganizationsPort

type OrganizationsPort interface {
	ListRoots(ctx context.Context, in ListRootsInput) (ListRootsOutput, error)
	ListOrganizationalUnitsForParent(ctx context.Context, in ListOrganizationalUnitsForParentInput) (ListOrganizationalUnitsForParentOutput, error)
	ListAccountsForParent(ctx context.Context, in ListAccountsForParentInput) (ListAccountsForParentOutput, error)
	ListTagsForResource(ctx context.Context, in ListTagsForResourceInput) (ListTagsForResourceOutput, error)
}

OrganizationsPort is the read-only Organizations delegation.

type PairPlan

type PairPlan struct {
	Account string `json:"account"`
	Region  string `json:"region"`
	Scan    bool   `json:"scan"`
	Reason  string `json:"reason"`
}

PairPlan says whether an account and region are scanned.

func TargetPairs

func TargetPairs(cfg Config, inv OrgInventory, enabled map[string][]string) []PairPlan

TargetPairs says, for each account and region, whether it is scanned; enabled gives each account's enabled regions, for the regions ["*"].

type ProgressEvent

type ProgressEvent struct {
	Phase     string `json:"phase"` // discovery, requests or uptime
	Account   string `json:"account"`
	Region    string `json:"region"`
	From      string `json:"from"` // cache or aws
	Workloads int    `json:"workloads"`
	Error     string `json:"error,omitempty"`
}

ProgressEvent says a region is done: where it came from (the cache or AWS), how many workloads it holds and why it failed, if it did. JSON names as Node's.

type RegionDiscovery

type RegionDiscovery struct {
	Account        string
	Region         string
	Workloads      []Workload
	Ineligible     []IneligibleRule
	Clusters       []UnreadableCluster
	Error          string
	Databases      []Database
	DatabasesError string
}

RegionDiscovery is what discovery kept of an account and region (the cache's value). Databases nil: not read (a file kept before the databases existed).

func All

All discovers every account's regions, the accounts at most Concurrency at a time, each account's regions one after the other. The regions come back in the organization's order, whatever finished first. A region that fails is a RegionDiscovery with its Error; an account that fails (not a refused role, already listed apart) is one with region "*". The error is the context's.

func Region

func Region(ctx context.Context, ports RegionPorts, where Where) (RegionDiscovery, error)

Region discovers one account and region: the scan, the workloads described eight at a time in the scan's order, the clusters unreadable and the companion databases. A scan that fails (or a rule whose waker cannot be read) fails the region.

func (RegionDiscovery) MarshalJSON

func (r RegionDiscovery) MarshalJSON() ([]byte, error)

MarshalJSON writes Node's shape: workloads and ineligible always arrays, clusters, error and databasesError only when there are some, databases when they were read (an empty array included).

func (*RegionDiscovery) UnmarshalJSON

func (r *RegionDiscovery) UnmarshalJSON(b []byte) error

UnmarshalJSON reads the shape MarshalJSON writes (and the Node estimate's files).

type RegionEC2Port

type RegionEC2Port interface {
	stopped.EC2Port
	DescribeSecurityGroups(ctx context.Context, in DescribeSecurityGroupsInput) (DescribeSecurityGroupsOutput, error)
}

RegionEC2Port is what a region's discovery reads of EC2: instances (with their state and security groups) and security groups.

type RegionPorts

type RegionPorts struct {
	// Scan is discovery's scan of the region (ScanRegion with the region's
	// ports); its clusters the profile could not read are listed by Region.
	Scan func(ctx context.Context) (ScanResult, error)
	// Standalone is the same scan with the standalone one (ScanRegionWith, Standalone on); nil: none.
	Standalone  func(ctx context.Context) (ScanResult, error)
	AutoScaling AutoScalingPort
	ELBv2       RulesPort
	EC2         RegionEC2Port
	Stopped     stopped.Ports
}

RegionPorts are what one region's discovery reads (Node's RegionPorts, which extends StoppedPorts): the scan, the Auto Scaling groups, a rule by ARN, EC2 (instances, security groups) and what a nap stops (ECS services, RDS instances and clusters, the clusters' clients). Stopped.RDS nil: the databases are not read. Stopped.EC2 and EC2 are the same client.

type Reservation

type Reservation struct {
	Instances []Instance `json:"Instances,omitempty"`
}

Reservation groups instances.

type Root

type Root struct {
	ID   string `json:"Id,omitempty"`
	Name string `json:"Name,omitempty"`
}

Root is an organization root.

type Rule

type Rule struct {
	RuleArn    string      `json:"RuleArn,omitempty"`
	Priority   string      `json:"Priority,omitempty"`
	IsDefault  bool        `json:"IsDefault,omitempty"`
	Conditions []Condition `json:"Conditions,omitempty"`
	Actions    []Action    `json:"Actions,omitempty"`
}

Rule is an ELBv2 listener rule.

type RuleRef

type RuleRef struct {
	ID         string   `json:"id"` // rule ARN
	Listener   string   `json:"listener"`
	Priority   string   `json:"priority"`
	Conditions string   `json:"conditions"`
	Hosts      []string `json:"hosts"`
	Managed    bool     `json:"managed"` // tagged dormeto:workload
}

RuleRef is a listener rule of a candidate.

type RulesPort

type RulesPort interface {
	DescribeRules(ctx context.Context, in DescribeRulesInput) (DescribeRulesOutput, error)
}

RulesPort is the ELBv2 call discovery makes beyond the scan: rules by ARN.

type ScanOptions added in v0.16.0

type ScanOptions struct {
	Standalone bool
	// WithoutStandaloneIdle leaves the standalone candidates' idle share unread (their idleHours7d null): the estimate
	// reads their signals over its own days (Go only; the manager's scan always reads it).
	WithoutStandaloneIdle bool
}

ScanOptions are a scan's options. Standalone (the perimeter's standalone scan on): the standalone candidates too; off, not one call more.

type ScanPorts

type ScanPorts struct {
	ELBv2       ELBv2Port
	AutoScaling AutoScalingPort
	EC2         EC2Port
	ECS         ECSPort
	CloudWatch  CloudWatchPort
	RDS         stopped.RDSPort
	Kubernetes  *kubernetes.Ports
}

ScanPorts are the read-only calls of a scan. ELBv2 is required; a port left nil is one the scan does not read (no Auto Scaling groups, ECS services, idle hours, nodes or clusters; for the standalone scan, no instances or databases). Kubernetes is the region's EKS clusters and their API. RDS is read by the standalone scan only.

type ScanResult

type ScanResult struct {
	Rules      []ScannedRule        `json:"rules"`
	Clusters   []kubernetes.Cluster `json:"clusters"`
	Standalone *StandaloneScan      `json:"standalone,omitempty"`
}

ScanResult is a region's scan: its candidates in the scan's order and the region's clusters as read (the estimate lists those it cannot read), and, with the standalone scan, its standalone candidates and what it could not read (nil without it).

func ScanRegion

func ScanRegion(ctx context.Context, ports ScanPorts, where Where, now time.Time) (ScanResult, error)

ScanRegion scans an account and region. now gives the end of the idle window (the hour before it). A call that fails fails the scan, except the clusters' listing when the role lacks EKS rights (the region is scanned as before).

func ScanRegionWith added in v0.16.0

func ScanRegionWith(ctx context.Context, ports ScanPorts, where Where, now time.Time, options ScanOptions) (ScanResult, error)

ScanRegionWith is ScanRegion with its options. With the standalone scan, a list the discovery role may not read, the services' tags refused and the standalone idle share CloudWatch fails for are said in the result's report, not failures.

type ScannedRule

type ScannedRule struct {
	ID              string              `json:"id"`
	Account         string              `json:"account"`
	Region          string              `json:"region"`
	LoadBalancer    string              `json:"loadBalancer"`
	LoadBalancerArn string              `json:"loadBalancerArn"`
	Listener        string              `json:"listener"`
	Priority        string              `json:"priority"`
	Conditions      string              `json:"conditions"`
	Hosts           []string            `json:"hosts"`
	TargetGroup     *string             `json:"targetGroup"`
	TargetGroupArn  *string             `json:"targetGroupArn"`
	Backend         *Backend            `json:"backend"`
	Tags            map[string][]string `json:"tags"` // every value of each tag on the load balancer, the target group or the rule
	Rules           []RuleRef           `json:"rules"`
	Eligibility     string              `json:"eligibility"`
	Reason          string              `json:"reason,omitempty"`
	WorkloadID      string              `json:"workloadId,omitempty"`
	IdleHours7d     *int                `json:"idleHours7d"`
	Requests7d      *int                `json:"requests7d"`
}

ScannedRule is a candidate: an application target group with every rule forwarding to it (ID the target group ARN), or a rule that forwards to no single application target group (ID the rule ARN).

type SecurityGroup

type SecurityGroup struct {
	GroupId       string         `json:"GroupId,omitempty"`
	IpPermissions []IpPermission `json:"IpPermissions,omitempty"`
}

SecurityGroup is a security group and its ingress rules.

type Service

type Service struct {
	ServiceArn         string                `json:"serviceArn,omitempty"`
	Status             string                `json:"status,omitempty"`
	SchedulingStrategy string                `json:"schedulingStrategy,omitempty"`
	LoadBalancers      []ServiceLoadBalancer `json:"loadBalancers,omitempty"`
	Tags               []ServiceTag          `json:"tags,omitempty"`
}

Service is the part of an ECS service the scan reads.

type ServiceLoadBalancer

type ServiceLoadBalancer struct {
	TargetGroupArn string `json:"targetGroupArn,omitempty"`
}

ServiceLoadBalancer is a service's load balancer attachment.

type ServiceTag added in v0.16.0

type ServiceTag struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

ServiceTag is an ECS tag (camelCase, as ECS answers).

type SignalMetric added in v0.16.0

type SignalMetric struct {
	Namespace  string      `json:"namespace"`
	Name       string      `json:"name"`
	Dimensions []Dimension `json:"dimensions"`
	Stat       string      `json:"stat"`
}

SignalMetric is the CloudWatch metric of a signal.

type StandaloneIneligible added in v0.16.0

type StandaloneIneligible struct {
	Kind   string `json:"kind"`
	ID     string `json:"id"`
	ARN    string `json:"arn"`
	Name   string `json:"name"`
	Reason string `json:"reason"`
}

StandaloneIneligible is a standalone candidate the router would refuse, with the scan's reason.

type StandaloneRegion added in v0.16.0

type StandaloneRegion struct {
	Account    string                 `json:"account"`
	Region     string                 `json:"region"`
	Resources  []StandaloneResource   `json:"resources"`
	Ineligible []StandaloneIneligible `json:"ineligible"`
	Problems   []string               `json:"problems"`
	Unread     []string               `json:"unread"`
	// Failed: the standalone part's scan failed (its error in Problems): never kept, scanned again next time.
	Failed bool `json:"-"`
}

StandaloneRegion is what the standalone scan kept of an account and region (the cache's value): its resources, its ineligible candidates, and what it could not read (the scan's report).

type StandaloneReport added in v0.16.0

type StandaloneReport struct {
	Problems []string `json:"problems"`
	Unread   []string `json:"unread"`
}

StandaloneReport is what the standalone scan could not read: a sentence each for the run's problems, and the kinds whose stored candidates stay as they were (a kind without its port is unread without a problem).

type StandaloneResource added in v0.16.0

type StandaloneResource struct {
	Account    string              `json:"account"`
	Region     string              `json:"region"`
	Kind       string              `json:"kind"`
	ID         string              `json:"id"`
	ARN        string              `json:"arn"`
	Name       string              `json:"name"`
	Tags       map[string][]string `json:"tags"`
	Managed    bool                `json:"managed,omitempty"`
	WorkloadID string              `json:"workloadId,omitempty"`
	Stopped    []stopped.Item      `json:"stopped"`
	// An instance's state when discovered (not one Dormeto manages).
	InstanceState string `json:"instanceState,omitempty"`
	// An ECS service's desired count when discovered (not one Dormeto manages): it is priced at it, at least one task.
	EcsDesired *int `json:"ecsDesired,omitempty"`
}

StandaloneResource is an eligible (or managed) standalone candidate of a region, described: its resource (Kind one of the resource kinds, ID its backend id: an instance id, a group's name, a service's ARN, a database's identifier), what a nap stops, its tags.

type StandaloneRule added in v0.16.0

type StandaloneRule struct {
	Kind        string              `json:"kind"` // KindStandalone
	ID          string              `json:"id"`
	Account     string              `json:"account"`
	Region      string              `json:"region"`
	ResourceArn string              `json:"resourceArn"`
	Name        string              `json:"name"`
	Backend     Backend             `json:"backend"`
	Tags        map[string][]string `json:"tags"`
	Eligibility string              `json:"eligibility"`
	Reason      string              `json:"reason,omitempty"`
	WorkloadID  string              `json:"workloadId,omitempty"`
	IdleHours7d *int                `json:"idleHours7d"`
}

StandaloneRule is a standalone candidate: a resource no route uses (ID and ResourceArn its ARN), its backend the resource itself.

type StandaloneScan added in v0.16.0

type StandaloneScan struct {
	Rules  []StandaloneRule `json:"rules"`
	Report StandaloneReport `json:"report"`
}

StandaloneScan is the standalone part of a region's scan: its candidates (instances, then groups, services, RDS instances, RDS clusters, each in the order AWS listed them) and what it could not read.

type Tag

type Tag struct {
	Key   string `json:"Key,omitempty"`
	Value string `json:"Value,omitempty"`
}

Tag is an AWS tag.

type TagDescription

type TagDescription struct {
	ResourceArn string `json:"ResourceArn,omitempty"`
	Tags        []Tag  `json:"Tags,omitempty"`
}

TagDescription is the tags of a resource.

type TagWant

type TagWant struct {
	Key    string
	Values []string
}

TagWant is a tag a criterion asks for, with the values it accepts (none: any value).

type TagWants

type TagWants []TagWant

TagWants are the tags of a criterion, in the order the configuration lists them (the order of their description). It reads and writes a JSON object {"key": ["value", ...]}. A nil TagWants is a dimension the criterion does not set; an empty one is set, and asks for nothing.

func (TagWants) Map

func (w TagWants) Map() map[string][]string

Map is the wanted tags by key.

func (TagWants) MarshalJSON

func (w TagWants) MarshalJSON() ([]byte, error)

MarshalJSON writes the object in order.

func (*TagWants) UnmarshalJSON

func (w *TagWants) UnmarshalJSON(b []byte) error

UnmarshalJSON reads an object, keeping its key order.

type Target

type Target struct {
	Account     string
	Credentials func(ctx context.Context) (*aws.Credentials, error)
}

Target is a reached account and how to get its credentials (nil credentials: the profile's own).

type TargetDescription

type TargetDescription struct {
	ID string `json:"Id,omitempty"`
}

TargetDescription is a registered target.

type TargetGroup

type TargetGroup struct {
	TargetGroupArn   string   `json:"TargetGroupArn,omitempty"`
	TargetGroupName  string   `json:"TargetGroupName,omitempty"`
	TargetType       string   `json:"TargetType,omitempty"`
	LoadBalancerArns []string `json:"LoadBalancerArns,omitempty"`
	VpcId            string   `json:"VpcId,omitempty"`
}

TargetGroup is an ELBv2 target group.

type TargetHealthDescription

type TargetHealthDescription struct {
	Target TargetDescription `json:"Target"`
}

TargetHealthDescription is a target and its health.

type UnreadableCluster

type UnreadableCluster struct {
	Name   string `json:"name"`
	Reason string `json:"reason"`
}

UnreadableCluster is an EKS cluster the profile cannot read, and why.

type UserIdGroupPair

type UserIdGroupPair struct {
	GroupId string `json:"GroupId,omitempty"`
}

UserIdGroupPair is a security group a rule names.

type ValuesConfig

type ValuesConfig struct {
	Values []string `json:"Values,omitempty"`
}

ValuesConfig holds the values of a host or path condition.

type Where

type Where struct{ Account, Region string }

Where is an account and region.

type Workload

type Workload struct {
	Account         string          `json:"account"`
	Region          string          `json:"region"`
	LoadBalancer    string          `json:"loadBalancer"`
	LoadBalancerArn string          `json:"loadBalancerArn"`
	TargetGroup     string          `json:"targetGroup"`
	TargetGroupArn  string          `json:"targetGroupArn"`
	Hosts           []string        `json:"hosts"`
	Backend         WorkloadBackend `json:"backend"`
	Stopped         []stopped.Item  `json:"stopped"`
	// Every value of each tag on its load balancer, target group or rule.
	Tags map[string][]string `json:"tags"`
	// An instance's state when discovered (not one Dormeto manages).
	InstanceState string `json:"instanceState,omitempty"`
	// An ECS service's desired count when discovered (not one Dormeto manages).
	EcsDesired *int `json:"ecsDesired,omitempty"`
	// Already managed by Dormeto, with its waker target group when found.
	Managed             bool   `json:"managed,omitempty"`
	WakerTargetGroupArn string `json:"wakerTargetGroupArn,omitempty"`
	// Its backend's security groups: a database letting one in is its companion.
	SecurityGroups []string `json:"securityGroups"`
}

Workload is an eligible (or managed) workload of a region, described as the router would: what a nap stops, its tags and its security groups.

type WorkloadBackend

type WorkloadBackend struct {
	Kind string `json:"kind"`
	ID   string `json:"id"`
}

WorkloadBackend is a workload's backend as kept: its kind and id.

Jump to

Keyboard shortcuts

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