Skip to content

Commit

Permalink
Reuse connection, no commends, add arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
lewg committed Sep 21, 2023
1 parent 5f0afba commit 39ae0ea
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-deps:
go get github.com/aktau/github-release

build:
CGO_ENABLED=0 gox -ldflags "-X main.version=$(VERSION)" -osarch="darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm windows/386 windows/amd64" -output "pkg/{{.OS}}_{{.Arch}}/$(PROJECT_NAME)"
CGO_ENABLED=0 gox -ldflags "-X main.version=$(VERSION)" -osarch="darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm linux/arm64 windows/386 windows/amd64" -output "pkg/{{.OS}}_{{.Arch}}/$(PROJECT_NAME)"
for pkg in $$(ls pkg/); do cp CONTRIBUTING.md CONTRIBUTORS.md LICENSE NOTICE pkg/$${pkg}; done
for pkg in $$(ls pkg/); do cd pkg/$${pkg}; tar cvzf "../../$(PROJECT_NAME)-$${pkg}-$(VERSION).tar.gz" $(PROJECT_NAME)*; cd ../..; done

Expand Down
75 changes: 58 additions & 17 deletions buildenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

var (
version = "Development"
vault *vaultapi.Client
)

// EnvErrorCode Exit Code for Missing Environment
Expand Down Expand Up @@ -47,10 +48,12 @@ func GetVaultSecret(path string) (*vaultapi.Secret, error) {
// Get Config Completely From Environment
var c *vaultapi.Config

vault, err := vaultapi.NewClient(c)

if err != nil {
return nil, fmt.Errorf("Vault - Client Error: %s", err)
if vault == nil {
var err error
vault, err = vaultapi.NewClient(c)
if err != nil {
return nil, fmt.Errorf("Vault - Client Error: %s", err)
}
}

vaultSecret, err := vault.Logical().Read(path)
Expand All @@ -71,6 +74,7 @@ func main() {
var dc string
var varsFile string
var mlockBool = false
var skipComments = false

type EnvVars map[string]string

Expand Down Expand Up @@ -125,6 +129,12 @@ func main() {
Required: false,
Destination: &mlockBool,
},
cli.BoolFlag{
Name: "no_comments, c",
Usage: "Supress all comments in the output",
Required: false,
Destination: &skipComments,
},
}

app.Version = version
Expand Down Expand Up @@ -162,39 +172,59 @@ func main() {
}
}

fmt.Println("# Setting Variables for:")
fmt.Printf("# Environment: %s\n", env)
if !skipComments {
fmt.Println("# Setting Variables for:")
fmt.Printf("# Environment: %s\n", env)
}
if dc != "" {
fmt.Printf("# Datacenter: %s\n", dc)
if !skipComments {
fmt.Printf("# Datacenter: %s\n", dc)
}
}

// Print The Globals
fmt.Println("# Global Vars:")
if !skipComments {
fmt.Println("# Global Vars:")
}
for k, v := range config.Vars {
fmt.Printf("export %s=%q\n", k, v)
}

fmt.Println("# Global Secrets:")
if !skipComments {
fmt.Println("# Global Secrets:")
}
for k, path := range config.Secrets {
secret, err := GetVaultSecret(path)
if err == nil {
fmt.Printf("export %s=%q # %s\n", k, secret.Data["value"], path)
fmt.Printf("export %s=%q", k, secret.Data["value"])
if !skipComments {
fmt.Printf(" # %s", path)
}
fmt.Println()
} else {
return cli.NewExitError(err.Error(), VaultErrorCode)
}
}

// Print The Environment Specific Vars
fmt.Printf("# Environment (%s) Vars:\n", env)
if !skipComments {
fmt.Printf("# Environment (%s) Vars:\n", env)
}
for k, v := range config.Environments[env].Vars {
fmt.Printf("export %s=%q\n", k, v)
}

fmt.Printf("# Environment (%s) Secrets:\n", env)
if !skipComments {
fmt.Printf("# Environment (%s) Secrets:\n", env)
}
for k, path := range config.Environments[env].Secrets {
secret, err := GetVaultSecret(path)
if err == nil {
fmt.Printf("export %s=%q # %s\n", k, secret.Data["value"], path)
fmt.Printf("export %s=%q", k, secret.Data["value"])
if !skipComments {
fmt.Printf(" # %s", path)
}
fmt.Println()
} else {
return cli.NewExitError(err.Error(), VaultErrorCode)
}
Expand All @@ -203,22 +233,33 @@ func main() {
// Print the DC Specific Vars
if legacy {
if dc != "" {
fmt.Printf("# Datacenter (%s) Specific Vars:\n", dc)
if !skipComments {
fmt.Printf("# Datacenter (%s) Specific Vars:\n", dc)
}
for k, v := range config.Environments[env].Dcs[dc].Vars {
fmt.Printf("export %s=%q\n", k, v)
}
}
} else {
fmt.Printf("# Datacenter (%s) Specific Vars:\n", env)
if !skipComments {
fmt.Printf("# Datacenter (%s) Specific Vars:\n", env)
}
for k, v := range config.Environments[env].Dcs[dc].Vars {
fmt.Printf("export %s=%q\n", k, v)
}

fmt.Printf("# Datacenter (%s) Specific Secrets:\n", env)
if !skipComments {
fmt.Printf("# Datacenter (%s) Specific Secrets:\n", env)
}

for k, path := range config.Environments[env].Dcs[dc].Secrets {
secret, err := GetVaultSecret(path)
if err == nil {
fmt.Printf("export %s=%q # %s\n", k, secret.Data["value"], path)
fmt.Printf("export %s=%q", k, secret.Data["value"])
if !skipComments {
fmt.Printf(" # %s", path)
}
fmt.Println()
} else {
return cli.NewExitError(err.Error(), VaultErrorCode)
}
Expand Down

0 comments on commit 39ae0ea

Please sign in to comment.