Skip to content

Commit

Permalink
fix(): small update for AWS Secret Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
le-vlad committed May 8, 2024
1 parent 410c158 commit f99426e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ETCD struct {
}

type Secrets struct {
StorageType secret.SecretsStorageType `yaml:"storage_type"`
StorageType secret.SecretsStorageType `yaml:"storage_type" validate:"required"`
Config interface{} `yaml:"config"`
}

Expand Down
5 changes: 3 additions & 2 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ func resolveSecrets(config []byte) []byte {
}

secretStorage := secret.NewSecrets(conf.Secrets.StorageType, conf.Secrets.Config)

replaced := secretsRegex.ReplaceAllFunc(config, func(content []byte) []byte {
var value string
if len(content) > 4 {
varName := string(content[2 : len(content)-1])
// 9 - removes #{secret.
// -1 - removes }
varName := string(content[9 : len(content)-1])
secretValue, err := secretStorage.Retrieve(varName)
if err != nil {
logger.GetInstance().Fatalf("Failed to resolve secret value. Error: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion config/config_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Test_resolveSecrets(t *testing.T) {
log.Fatal(err)
}

if cfg.Service.ETCD.Host != "value_secret.etcd/host" {
if cfg.Service.ETCD.Host != "value_etcd/host" {
t.Fatal("Invalid ETCD host in config")
}
}
2 changes: 1 addition & 1 deletion internal/secret/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type SecretsStorageType string

const AwsSecretStorage SecretsStorageType = "aws_secret_storage"
const AwsSecretStorage SecretsStorageType = "aws_secret_manager"
const MockSecretStorage SecretsStorageType = "mock_secret_storage"

type Secrets struct{}
Expand Down
9 changes: 6 additions & 3 deletions internal/secret/secretstorage/aws_secret_manager.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package secretstorage

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/secretsmanager"
)

type AwsSecretManagerConfig struct {
SecretKey string `yaml:"secret_key"`
SecretKeyID string `yaml:"secret_key_id"`
Region string `yaml:"region"`
SecretKey string `yaml:"aws_secret_key"`
SecretKeyID string `yaml:"aws_secret_key_id"`
Region string `yaml:"aws_region"`
}

type AwsSecretManager struct {
Expand All @@ -35,6 +37,7 @@ func NewAwsSecretManager(config AwsSecretManagerConfig) *AwsSecretManager {
}

func (a *AwsSecretManager) Retrieve(key string) (string, error) {
fmt.Println("Rertienving secret from AWS Secret Manager", key)
v, err := a.secretsmanager.GetSecretValue(&secretsmanager.GetSecretValueInput{
SecretId: aws.String(key),
})
Expand Down
7 changes: 5 additions & 2 deletions public/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package stream

import (
"errors"
"sync"
"time"

"github.com/usedatabrew/blink/config"
"github.com/usedatabrew/blink/internal/offset_storage"
"github.com/usedatabrew/blink/internal/schema"
"github.com/usedatabrew/blink/internal/service_registry"
"github.com/usedatabrew/blink/internal/stream_context"
"github.com/usedatabrew/message"
"github.com/usedatabrew/tango"
"sync"
"time"
)

type Stream struct {
Expand All @@ -32,6 +33,8 @@ func InitFromConfig(config config.Configuration) (*Stream, error) {
if config.Service.OffsetStorageURI != "" {
offsetStorage := offset_storage.NewOffsetStorage(config.Service.OffsetStorageURI)
streamContext.SetOffsetStorage(offsetStorage)
} else {
streamContext.Logger.Warn("No offset storage URI provided. Offset will not be stored")
}

var processorList []string
Expand Down

0 comments on commit f99426e

Please sign in to comment.