Skip to content

Commit

Permalink
chore: pin go version to allow compiling from older images
Browse files Browse the repository at this point in the history
- Used RegistryKeys for all plugin types for listing command.
  • Loading branch information
yusufhm committed Feb 12, 2025
1 parent c7dd8ad commit f7e1c2f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
24 changes: 10 additions & 14 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmd

import (
"fmt"
"maps"
"slices"
"sort"

log "github.com/sirupsen/logrus"
Expand All @@ -15,6 +13,7 @@ import (
"github.com/salsadigitalauorg/shipshape/pkg/connection"
"github.com/salsadigitalauorg/shipshape/pkg/fact"
"github.com/salsadigitalauorg/shipshape/pkg/output"
"github.com/salsadigitalauorg/shipshape/pkg/remediation"
"github.com/salsadigitalauorg/shipshape/pkg/shipshape"
)

Expand Down Expand Up @@ -46,30 +45,27 @@ var configListPluginsCmd = &cobra.Command{
Long: `List all available plugins that can be used in shipshape`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Connection plugins:")
plugins := slices.Collect(maps.Keys(connection.Registry))
sort.Strings(plugins)
for _, p := range plugins {
for _, p := range connection.RegistryKeys() {
fmt.Println(" - " + p)
}

fmt.Println("\nFact plugins:")
plugins = slices.Collect(maps.Keys(fact.Registry))
sort.Strings(plugins)
for _, p := range plugins {
for _, p := range fact.RegistryKeys() {
fmt.Println(" - " + p)
}

fmt.Println("\nAnalyse plugins:")
plugins = slices.Collect(maps.Keys(analyse.Registry))
sort.Strings(plugins)
for _, p := range plugins {
for _, p := range analyse.RegistryKeys() {
fmt.Println(" - " + p)
}

fmt.Println("\nRemediate plugins:")
for _, p := range remediation.RegistryKeys() {
fmt.Println(" - " + p)
}

fmt.Println("\nOutput plugins:")
plugins = slices.Collect(maps.Keys(output.Outputters))
sort.Strings(plugins)
for _, p := range plugins {
for _, p := range output.RegistryKeys() {
fmt.Println(" - " + p)
}
},
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/salsadigitalauorg/shipshape

go 1.23.5
go 1.21.0

toolchain go1.22.5

require (
github.com/doug-martin/goqu/v9 v9.19.0
Expand Down
7 changes: 5 additions & 2 deletions pkg/analyse/analyse.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package analyse

import (
"sort"

log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"

Expand All @@ -11,18 +13,19 @@ var Registry = map[string]func(string) Analyser{}
var Analysers = map[string]Analyser{}
var Errors = []error{}

func registryKeys() []string {
func RegistryKeys() []string {
keys := []string{}
for k := range Registry {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

// ParseConfig parses the raw config and creates the analysers.
func ParseConfig(raw map[string]map[string]interface{}) {
count := 0
log.WithField("registry", registryKeys()).Debug("analysers")
log.WithField("registry", RegistryKeys()).Debug("analysers")
for name, pluginConf := range raw {
for pluginName, pluginMap := range pluginConf {
f, ok := Registry[pluginName]
Expand Down
6 changes: 4 additions & 2 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package connection

import (
"fmt"
"sort"

log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
Expand All @@ -11,17 +12,18 @@ var Registry = map[string]func(string) Connectioner{}
var Connections = map[string]Connectioner{}
var Errors = []error{}

func registryKeys() []string {
func RegistryKeys() []string {
keys := []string{}
for k := range Registry {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

func ParseConfig(raw map[string]map[string]interface{}) {
count := 0
log.WithField("registry", registryKeys()).Debug("available connections")
log.WithField("registry", RegistryKeys()).Debug("available connections")
for name, pluginConf := range raw {
for pluginName, pluginMap := range pluginConf {
f, ok := Registry[pluginName]
Expand Down
7 changes: 5 additions & 2 deletions pkg/fact/facts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fact

import (
"sort"

log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -41,17 +43,18 @@ func GetInstance(name string) Facter {
}
}

func registryKeys() []string {
func RegistryKeys() []string {
keys := []string{}
for k := range Registry {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

func ParseConfig(raw map[string]map[string]interface{}) {
count := 0
log.WithField("registry", registryKeys()).Debug("available fact plugins")
log.WithField("registry", RegistryKeys()).Debug("available fact plugins")
for name, pluginConf := range raw {
for pluginName, pluginMap := range pluginConf {
f, ok := Registry[pluginName]
Expand Down
6 changes: 4 additions & 2 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package output

import (
"io"
"sort"

log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
Expand All @@ -15,17 +16,18 @@ type Outputter interface {

var Outputters = map[string]Outputter{}

func registryKeys() []string {
func RegistryKeys() []string {
keys := []string{}
for k := range Outputters {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

func ParseConfig(raw map[string]interface{}, rl *result.ResultList) {
count := 0
log.WithField("registry", registryKeys()).Debug("outputters")
log.WithField("registry", RegistryKeys()).Debug("outputters")
for pluginName, pluginMap := range raw {
o, ok := Outputters[pluginName]
if !ok {
Expand Down
10 changes: 10 additions & 0 deletions pkg/remediation/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package remediation
import (
"encoding/json"
"fmt"
"sort"

log "github.com/sirupsen/logrus"
)
Expand All @@ -29,6 +30,15 @@ type RemediationResult struct {

var Registry = map[string]func() Remediator{}

func RegistryKeys() []string {
keys := []string{}
for k := range Registry {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

func RemediatorFromInterface(remediation interface{}) Remediator {
if remediation == nil {
return nil
Expand Down

0 comments on commit f7e1c2f

Please sign in to comment.