Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions aws-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"flag"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ssm"
"log"
"os"
"strings"

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

const (
Expand All @@ -17,6 +18,7 @@ const (
)

func main() {
// Check if AWS_ENV_PATH is set
if os.Getenv("AWS_ENV_PATH") == "" {
log.Println("aws-env running locally, without AWS_ENV_PATH")
return
Expand All @@ -26,15 +28,18 @@ func main() {
format := flag.String("format", formatExports, "output format")
flag.Parse()

if *format == formatExports || *format == formatDotenv {
} else {
if *format != formatExports && *format != formatDotenv {
log.Fatal("Unsupported format option. Must be 'exports' or 'dotenv'")
}

sess := CreateSession()
client := CreateClient(sess)

ExportVariables(client, os.Getenv("AWS_ENV_PATH"), *recursivePtr, *format, "")
// if AWS_ENV_PATH contains a comma-separated list, export variables for each path
paths := strings.Split(os.Getenv("AWS_ENV_PATH"), ",")
for _, path := range paths {
ExportVariables(client, strings.TrimSpace(path), *recursivePtr, *format, "")
}
}

func CreateSession() *session.Session {
Expand Down Expand Up @@ -77,6 +82,7 @@ func OutputParameter(path string, parameter *ssm.Parameter, format string) {

env := strings.Replace(strings.Trim(name[len(path):], "/"), "/", "_", -1)
value = strings.Replace(value, "\n", "\\n", -1)
value = strings.Replace(value, "'", "\\'", -1)

switch format {
case formatExports:
Expand Down
Binary file removed bin/aws-env-darwin-386
Binary file not shown.
Binary file modified bin/aws-env-darwin-amd64
Binary file not shown.
Binary file added bin/aws-env-darwin-arm64
Binary file not shown.
Binary file removed bin/aws-env-linux-386
Binary file not shown.
Binary file modified bin/aws-env-linux-amd64
Binary file not shown.
Binary file modified bin/aws-env-linux-arm64
Binary file not shown.
Binary file removed bin/aws-env-windows-386
Binary file not shown.
Binary file modified bin/aws-env-windows-amd64
Binary file not shown.
Binary file added bin/aws-env-windows-arm64
Binary file not shown.
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
BUILD_DIR=bin
NAME=aws-env

mkdir $BUILD_DIR
mkdir -p $BUILD_DIR

for GOOS in darwin linux windows; do
for GOARCH in 386 amd64; do
for GOARCH in amd64 arm64; do
GOOS=$GOOS GOARCH=$GOARCH go build -v -o $BUILD_DIR/$NAME-$GOOS-$GOARCH
done
done
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/Mailbutler/aws-env

go 1.24.4

require github.com/aws/aws-sdk-go v1.55.7

require github.com/jmespath/go-jmespath v0.4.0 // indirect
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE=
github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=