Skip to content

Commit

Permalink
Updating env variables to Prepend crda (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Deepak Sharma authored Jun 2, 2021
1 parent b91c34b commit 734eec0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions acceptance-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ set -exv

mkdir -p $HOME/.crda

export AUTH_TOKEN=${THREE_SCALE_KEY:-3e42fa66f65124e6b1266a23431e3d08};
export CRDA_AUTH_TOKEN=${THREE_SCALE_KEY:-3e42fa66f65124e6b1266a23431e3d08};
export CRDA_KEY=${CRDA_KEY:-d931dd95-ab1f-4f74-9a9f-fb50f60e4ea9};
export HOST=https://f8a-analytics-preview-2445582058137.staging.gw.apicast.io
export CRDA_HOST=https://f8a-analytics-preview-2445582058137.staging.gw.apicast.io
export snyk_token=${SNYK_TOKEN}

printf 'auth_token: %s\nconsent_telemetry: false\ncrda_key: %s\nhost: %s' "${AUTH_TOKEN}" "${CRDA_KEY}" "${HOST}" >> $HOME/.crda/config.yaml
printf 'crda_auth_token: %s\nconsent_telemetry: false\ncrda_key: %s\nhost: %s' "${CRDA_AUTH_TOKEN}" "${CRDA_KEY}" "${HOST}" >> $HOME/.crda/config.yaml

cat $HOME/.crda/config.yaml

Expand Down
4 changes: 2 additions & 2 deletions cmd/analyse.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func runAnalyse(cmd *cobra.Command, args []string) error {
manifestPath := getAbsPath(args[0])
requestParams := driver.RequestType{
UserID: viper.GetString("crda_key"),
ThreeScaleToken: viper.GetString("auth_token"),
Host: viper.GetString("host"),
ThreeScaleToken: viper.GetString("crda_auth_token"),
Host: viper.GetString("crda_host"),
Client: client,
RawManifestFile: manifestPath,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func runAuth(cmd *cobra.Command, _ []string) error {
requestParams := auth.RequestServerType{
UserID: viper.GetString("crda_key"),
SynkToken: snykToken,
ThreeScaleToken: viper.GetString("auth_token"),
Host: viper.GetString("host"),
ThreeScaleToken: viper.GetString("crda_auth_token"),
Host: viper.GetString("crda_host"),
Client: client,
}
userID, err := auth.RequestServer(cmd.Context(), requestParams)
Expand Down
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ func initConfig() {
log.Fatal().Err(err).Msgf(err.Error())
}
}
if !viper.IsSet("host") {
viper.Set("host", utils.Host)
if !viper.IsSet("crda_host") {
viper.Set("crda_host", utils.CRDAHost)
}
if !viper.IsSet("auth_token") {
viper.Set("auth_token", utils.AuthToken)
if !viper.IsSet("crda_auth_token") {
viper.Set("crda_auth_token", utils.CRDAAuthToken)
}

err = viper.WriteConfig()
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/fabric8-analytics/cli-tools/pkg/telemetry"
"net/http"

utils "github.com/fabric8-analytics/cli-tools/utils"
"github.com/fabric8-analytics/cli-tools/utils"
"github.com/rs/zerolog/log"
)

Expand Down
8 changes: 4 additions & 4 deletions pkg/config/viper_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

type viperConfigs struct {
Host string `mapstructure:"HOST" yaml:"host"`
AuthToken string `mapstructure:"AUTH_TOKEN" yaml:"auth_token"`
Host string `mapstructure:"CRDA_HOST" yaml:"crda_host"`
AuthToken string `mapstructure:"CRDA_AUTH_TOKEN" yaml:"crda_auth_token"`
CrdaKey string `mapstructure:"CRDA_KEY" yaml:"crda_key"`
ConsentTelemetry string `mapstructure:"CONSENT_TELEMETRY" yaml:"consent_telemetry"`
}
Expand All @@ -20,8 +20,8 @@ func ViperUnMarshal() *viperConfigs {
viper.AutomaticEnv()
// Have to bind individual variables: https://github.com/spf13/viper/issues/188
viper.BindEnv("CONSENT_TELEMETRY")
viper.BindEnv("AUTH_TOKEN")
viper.BindEnv("HOST")
viper.BindEnv("CRDA_AUTH_TOKEN")
viper.BindEnv("CRDA_HOST")
viper.BindEnv("CRDA_KEY")
err := viper.Unmarshal(&ActiveConfigValues)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/viper_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

func TestViperUnMarshal(t *testing.T) {
os.Setenv("HOST", "host")
os.Setenv("AUTH_TOKEN", "token")
os.Setenv("CRDA_HOST", "host")
os.Setenv("CRDA_AUTH_TOKEN", "token")
os.Setenv("CONSENT_TELEMETRY", "false")
os.Setenv("CRDA_KEY", "abc")
want := &viperConfigs{
Expand Down
8 changes: 4 additions & 4 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package utils

// Flag Defaults
const (
Host string = "https://f8a-analytics-2445582058137.production.gw.apicast.io"
AuthToken string = "9e7da76708fe374d8c10fa752e72989f"
Debug bool = false
ActualHost string = "https://recommender.api.openshift.io"
CRDAHost string = "https://f8a-analytics-2445582058137.production.gw.apicast.io"
CRDAAuthToken string = "9e7da76708fe374d8c10fa752e72989f"
Debug bool = false
ActualHost string = "https://recommender.api.openshift.io"
)

0 comments on commit 734eec0

Please sign in to comment.