Skip to content

Commit

Permalink
Remove support for GCP auth via env vars (closes #181)
Browse files Browse the repository at this point in the history
  • Loading branch information
colmsnowplow committed Aug 12, 2022
1 parent ae608a2 commit 6f961ef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 62 deletions.
11 changes: 0 additions & 11 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ package cmd
import (
"encoding/json"
"fmt"
"os"

"github.com/getsentry/sentry-go"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
sentryhook "github.com/snowplow-devops/go-sentryhook"

config "github.com/snowplow-devops/stream-replicator/config"
"github.com/snowplow-devops/stream-replicator/pkg/common"
)

var (
Expand All @@ -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 {
Expand Down
19 changes: 9 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ type Config struct {

// 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"`
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"`
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.
Expand Down
15 changes: 0 additions & 15 deletions pkg/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
26 changes: 0 additions & 26 deletions pkg/common/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6f961ef

Please sign in to comment.