Skip to content

Commit

Permalink
feat(plugin): first iteration plugin manager (#71)
Browse files Browse the repository at this point in the history
* feat(plugin): first iteration plugin manager
  • Loading branch information
Stan Girard authored Sep 8, 2022
1 parent 97cef4a commit 378b0e1
Show file tree
Hide file tree
Showing 185 changed files with 228 additions and 11,519 deletions.
44 changes: 9 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,28 @@ go 1.19

require (
github.com/aws/aws-sdk-go-v2 v1.16.14
github.com/aws/aws-sdk-go-v2/config v1.17.5
github.com/aws/aws-sdk-go-v2/service/acm v1.14.16
github.com/aws/aws-sdk-go-v2/service/apigateway v1.15.18
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.23.14
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.20.3
github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.16.12
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.16.4
github.com/aws/aws-sdk-go-v2/service/ec2 v1.54.4
github.com/aws/aws-sdk-go-v2/service/ecr v1.17.16
github.com/aws/aws-sdk-go-v2/service/eks v1.21.11
github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.18.17
github.com/aws/aws-sdk-go-v2/service/guardduty v1.15.7
github.com/aws/aws-sdk-go-v2/service/iam v1.18.17
github.com/aws/aws-sdk-go-v2/service/lambda v1.24.4
github.com/aws/aws-sdk-go-v2/service/rds v1.25.5
github.com/aws/aws-sdk-go-v2/service/s3 v1.27.9
github.com/fatih/color v1.13.0
github.com/hashicorp/go-hclog v1.3.0
github.com/mitchellh/mapstructure v1.5.0
github.com/rs/zerolog v1.28.0
github.com/hashicorp/go-plugin v1.4.5
github.com/vbauerster/mpb/v7 v7.5.2
golang.org/x/exp v0.0.0-20220906200021-fcb1a314c389
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.7 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.18 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.21 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.12 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.16 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.15 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.11.21 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.17 // indirect
github.com/aws/smithy-go v1.13.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/golang/protobuf v1.3.4 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/rivo/uniseg v0.3.4 // indirect
golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.27.1 // indirect
)
132 changes: 57 additions & 75 deletions go.sum

Large diffs are not rendered by default.

44 changes: 4 additions & 40 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,24 @@ import (
"flag"
"os"
"sort"
"time"

"github.com/stangirard/yatas/internal/report"
"github.com/stangirard/yatas/internal/yatas"
"github.com/stangirard/yatas/plugins"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
"github.com/stangirard/yatas/plugins/manager"
)

var (
compare = flag.Bool("compare", false, "compare with previous report")
progressflag = flag.Bool("no-progress", false, "don't show the progress bar")
ci = flag.Bool("ci", false, "run in CI with exit code")
compare = flag.Bool("compare", false, "compare with previous report")
ci = flag.Bool("ci", false, "run in CI with exit code")
)

func Execute() error {
config, err := yatas.ParseConfig(".yatas.yml")
if err != nil {
return err
}
checks := manager.RunPlugin("aws", config)

if !*progressflag {
config.Progress = mpb.New(mpb.WithWidth(64))
bar := config.Progress.AddBar(0, mpb.PrependDecorators(
decor.Name("Categories : "),
decor.CountersNoUnit(" %d / %d")),
mpb.AppendDecorators(

decor.Percentage(),
),
)
bar.SetPriority(10)
config.ServiceProgress.Bar = bar

bar2 := config.Progress.AddBar(0,

mpb.PrependDecorators(
decor.Name("Checks : "),
decor.CountersNoUnit("%d / %d")),
mpb.AppendDecorators(
decor.Percentage(),
),
)
bar2.SetPriority(11)

config.CheckProgress.Bar = bar2

}
checks, err := plugins.Execute(config)
if config.Progress != nil {
config.ServiceProgress.Bar.SetTotal(config.ServiceProgress.Bar.Current(), true)
time.Sleep(time.Millisecond * 100)

}
if err != nil {
return err
}
Expand Down
41 changes: 18 additions & 23 deletions internal/yatas/progress.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package yatas

import (
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
// func (c *Config) AddBar(description, id string, value, priority int, p *mpb.Progress) {
// if c.PluginsProgress == nil {
// c.PluginsProgress = make(map[string]Progress)
// }
// c.PluginsProgress[id] = Progress{
// Bar: p.AddBar(int64(value),
// mpb.PrependDecorators(
// decor.Name(description),
// decor.CountersNoUnit(" %d / %d"),
// ),
// mpb.AppendDecorators(
// decor.Percentage(),
// ),
// ),
// Value: value,
// }
// c.PluginsProgress[id].Bar.SetPriority(priority)

func (c *Config) AddBar(description, id string, value, priority int, p *mpb.Progress) {
if c.PluginsProgress == nil {
c.PluginsProgress = make(map[string]Progress)
}
c.PluginsProgress[id] = Progress{
Bar: p.AddBar(int64(value),
mpb.PrependDecorators(
decor.Name(description),
decor.CountersNoUnit(" %d / %d"),
),
mpb.AppendDecorators(
decor.Percentage(),
),
),
Value: value,
}
c.PluginsProgress[id].Bar.SetPriority(priority)

}
// }
38 changes: 14 additions & 24 deletions internal/yatas/yatas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package yatas
import (
"strings"
"sync"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/stangirard/yatas/internal/helpers"
Expand Down Expand Up @@ -41,15 +40,9 @@ type Progress struct {
}

type Config struct {
sync.Mutex

Plugins []Plugin `yaml:"plugins"`
AWS []AWS_Account `yaml:"aws"`
Ignore []Ignore `yaml:"ignore"`
Progress *mpb.Progress
ServiceProgress Progress
CheckProgress Progress
PluginsProgress map[string]Progress
Plugins []Plugin `yaml:"plugins"`
AWS []AWS_Account `yaml:"aws"`
Ignore []Ignore `yaml:"ignore"`
}

func (c *Config) CheckExclude(id string) bool {
Expand Down Expand Up @@ -113,14 +106,13 @@ func unmarshalYAML(data []byte, config *Config) error {
func CheckTest[A, B, C any](wg *sync.WaitGroup, config *Config, id string, test func(A, B, C)) func(A, B, C) {
if !config.CheckExclude(id) && config.CheckInclude(id) {
wg.Add(1)
if config.CheckProgress.Bar != nil {
config.Lock()
config.CheckProgress.Value++
config.CheckProgress.Bar.SetTotal(int64(config.CheckProgress.Value), false)
config.Unlock()
time.Sleep(time.Millisecond * 10)
// if config.CheckProgress.Bar != nil {

}
// config.CheckProgress.Value++
// config.CheckProgress.Bar.SetTotal(int64(config.CheckProgress.Value), false)
// time.Sleep(time.Millisecond * 10)

// }
return test
} else {
return func(A, B, C) {}
Expand All @@ -133,14 +125,12 @@ func CheckTest[A, B, C any](wg *sync.WaitGroup, config *Config, id string, test
func CheckMacroTest[A, B, C, D any](wg *sync.WaitGroup, config *Config, test func(A, B, C, D)) func(A, B, C, D) {
wg.Add(1)
// TODO check
if config.ServiceProgress.Bar != nil {
config.Lock()
config.ServiceProgress.Value++
config.ServiceProgress.Bar.SetTotal(int64(config.ServiceProgress.Value), false)
config.Unlock()
time.Sleep(time.Millisecond * 10)
// if config.ServiceProgress.Bar != nil {
// config.ServiceProgress.Value++
// config.ServiceProgress.Bar.SetTotal(int64(config.ServiceProgress.Value), false)
// time.Sleep(time.Millisecond * 10)

}
// }

return test
}
Expand Down
35 changes: 0 additions & 35 deletions plugins/aws/acm/acm.go

This file was deleted.

30 changes: 0 additions & 30 deletions plugins/aws/acm/acmExpiry.go

This file was deleted.

82 changes: 0 additions & 82 deletions plugins/aws/acm/acmExpiry_test.go

This file was deleted.

Loading

0 comments on commit 378b0e1

Please sign in to comment.