Skip to content

Commit 8a47353

Browse files
committed
Use ENCRYPT_KEY_BASE64 as alternative to ENCRYPT_KEY
1 parent 510a9f2 commit 8a47353

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
FROM golang:1.14 as builder
1+
FROM golang:1.17 as builder
22

33
ARG MAKE_TARGET="test build"
44

55
WORKDIR "/code"
66
ADD . "/code"
77
RUN make BINARY=spring-config-decryptor ${MAKE_TARGET}
88

9-
FROM alpine:3.12
9+
FROM scratch
1010
COPY --from=builder /code/spring-config-decryptor /spring-config-decryptor
1111
ENTRYPOINT ["/spring-config-decryptor"]

Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.14 as builder
1+
FROM golang:1.17 as builder
22

33
ARG GOOS=linux
44
ARG GOARCH=amd64

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.PHONY: clean build fmt test
44

5-
TAG ?= "v0.0.3"
5+
TAG ?= "v0.0.4"
66

77
BUILD_FLAGS ?=
88
BINARY ?= spring-config-decryptor

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ The secret values are base64 encoded and start with `{cipher}` prefix.
1515

1616
Linux
1717

18-
curl -Ls https://github.com/grepplabs/spring-config-decryptor/releases/download/v0.0.2/spring-config-decryptor-v0.0.2-linux-amd64.tar.gz | tar xz
18+
curl -Ls https://github.com/grepplabs/spring-config-decryptor/releases/download/v0.0.4/spring-config-decryptor-v0.0.4-linux-amd64.tar.gz | tar xz
1919

2020
macOS
2121

22-
curl -Ls https://github.com/grepplabs/spring-config-decryptor/releases/download/v0.0.2/spring-config-decryptor-v0.0.2-darwin-amd64.tar.gz | tar xz
22+
curl -Ls https://github.com/grepplabs/spring-config-decryptor/releases/download/v0.0.4/spring-config-decryptor-v0.0.4-darwin-amd64.tar.gz | tar xz
2323

2424
windows
2525

26-
curl -Ls https://github.com/grepplabs/spring-config-decryptor/releases/download/v0.0.2/spring-config-decryptor-v0.0.2-windows-amd64.tar.gz | tar xz
26+
curl -Ls https://github.com/grepplabs/spring-config-decryptor/releases/download/v0.0.4/spring-config-decryptor-v0.0.4-windows-amd64.tar.gz | tar xz
2727

2828

2929
2. Move the binary in to your PATH.
@@ -62,7 +62,7 @@ The secret values are base64 encoded and start with `{cipher}` prefix.
6262
-f string
6363
The file name to decrypt. Use '-' for stdin. (default "-")
6464
-k string
65-
The file with RSA private key. If empty the key is read from environment variable ENCRYPT_KEY
65+
The file with RSA private key. If empty the key is read from environment variable ENCRYPT_KEY / ENCRYPT_KEY_BASE64
6666
-o string
6767
The file to write the result to. Use '-' for stdout. (default "-")
6868

main.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/base64"
45
"flag"
56
"fmt"
67
"io"
@@ -11,13 +12,14 @@ import (
1112
)
1213

1314
const (
14-
defaultEnvEncryptKey = "ENCRYPT_KEY"
15+
defaultEnvEncryptKey = "ENCRYPT_KEY"
16+
defaultEnvEncryptKeyBase64 = "ENCRYPT_KEY_BASE64"
1517
)
1618

1719
var (
1820
inputFile = flag.String("f", "-", `The file name to decrypt. Use '-' for stdin.`)
1921
outputFile = flag.String("o", "-", `The file to write the result to. Use '-' for stdout.`)
20-
keyFile = flag.String("k", "", fmt.Sprintf("The file with RSA private key. If empty the key is read from environment variable %s ", defaultEnvEncryptKey))
22+
keyFile = flag.String("k", "", fmt.Sprintf("The file with RSA private key. If empty the key is read from environment variable %s / %s", defaultEnvEncryptKey, defaultEnvEncryptKeyBase64))
2123
)
2224

2325
func main() {
@@ -33,12 +35,15 @@ func main() {
3335
if err != nil {
3436
exitOnError("key file reading error: %v", err)
3537
}
36-
} else {
37-
value := os.Getenv(defaultEnvEncryptKey)
38-
if value == "" {
39-
exitOnError("missing private key error, provide key in the env variable %s or use -k flag", defaultEnvEncryptKey)
40-
}
38+
} else if value := os.Getenv(defaultEnvEncryptKey); value != "" {
4139
key = []byte(value)
40+
} else if value = os.Getenv(defaultEnvEncryptKeyBase64); value != "" {
41+
key, err = base64.StdEncoding.DecodeString(value)
42+
if err != nil {
43+
exitOnError("key file reading error: %v", err)
44+
}
45+
} else {
46+
exitOnError("missing private key error, provide key in the env variable %s / %s or use -k flag", defaultEnvEncryptKey, defaultEnvEncryptKeyBase64)
4247
}
4348

4449
var input io.Reader

0 commit comments

Comments
 (0)