This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
53 lines (44 loc) · 1.42 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
package main
import (
"github.com/riotkit-org/volume-syncing-controller/cmd"
"github.com/riotkit-org/volume-syncing-controller/pkg/helpers"
"os"
"strings"
)
func main() {
command := cmd.Main()
args := prepareArgs(os.Args)
if args != nil && len(args) > 1 && (args[1] == "sync-to-remote" || args[1] == "remote-to-local-sync") {
args = args[1:]
command.SetArgs(args)
}
err := command.Execute()
if err != nil {
os.Exit(1)
}
}
// prepareArgs Collects all REMOTE_xxx, ENCRYPTED_xxx environment variables and changes to "-p xxx=yyy" and "-e xxx=yyy"
//
// That makes easier to use in Kubernetes and in Docker
//
// e.g. REMOTE_ACCESS_KEY_ID=123456 - will convert to access_key_id=123456 under section [remote]
func prepareArgs(args []string) []string {
for _, env := range os.Environ() {
pair := strings.SplitN(env, "=", 2)
envName := pair[0]
value := helpers.GetEnvOrDefault(pair[0], "")
if strings.HasPrefix(envName, "REMOTE_") {
args = appendVar(args, "REMOTE_", "-p", envName, value.(string))
} else if strings.HasPrefix(envName, "ENCRYPTED_") {
args = appendVar(args, "ENCRYPTED_", "-e", envName, value.(string))
}
}
return args
}
func appendVar(args []string, prefix string, switchName string, envName string, value string) []string {
namePair := strings.SplitN(envName, prefix, 2)
name := strings.ToLower(namePair[1])
args = append(args, switchName)
args = append(args, name+"="+value)
return args
}