scan

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func API

func API(service string) map[string][]string

API returns a map of all supported APIs and their dependencies for the specified service.

func NewTFState

func NewTFState(maps []*Map) (*tf.State, error)

NewTFState combines resources from all maps into a single Terraform state.

func Register

func Register(id string, newFunc interface{}, iface svcIface, roots ...interface{}) struct{}

Register adds a new scannable service to the registry.

func ServiceNames

func ServiceNames() []string

ServiceNames returns the names of all scannable services.

func Walk

func Walk(maps []*Map, fn WalkFunc) error

Walk calls fn for each map, API name, and call instance in maps. It returns the first non-nil error from fn.

Types

type Call

type Call struct {
	ID    string         `json:"-"`                // Unique call ID
	Stats *Stats         `json:"#stats,omitempty"` // Call statistics
	Src   map[string]int `json:"src,omitempty"`    // Source call IDs
	In    interface{}    `json:"in,omitempty"`     // API *Input struct
	Out   []interface{}  `json:"out,omitempty"`    // API *Output struct
	Err   *Err           `json:"err,omitempty"`    // Decoded error
	// contains filtered or unexported fields
}

Call is one specific instance of an API call.

type Ctx

type Ctx struct {
	Map // Scan results
	// contains filtered or unexported fields
}

Ctx contains the scan state for one service/region combination.

func TestCtx

func TestCtx(iface interface{}) *Ctx

TestCtx returns a context for unit testing a scanner implementation.

func (*Ctx) ARN

func (ctx *Ctx) ARN(resource ...string) *string

ARN constructs a service-specific ARN for the specified resource.

func (*Ctx) CopyInput

func (*Ctx) CopyInput(dst interface{}, field string, out output)

CopyInput copies the value of an Input struct field that generated out into a new Input slice. It is equivalent to:

v := ctx.Input(out).(*T).Field
for i := range dst {
	dst[i].Field = v
}

func (*Ctx) Group

func (*Ctx) Group(dst interface{}, dstField string, src interface{}, srcField string, max int)

Group populates one slice Input struct field in *dst using up to max src slice values. If max is <= 0, then all src values are added to one Input struct. If srcField is specified, src must be a slice of structs or struct pointers containing the named field.

func (*Ctx) HandleError

func (*Ctx) HandleError(*aws.Request, *Err)

HandleError can be overridden by service scanners to set err.Ignore flag if the error is part of normal service behavior and is safe to ignore.

func (*Ctx) ImportResources

func (ctx *Ctx) ImportResources(typ string, attrs tfx.AttrGen) error

ImportResources adds new resources to ctx.Resources. See ImportResources method of tfx.ProviderMap for more info.

func (*Ctx) Input

func (*Ctx) Input(out output) interface{}

Input returns the Input struct that generated the given Output struct.

func (*Ctx) MakeResources

func (ctx *Ctx) MakeResources(typ string, attrs tfx.AttrGen) error

MakeResources adds new resources to ctx.Resources. See MakeResources method of tfx.ProviderMap for more info.

func (*Ctx) Mode

func (ctx *Ctx) Mode(test Mode) bool

Mode returns true if all mode bits in test are enabled.

func (*Ctx) SetMode

func (ctx *Ctx) SetMode(m Mode)

SetMode sets scan mode. This should only be used for testing.

func (*Ctx) Split

func (*Ctx) Split(dst interface{}, dstField string, src interface{}, srcField string)

Split populates one non-slice Input struct field in *dst for each src slice value. If srcField is specified, src must be a slice of structs or struct pointers containing the named field.

func (*Ctx) Strings

func (ctx *Ctx) Strings(src interface{}, srcField string) []string

Strings extracts string values from a slice of structs or struct pointers containing the named field.

func (*Ctx) UpdateRequest

func (*Ctx) UpdateRequest(*aws.Request)

UpdateRequest can be overridden by service scanners to modify each request before it is sent to fix broken SDK models.

type Err

type Err struct {
	Status    int    // HTTP status code
	Code      string // AWS error code
	Message   string // Error message
	RequestID string // AWS request ID
	Ignore    bool   // Error was expected, safe to ignore

	Cause *Err `json:",omitempty"` // Original cause
	// contains filtered or unexported fields
}

Err contains information about an API call error.

func (*Err) String

func (e *Err) String() string

String implements fmt.Stringer interface.

type IO

type IO map[string]interface{}

IO replaces SDK Input/Output struct types in Calls when a Map is compacted.

type Map

type Map struct {
	arn.Ctx
	Service   string
	Calls     map[string][]*Call
	Resources map[string]*tf.ResourceState
}

Map contains all calls for one account/region/service, indexed by API name. Resources are indexed by Terraform state keys.

func Account

func Account(cfg *aws.Config, op Opts) ([]*Map, error)

Account creates a map of each service in each region using worker goroutines. If regions is empty, all regions within the current partition are scanned. If services is empty, all supported services are scanned.

func Compact

func Compact(maps []*Map) []*Map

Compact replaces all Input/Output structs in m with IO maps containing only non-zero values.

type Mode

type Mode uint32

Mode is a bitset that determines service scanning behavior. Scanners may issue different API calls in different modes.

const (
	RootsOnly   Mode = 1 << iota // Make only root API calls
	KeepStats                    // Maintain call statistics
	CloudAssert                  // Limit calls to those used by cloudassert
	TFState                      // Generate skeleton Terraform state
)

type Opts

type Opts struct {
	Mode     Mode     // Scan mode
	Regions  []string // AWS regions
	Services []string // Service names
	Workers  int      // Maximum number of concurrent API calls
}

Opts specifies optional scan parameters.

type Service

type Service struct {
	ID      string        // Endpoint ID
	NewFunc interface{}   // SDK client constructor
	Iface   interface{}   // Scanner implementation
	Roots   []interface{} // Root inputs
}

Service contains information about one registered service.

func ServiceInfo

func ServiceInfo(name string) Service

ServiceInfo returns information about one registered service.

type Stats

type Stats struct {
	Order    int // Call issue order (-1 for combined stats)
	Requests int // Total number of requests
	Retries  int // Number of retried requests
	Errors   int // Number of terminal, non-ignored errors

	QueueTime    float64 // Time spent waiting for a worker
	ExecTime     float64 // Execution time (to worker and back)
	MinRoundTrip float64 // Fastest response time
	MaxRoundTrip float64 // Slowest response time
	// contains filtered or unexported fields
}

Stats contains performance information for one or more calls. All times are in seconds.

func (*Stats) Combine

func (s *Stats) Combine(t *Stats)

Combine updates s with stats from t.

func (*Stats) RoundTimes

func (s *Stats) RoundTimes()

RoundTimes rounds all times to the nearest millisecond.

type WalkFunc

type WalkFunc func(m *Map, api string, c *Call) error

WalkFunc is a function type called by Map.Walk().

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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