Skip to content

Commit

Permalink
Merge pull request #7 from armosec/fix-unmarshal-config
Browse files Browse the repository at this point in the history
fix config unmarshal
  • Loading branch information
amirmalka authored Aug 30, 2023
2 parents 57825fc + 4239a40 commit 9e6bf6f
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 90 deletions.
8 changes: 7 additions & 1 deletion armometadata/k8sutils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package armometadata

import (
"encoding/json"
"fmt"
"hash/fnv"
"path"
Expand Down Expand Up @@ -93,6 +94,11 @@ func LoadConfig(configPath string) (*ClusterConfig, error) {
return config, err
}

err = viper.Unmarshal(config)
res, err := json.Marshal(viper.AllSettings())
if err != nil {
return config, err
}

err = json.Unmarshal(res, &config)
return config, err
}
18 changes: 17 additions & 1 deletion armometadata/k8sutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package armometadata
import (
"testing"

"github.com/armosec/armoapi-go/armotypes"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -78,6 +79,17 @@ func TestLoadClusterConfig(t *testing.T) {
GatewayRestURL: "gateway:8002",
KubevulnURL: "kubevuln:8080",
KubescapeURL: "kubescape:8080",
InstallationData: armotypes.InstallationData{
Namespace: "kubescape",
ImageVulnerabilitiesScanningEnabled: BoolPtr(true),
PostureScanEnabled: BoolPtr(true),
OtelCollectorEnabled: BoolPtr(true),
ClusterProvider: "aws",
ClusterShortName: "ccc",
StorageEnabled: BoolPtr(true),
RelevantImageVulnerabilitiesConfiguration: "detect",
RelevantImageVulnerabilitiesEnabled: BoolPtr(false),
},
},
},
{
Expand All @@ -91,8 +103,8 @@ func TestLoadClusterConfig(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viper.Reset()

got, err := LoadConfig(tt.args.path)

if tt.wantErr {
assert.Errorf(t, err, "LoadClusterConfig() error = %v, wantErr %v", err, tt.wantErr)
return
Expand All @@ -103,3 +115,7 @@ func TestLoadClusterConfig(t *testing.T) {
})
}
}

func BoolPtr(b bool) *bool {
return &b
}
19 changes: 9 additions & 10 deletions armometadata/testdata/clusterData.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
"triggerNewImageScan": "false",
"accountID": "ed1e102b-13eb-4d25-b078-e10386305b26",
"clusterName": "gke_armo-test-clusters_us-central1-c_matthias",
"nodeAgent": "false",
"maxImageSize": 5.36870912e+09,
"keepLocal": false,
"scanTimeout": "5m",
"clusterShortName": "ccc",
"storage": true,
"relevantImageVulnerabilitiesEnabled": true,
"relevantImageVulnerabilitiesEnabled": false,
"relevantImageVulnerabilitiesConfiguration": "detect",
"namespace": "kubescape",
"imageVulnerabilitiesScanningEnabled": true,
"postureScanEnabled": true,
"otelCollector": true,
"nodeAgent": "true",
"maxImageSize": 5.36870912e+09,
"keepLocal": false,
"scanTimeout": "5m",
"backendOpenAPI": "https://api-dev.armosec.io/api",
"eventReceiverRestURL": "https://report.eudev3.cyberarmorsoft.com",
"eventReceiverWebsocketURL": "wss://report.eudev3.cyberarmorsoft.com",
"rootGatewayURL": "wss://ens.eudev3.cyberarmorsoft.com/v1/waitfornotification"
}
"clusterProvider": "aws"
}
67 changes: 35 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,75 @@ module github.com/armosec/utils-k8s-go
go 1.18

require (
github.com/armosec/armoapi-go v0.0.191
github.com/armosec/utils-go v0.0.12
github.com/docker/docker v20.10.17+incompatible
github.com/armosec/armoapi-go v0.0.234
github.com/armosec/utils-go v0.0.20
github.com/docker/docker v24.0.5+incompatible
github.com/francoispqt/gojay v1.2.13
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.22.0
k8s.io/api v0.24.3
k8s.io/apimachinery v0.24.3
k8s.io/api v0.25.3
k8s.io/apimachinery v0.27.4
k8s.io/apiserver v0.24.3
k8s.io/client-go v0.24.3
k8s.io/client-go v0.25.3
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/armosec/gojay v1.2.15 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stripe/stripe-go/v74 v74.8.0 // indirect
github.com/stripe/stripe-go/v74 v74.28.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 9e6bf6f

Please sign in to comment.