From 0465dbcfb250ecf19812b07ffd01e4ea5c35f37a Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 12 Dec 2024 16:47:57 +0100 Subject: [PATCH] fix: check dynamo credentials on start Closes #18 --- acme/setup.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/acme/setup.go b/acme/setup.go index dcc0d55..7db4779 100644 --- a/acme/setup.go +++ b/acme/setup.go @@ -2,6 +2,7 @@ package acme import ( "fmt" + "os" "strconv" "strings" @@ -117,12 +118,23 @@ func parse(c *caddy.Controller) (*acmeReader, *acmeWriter, error) { if len(args) != 1 { return nil, nil, c.ArgErr() } + // Confirm required AWS environment variables are present + requiredVars := []string{ + "AWS_REGION", + "AWS_ACCESS_KEY_ID", + "AWS_SECRET_ACCESS_KEY", + } + for _, v := range requiredVars { + if os.Getenv(v) == "" { + return nil, nil, fmt.Errorf("database-type dynamo: missing or empty environment variable: %s", v) + } + } ddbClient := ddbv1.New(session.Must(session.NewSession())) ds = ddbds.New(ddbClient, args[0]) case "badger": if len(args) != 1 { - return nil, nil, fmt.Errorf("need to pass a path for the Badger configuration") + return nil, nil, fmt.Errorf("database-type badger: need to pass a path for the Badger configuration") } dbPath := args[0] var err error