commons

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 20 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddChecks added in v1.5.1

func AddChecks(checkConfig *CheckConfig, resources ...[]CheckDefinition)

func CheckMacroTest

func CheckMacroTest[A, B, C, D any](wg *sync.WaitGroup, config *Config, test func(A, B, C, D)) func(A, B, C, D)

Check Macro test is a wrapper around a category that runs all the checks in the category. It allows for a simpler integration of new categories without bloating the code.

func CheckResources added in v1.5.0

func CheckResources(checkConfig CheckConfig, resources []Resource, checkDefinitions []CheckDefinition)

func CheckTest

func CheckTest[A, B, C any](wg *sync.WaitGroup, config *Config, id string, test func(A, B, C)) func(A, B, C)

Check test if a wrapper around a check that allows to verify if the check is included or excluded and add some custom logic. It allows for a simpler integration of new tests without bloating the code.

func GetLatestReleaseTag

func GetLatestReleaseTag(plugin Plugin) (string, error)

func GetRelease

func GetRelease(ctx context.Context, client *github.Client, owner, repo, tag string) (*github.RepositoryRelease, *github.Response, error)

Types

type Check

type Check struct {
	Name        string        `yaml:"name"`        // Name of the check
	Description string        `yaml:"description"` // Description of the check
	Status      string        `yaml:"status"`      // Status of the check - OK, FAIL
	Id          string        `yaml:"id"`          // ID of the check - unique identifier for the check - AWS_IAM_001
	Categories  []string      `yaml:"categories"`  // Category of the check - Security, Cost, Performance, Fault Tolerance, Operational Excellence, etc ...
	Results     []Result      `yaml:"results"`     // Results of the check
	Duration    time.Duration `yaml:"duration"`    // Duration of the check
	StartTime   time.Time
	EndTime     time.Time
}

A check is a test that is run on a resource

func (*Check) AddResult

func (c *Check) AddResult(result Result)

Add Result to a check with some logic to update the status of the check

func (*Check) EndCheck

func (c *Check) EndCheck()

End a check by updating the duration and end time

func (*Check) InitCheck

func (c *Check) InitCheck(name, description, id string, categories []string)

Initialise a check

type CheckConfig

type CheckConfig struct {
	Wg          *sync.WaitGroup // Wait group to wait for all the checks to be done
	Queue       chan Check      // Queue to add the results to
	ConfigYatas *Config         // Yatas config
}

CheckConfig is a struct that contains all the information needed to run a check.

func (*CheckConfig) Init

func (c *CheckConfig) Init(config *Config)

Init the check config struct. Particularly useful in the categories. It allows to pass the config to the checks and allows them to be run in parallel by adding the results to the queue.

type CheckDefinition added in v1.5.0

type CheckDefinition struct {
	Title          string
	Description    string
	Categories     []string
	ConditionFn    func(Resource) bool
	SuccessMessage string
	FailureMessage string
}

type CheckFunc added in v1.5.0

type CheckFunc func(interface{}) Result

type Config

type Config struct {
	Plugins      []Plugin                 `yaml:"plugins"`
	Ignore       []Ignore                 `yaml:"ignore"`
	PluginConfig []map[string]interface{} `yaml:"pluginsConfiguration"`
	Tests        []Tests                  `yaml:"tests"`
}

func ParseConfig

func ParseConfig(configFile string) (*Config, error)

ParseConfig reads the specified configuration file, parses its content, and returns a Config object. It returns an error if the file cannot be read, the content is not valid YAML, or the configuration is not valid.

func (*Config) CheckExclude

func (c *Config) CheckExclude(id string) bool

func (*Config) CheckInclude

func (c *Config) CheckInclude(id string) bool

func (*Config) FindPluginWithName

func (c *Config) FindPluginWithName(name string) *Plugin

type Ignore

type Ignore struct {
	ID     string   `yaml:"id"`
	Regex  bool     `yaml:"regex"`
	Values []string `yaml:"values"`
}

type Plugin

type Plugin struct {
	Name           string   `yaml:"name"`
	Enabled        bool     `yaml:"enabled"`
	Source         string   `yaml:"source"`
	Type           string   `default:"checks" yaml:"type" `
	Version        string   `yaml:"version"`
	Description    string   `yaml:"description"`
	Exclude        []string `yaml:"exclude"`
	Include        []string `yaml:"include"`
	Command        string   `yaml:"command"`
	Args           []string `yaml:"args"`
	ExpectedOutput string   `yaml:"expected_output"`
	ExpectedStatus int      `yaml:"expected_status"`

	// Parsed source attributes
	SourceOwner string
	SourceRepo  string
}

func (*Plugin) AssetName

func (c *Plugin) AssetName() string

AssetName returns a name that the asset contained in the release should meet. The name must be in a format similar to `yatas-aws_darwin_amd64.zip`.

func (*Plugin) Install

func (c *Plugin) Install() (string, error)

func (*Plugin) InstallPath

func (c *Plugin) InstallPath() string

InstallPath returns an installation path from the plugin directory.

func (*Plugin) TagName

func (c *Plugin) TagName() string

func (*Plugin) Validate

func (c *Plugin) Validate() error

type Resource added in v1.5.0

type Resource interface {
	GetID() string
}

type Result

type Result struct {
	Message    string `yaml:"message"`      // Message to display
	Status     string `yaml:"status"`       // Status of the check
	ResourceID string `yaml:"resource_arn"` // Resource ID - unique identifier for the resource
}

type T

type T Check

type Tests

type Tests struct {
	Account string  `yaml:"account"` // Account name
	Checks  []Check `yaml:"checks"`  // Checks
}

Wrapper struct that holds all the results of the checks for each account

type Yatas

type Yatas interface {
	Run(c *Config) []Tests
}

Yatas is the interface that we're exposing as a plugin.

type YatasPlugin

type YatasPlugin struct {
	// Impl Injection
	Impl Yatas
}

This is the implementation of plugin.Plugin so we can serve/consume this

This has two methods: Server must return an RPC server for this plugin type. We construct a YatasRPCServer for this.

Client must return an implementation of our interface that communicates over an RPC client. We return YatasRPC for this.

Ignore MuxBroker. That is used to create more multiplexed streams on our plugin connection and is a more advanced use case.

func (YatasPlugin) Client

func (YatasPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

func (*YatasPlugin) Server

func (p *YatasPlugin) Server(*plugin.MuxBroker) (interface{}, error)

type YatasRPC

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

Here is an implementation that talks over RPC

func (*YatasRPC) Run

func (g *YatasRPC) Run(c *Config) []Tests

type YatasRPCServer

type YatasRPCServer struct {
	// This is the real implementation
	Impl Yatas
}

Here is the RPC server that YatasRPC talks to, conforming to the requirements of net/rpc

func (*YatasRPCServer) Run

func (s *YatasRPCServer) Run(c *Config, resp *[]Tests) error

Jump to

Keyboard shortcuts

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