-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (59 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"github.com/ssst0n3/awesome_libs/awesome_error"
"github.com/ssst0n3/awesome_libs/secret"
"github.com/ssst0n3/docker_secret/cert"
"github.com/ssst0n3/docker_secret/lib"
"os"
"strconv"
"strings"
)
const (
EnvSecret = "SECRET"
EnvDirSecret = "DIR_SECRET"
EnvDevelopment = "DEVELOPMENT"
)
var (
Secret []string
Development bool
DirSecret string
)
func GetEnv() {
var err error
envSecret := os.Getenv(EnvSecret)
Secret = strings.Split(envSecret, ",")
DirSecret = os.Getenv(EnvDirSecret)
envDevelopment := os.Getenv(EnvDevelopment)
Development, err = strconv.ParseBool(envDevelopment)
if err != nil {
awesome_error.CheckWarning(err)
Development = false
}
}
func main() {
GetEnv()
for _, e := range Secret {
if strings.HasPrefix(e, "CERT_") {
certName := cert.ParseEnv(e)
awesome_error.CheckFatal(cert.LoadCertificate(certName))
} else {
_, _, err := secret.LoadKey(e)
awesome_error.CheckFatal(err)
}
}
// COPY all secrets into /tmp/secret
if Development {
var sourceFilenameList []string
for _, e := range Secret {
if strings.HasPrefix(e, "CERT_") {
caFileName, keyFileName := cert.CertificateFileName(cert.ParseEnv(e))
sourceFilenameList = append(sourceFilenameList, caFileName)
sourceFilenameList = append(sourceFilenameList, keyFileName)
} else {
sourceFilenameList = append(sourceFilenameList, e)
}
}
awesome_error.CheckFatal(os.Chmod("/tmp/secret", 0777))
awesome_error.CheckFatal(lib.CopyFiles(sourceFilenameList, DirSecret, "/tmp/secret", 0777))
}
}