diff --git a/cmd/init.go b/cmd/init.go index 939425c8..a73a671a 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -9,7 +9,6 @@ package cmd import ( "encoding/json" "fmt" - "os" "github.com/getsentry/sentry-go" "github.com/pkg/errors" @@ -17,7 +16,6 @@ import ( sentryhook "github.com/snowplow-devops/go-sentryhook" config "github.com/snowplow-devops/stream-replicator/config" - "github.com/snowplow-devops/stream-replicator/pkg/common" ) var ( @@ -43,15 +41,6 @@ func Init() (*config.Config, bool, error) { return nil, false, errors.Wrap(err, "Failed to build config") } - // Configure GCP Access (if set) - if cfg.Data.GoogleServiceAccountB64 != "" { - targetFile, err := common.GetGCPServiceAccountFromBase64(cfg.Data.GoogleServiceAccountB64) - if err != nil { - return nil, false, errors.Wrap(err, "Failed to store GCP Service Account JSON file") - } - os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", targetFile) - } - // Configure Sentry sentryEnabled := cfg.Data.Sentry.Dsn != "" if sentryEnabled { diff --git a/config/config.go b/config/config.go index a63ff7a8..5076b4b2 100644 --- a/config/config.go +++ b/config/config.go @@ -33,18 +33,17 @@ type Config struct { Decoder Decoder } -// ConfigurationData for holding all configuration options -type ConfigurationData struct { - Source *Component `hcl:"source,block" envPrefix:"SOURCE_"` - Target *Component `hcl:"target,block" envPrefix:"TARGET_"` - FailureTarget *FailureConfig `hcl:"failure_target,block"` - Sentry *SentryConfig `hcl:"sentry,block"` - StatsReceiver *StatsConfig `hcl:"stats_receiver,block"` - Transformation string `hcl:"message_transformation,optional" env:"MESSAGE_TRANSFORMATION"` - LogLevel string `hcl:"log_level,optional" env:"LOG_LEVEL"` - GoogleServiceAccountB64 string `hcl:"google_application_credentials_b64,optional" env:"GOOGLE_APPLICATION_CREDENTIALS_B64"` - UserProvidedID string `hcl:"user_provided_id,optional" env:"USER_PROVIDED_ID"` - DisableTelemetry bool `hcl:"disable_telemetry,optional" env:"DISABLE_TELEMETRY"` +// configurationData for holding all configuration options +type configurationData struct { + Source *component `hcl:"source,block" envPrefix:"SOURCE_"` + Target *component `hcl:"target,block" envPrefix:"TARGET_"` + FailureTarget *failureConfig `hcl:"failure_target,block"` + Sentry *sentryConfig `hcl:"sentry,block"` + StatsReceiver *statsConfig `hcl:"stats_receiver,block"` + Transformations []*component `hcl:"transform,block"` + LogLevel string `hcl:"log_level,optional" env:"LOG_LEVEL"` + UserProvidedID string `hcl:"user_provided_id,optional" env:"USER_PROVIDED_ID"` + DisableTelemetry bool `hcl:"disable_telemetry,optional" env:"DISABLE_TELEMETRY"` } // component is a type to abstract over configuration blocks. diff --git a/pkg/common/helpers.go b/pkg/common/helpers.go index edea93fe..8a962424 100644 --- a/pkg/common/helpers.go +++ b/pkg/common/helpers.go @@ -20,23 +20,8 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sts" "github.com/pkg/errors" - "github.com/twinj/uuid" ) -// --- Cloud Helpers - -// GetGCPServiceAccountFromBase64 will take a base64 encoded string -// and attempt to create a JSON file on disk within the /tmp directory -// for later use in creating GCP clients. -func GetGCPServiceAccountFromBase64(serviceAccountB64 string) (string, error) { - targetFile := fmt.Sprintf(`tmp_replicator/stream-replicator-service-account-%s.json`, uuid.NewV4().String()) - err := DecodeB64ToFile(serviceAccountB64, targetFile) - if err != nil { - return ``, err - } - return targetFile, nil -} - // DeleteTemporaryDir deletes the temp directory we created to store credentials func DeleteTemporaryDir() error { err := os.RemoveAll(`tmp_replicator`) diff --git a/pkg/common/helpers_test.go b/pkg/common/helpers_test.go index 3360f29c..8257b87b 100644 --- a/pkg/common/helpers_test.go +++ b/pkg/common/helpers_test.go @@ -8,38 +8,12 @@ package common import ( "crypto/tls" - "strings" "testing" "time" "github.com/stretchr/testify/assert" ) -// --- Cloud Helpers -func TestGetGCPServiceAccountFromBase64(t *testing.T) { - assert := assert.New(t) - defer DeleteTemporaryDir() - - path, err := GetGCPServiceAccountFromBase64("ewogICJoZWxsbyI6IndvcmxkIgp9") - - assert.NotEqual(path, "") - assert.Nil(err) - assert.True(strings.HasPrefix(path, "tmp_replicator/stream-replicator-service-account-")) - assert.True(strings.HasSuffix(path, ".json")) -} - -func TestGetGCPServiceAccountFromBase64_NotBase64(t *testing.T) { - assert := assert.New(t) - - path, err := GetGCPServiceAccountFromBase64("helloworld") - - assert.Equal("", path) - assert.NotNil(err) - if err != nil { - assert.True(strings.HasPrefix(err.Error(), "Failed to Base64 decode")) - } -} - func TestGetAWSSession(t *testing.T) { assert := assert.New(t)