Skip to content

Commit 02057b2

Browse files
committed
Merge pull request #28 from Comcast/kv2updates
Major Refactor & KV2 Support #minor
2 parents 971813a + d66c8c2 commit 02057b2

16 files changed

+967
-521
lines changed

.github/workflows/tag.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
body: GitHub Actions Release
2727
draft: false
2828
prerelease: false
29-
- name: Set up Go 1.16
29+
- name: Set up Go 1.21
3030
uses: actions/setup-go@v1
3131
with:
32-
go-version: 1.16
32+
go-version: 1.21
3333
id: go
3434
- name: Check out new tag into the Go module directory
3535
uses: actions/checkout@v2

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ PROJECT_NAME := buildenv
66
all: clean build-deps build
77

88
build-deps:
9-
go get github.com/mitchellh/gox
10-
go get github.com/aktau/github-release
9+
go install github.com/mitchellh/gox@latest
1110

1211
build:
1312
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)"

README.md

+59-43
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,74 @@
11
buildenv
22
========
33

4-
A tool for generating environment exports from a YAML file. _Now with vault integration!_
4+
A tool for generating environment exports from a YAML file. Variables can be set in plain test, or by specifying vault key-value (version 2) paths and keys (`kv_secrets`) or the older generic / kv paths (`secrets`) where the key name "value" is assumed.
55

66
Usage
77
-----
88

99
Given a `variables.yml` file like this:
1010
```yaml
1111
---
12-
vars:
13-
GLOBAL: "global"
14-
15-
secrets:
16-
SECRET_TEST: "secret/test"
17-
18-
environments:
19-
stage:
20-
vars:
21-
ENVIRONMENT: "stage"
22-
23-
secrets:
24-
ANOTHER_SECRET: "secret/test2"
25-
26-
dcs:
27-
ndc_one:
28-
secrets:
29-
YET_ANOTHER_SECRET: "secret/test3"
30-
vars:
31-
DC: "one"
32-
33-
ndc_two:
34-
secrets:
35-
YET_ANOTHER_SECRET: "secret/test3"
36-
vars:
37-
DC: "one"
12+
vars:
13+
GLOBAL: "global"
14+
15+
secrets:
16+
GENERIC_SECRET: "gen/test"
17+
KV_SECRET: "old/test"
18+
KV2_SECRET: "secret/oldstyle"
19+
20+
kv_secrets:
21+
- path: "secret/test"
22+
vars:
23+
KV2_ONE: "one"
24+
KV2_TWO: "two"
25+
- path: "old/test"
26+
vars:
27+
KV1: "value"
28+
- path: "gen/test"
29+
vars:
30+
KV_GENERIC: "value"
31+
32+
environments:
33+
stage:
34+
vars:
35+
ENVIRONMENT: "stage"
36+
37+
secrets:
38+
ANOTHER_SECRET: "secret/oldstyle"
39+
40+
dcs:
41+
ndc_one:
42+
vars:
43+
DC: "one"
44+
kv_secrets:
45+
- path: "old/test"
46+
vars:
47+
KV2_THREE: "three"
3848
```
3949
4050
Output would look like this:
4151
4252
```
43-
% buildenv -e stage -d ndc_one
44-
# Setting Variables for:
45-
# Environment: stage
46-
# Datacenter: ndc_one
47-
# Global Vars:
53+
% buildenv -c -e stage -d ndc_one
54+
# Global Variables
4855
export GLOBAL="global"
49-
# Global Secrets:
50-
export SECRET_TEST="It Works" # secret/test
51-
# Environment (stage) Vars:
56+
export KV2_ONE="1" # Path: secret/test, Key: one
57+
export KV2_TWO="2" # Path: secret/test, Key: two
58+
export KV1="old" # Path: old/test, Key: value
59+
export KV_GENERIC="generic" # Path: gen/test, Key: value
60+
export GENERIC_SECRET="generic" # Path: gen/test, Key: value
61+
export KV_SECRET="old" # Path: old/test, Key: value
62+
export KV2_SECRET="default" # Path: secret/oldstyle, Key: value
63+
# Environment: stage
5264
export ENVIRONMENT="stage"
53-
# Environment (stage) Secrets:
54-
export ANOTHER_SECRET="It Still Works" # secret/test
55-
# Datacenter (ndc_one) Specific Vars:
56-
YET_ANOTHER_SECRET: "secretpassword"
65+
export ANOTHER_SECRET="default" # Path: secret/oldstyle, Key: value
66+
# Datacenter: ndc_one
5767
export DC="one"
68+
export KV2_THREE="3" # Path: old/test, Key: three
5869
```
5970

60-
*A Note About Vault:* If you have `secrets` defined in either the global or environment scope, it's a mapping from environment variable to the path in vault. Buildenv uses all the standard vault environment variables to communicate with vault (`VAULT_ADDR` and `VAULT_TOKEN` being the two you're most likely to use.)
71+
*A Note About Vault:* If you have `secrets` defined in either the global or environment scope, it's a mapping from environment variable to the path in vault. Buildenv uses all the standard vault environment variables to communicate with vault (`VAULT_ADDR` and `VAULT_TOKEN` being the two you're most likely to use.) You can find the complete list [in the vault client docs](https://pkg.go.dev/github.com/hashicorp/vault-client-go@v0.4.2#WithEnvironment).
6172

6273
Running on Linux or in Docker container
6374
----------
@@ -73,8 +84,13 @@ To test with vault, run:
7384
docker-compose up vault -d
7485
export VAULT_ADDR="http://localhost:8200"
7586
export VAULT_TOKEN="test"
76-
vault write secret/test "value=It Works"
77-
vault write secret/test2 "value=It Still Works"
78-
buildenv -e stage
87+
vault secrets enable -path gen generic
88+
vault secrets enable -version=1 -path old kv
89+
vault kv put secret/test "one=1" "two=2"
90+
vault kv put secret/oldstyle "value=default"
91+
vault kv put old/test "value=old" "three=3"
92+
vault write gen/test "value=generic"
93+
94+
buildenv -c -e stage -d ndc_one
7995
docker-compose down
8096
```

0 commit comments

Comments
 (0)