Skip to content

Commit

Permalink
feat(plugins): configuration for plugins passed as interface
Browse files Browse the repository at this point in the history
  • Loading branch information
StanGirard committed Sep 9, 2022
1 parent 93e4f11 commit 5a00c38
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 63 deletions.
13 changes: 7 additions & 6 deletions .yatas.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ ignore:
values:
- "VPC has only one gateway on vpc-08ffec87e034a8953"


aws:
- name: "TODO"
profile: ""
sso: false
region: "eu-west-3"
pluginsConfiguration:
- pluginName: aws
accounts:
- name: "example"
profile: ""
sso: false
region: "eu-west-3"


21 changes: 0 additions & 21 deletions internal/yatas/progress.go

This file was deleted.

38 changes: 34 additions & 4 deletions plugins/commons/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
package commons

import "strings"
import (
"strings"

"github.com/stangirard/yatas/internal/helpers"
"gopkg.in/yaml.v3"
)

type Config struct {
Plugins []Plugin `yaml:"plugins"`
AWS []AWS_Account `yaml:"aws"`
Ignore []Ignore `yaml:"ignore"`
Plugins []Plugin `yaml:"plugins"`
AWS []AWS_Account `yaml:"aws"`
Ignore []Ignore `yaml:"ignore"`
PluginConfig []interface{} `yaml:"pluginsConfiguration"`
}

func ParseConfig(configFile string) (*Config, error) {
// Read the file .yatas.yml
// File to array of bytes
data, err := helpers.ReadFile(configFile)
if err != nil {
return &Config{}, err
}

// Parse the yaml file
config := Config{}
err = unmarshalYAML(data, &config)
if err != nil {
return &Config{}, err
}

return &config, nil
}

func unmarshalYAML(data []byte, config *Config) error {
err := yaml.Unmarshal([]byte(data), &config)

return err
}

func (c *Config) FindPluginWithName(name string) *Plugin {
Expand Down
27 changes: 0 additions & 27 deletions plugins/commons/yatas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,8 @@ package commons

import (
"sync"

"github.com/stangirard/yatas/internal/helpers"
"gopkg.in/yaml.v3"
)

func ParseConfig(configFile string) (*Config, error) {
// Read the file .yatas.yml
// File to array of bytes
data, err := helpers.ReadFile(configFile)
if err != nil {
return &Config{}, err
}

// Parse the yaml file
config := Config{}
err = unmarshalYAML(data, &config)
if err != nil {
return &Config{}, err
}

return &config, nil
}

func unmarshalYAML(data []byte, config *Config) error {
err := yaml.Unmarshal([]byte(data), &config)

return err
}

// 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 CheckTest[A, B, C any](wg *sync.WaitGroup, config *Config, id string, test func(A, B, C)) func(A, B, C) {
Expand Down
11 changes: 7 additions & 4 deletions plugins/commons/yatas_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commons

import (
"fmt"
"sync"
"testing"

Expand Down Expand Up @@ -67,9 +68,10 @@ func TestConfig_CheckExclude(t *testing.T) {

func TestConfig_CheckInclude(t *testing.T) {
type fields struct {
Plugins []Plugin
AWS []AWS_Account
Ignore []Ignore
Plugins []Plugin
AWS []AWS_Account
Ignore []Ignore
PluginConfig interface{}
}
type args struct {
id string
Expand Down Expand Up @@ -144,7 +146,8 @@ func TestParseConfig(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := ParseConfig(tt.args.configFile)
config, err := ParseConfig(tt.args.configFile)
fmt.Println(config)
if (err != nil) != tt.wantErr {
t.Errorf("ParseConfig() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
2 changes: 1 addition & 1 deletion plugins/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func RunPlugin(pluginInput commons.Plugin, c *commons.Config) []commons.Tests {
// This prevents users from executing bad plugins or executing a plugin
// directory. It is a UX feature, not a security feature.
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
ProtocolVersion: 2,
MagicCookieKey: "BASIC_PLUGIN",
MagicCookieValue: "hello",
}
Expand Down

0 comments on commit 5a00c38

Please sign in to comment.