Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gak committed May 24, 2024
1 parent 8086136 commit b7c2973
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
116 changes: 116 additions & 0 deletions common/configuration/aws_secrets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package configuration

import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
_ "github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
_ "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
"log"
"net/url"
)

type AWSSecrets[R Role] struct {
client *secretsmanager.Client

AccessKeyId string
SecretAccessKey string
Region string
Endpoint string
}

var _ Resolver[Secrets] = AWSSecrets[Secrets]{}
var _ Provider[Secrets] = AWSSecrets[Secrets]{}
var _ MutableProvider[Secrets] = AWSSecrets[Secrets]{}

func (a AWSSecrets[R]) getClient(ctx context.Context) (*AWSSecrets[Secrets], error) {
cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion(a.region),
)
if err != nil {
return nil, err
}

svc := secretsmanager.NewFromConfig(cfg, func(o *secretsmanager.Options) {
e, ok := endpoint.Get()
if ok {
o.BaseEndpoint = aws.String(e)
}
})

return &AWSSecrets[Secrets]{
AccessKeyId: accessKeyId,
SecretAccessKey: secretAccessKey,
Region: region,
client: svc,
}, nil
}

func (a AWSSecrets[R]) Role() R {
var r R
return r
}

func (a AWSSecrets[R]) Get(ctx context.Context, ref Ref) (*url.URL, error) {}

func (a AWSSecrets[R]) Set(ctx context.Context, ref Ref, key *url.URL) error {
//this will have to do a list/check to see if the secret exists

}

func (a AWSSecrets[R]) Unset(ctx context.Context, ref Ref) error {}

func (a AWSSecrets[R]) List(ctx context.Context) ([]Entry, error) {}

func (a AWSSecrets[R]) Key() string {
return "asm"
}

func (a AWSSecrets[R]) Load(ctx context.Context, ref Ref, key *url.URL) ([]byte, error) {}

func (a AWSSecrets[R]) Writer() bool {
return true
}

func (a AWSSecrets[R]) Store(ctx context.Context, ref Ref, value []byte) (*url.URL, error) {}

func (a AWSSecrets[R]) Delete(ctx context.Context, ref Ref) error {}

func brainstorm() {
endpoint := "http://localhost:4566"

cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-west-2"),
)

if err != nil {
log.Fatalf("unable to load SDK config, %v", err)
}

svc := secretsmanager.NewFromConfig(cfg, func(o *secretsmanager.Options) {
o.BaseEndpoint = aws.String(endpoint)
})

// create a secret
name := "test-secret3"
secret := "hunter1"
_, err = svc.CreateSecret(context.TODO(), &secretsmanager.CreateSecretInput{
Name: &name,
SecretString: &secret,
})
if err != nil {
log.Fatalf("failed to create secret, %v", err)
}

// get the secret
out, err := svc.GetSecretValue(context.TODO(), &secretsmanager.GetSecretValueInput{
SecretId: &name,
})
if err != nil {
log.Fatalf("failed to retrieve secret, %v", err)
}

log.Printf("retrieved secret: %s", *out.SecretString)

}
9 changes: 9 additions & 0 deletions common/configuration/aws_secrets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package configuration

import "testing"

func TestMoo(t *testing.T) {
t.Log("moo")

brainstorm()
}

0 comments on commit b7c2973

Please sign in to comment.