Skip to content

Commit

Permalink
add support to get list of iac types with default versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala committed Sep 18, 2020
1 parent 4f99d24 commit 392c486
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/iac-providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package iacprovider
import (
"fmt"
"reflect"
"sort"
"strings"

"go.uber.org/zap"
)
Expand Down Expand Up @@ -54,8 +56,24 @@ func IsIacSupported(iacType, iacVersion string) bool {
// SupportedIacProviders returns list of Iac Providers supported in terrascan
func SupportedIacProviders() []string {
var iacTypes []string
for k, _ := range supportedIacProviders {
for k := range supportedIacProviders {
iacTypes = append(iacTypes, string(k))
}
sort.Strings(iacTypes)
return iacTypes
}

// SupportedIacVersions retuns a string of Iac providers and corresponding supported versions
func SupportedIacVersions() []string {
var iacVersions []string
for iac, versions := range supportedIacProviders {
var versionSlice []string
for k := range versions {
versionSlice = append(versionSlice, string(k))
}
versionString := strings.Join(versionSlice, ", ")
iacVersions = append(iacVersions, fmt.Sprintf("%s: %s", string(iac), versionString))
}
sort.Strings(iacVersions)
return iacVersions
}
13 changes: 13 additions & 0 deletions pkg/iac-providers/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,16 @@ func TestIsIacSupported(t *testing.T) {
})
}
}

func TestSupportedIacProviders(t *testing.T) {
t.Run("supported iac providers", func(t *testing.T) {
var want []string
for k := range supportedIacProviders {
want = append(want, string(k))
}
got := SupportedIacProviders()
if !reflect.DeepEqual(got, want) {
t.Errorf("got: '%v', want: '%v'", got, want)
}
})
}

0 comments on commit 392c486

Please sign in to comment.