This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (57 loc) · 1.37 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
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"os/signal"
"time"
)
// exit code on interrupt
const exitCodeInterrupt = 2
// default global timeout value
var timeout = flag.Uint("timeout", 120, "timeout in seconds")
func main() {
flag.Parse()
// handle ^C interrupt signals gracefully
ctx, cancel := context.WithDeadline(context.Background(),
time.Now().Add(time.Duration(*timeout)*time.Second))
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt)
defer func() {
signal.Stop(signalChan)
cancel()
}()
go func() {
select {
case <-signalChan:
log.Println("exiting. ^C again to force.")
cancel()
case <-ctx.Done():
}
<-signalChan
os.Exit(exitCodeInterrupt)
}()
// get Lagoon project/environment build variables from process environment
buildVars, err := LagoonBuildVars()
if err != nil {
log.Fatalf("couldn't get Lagoon build variables: %v", err)
}
// get variables from any configured secret stores
merged, err := MergeSecrets([]SecretStore{
&MockBackend{ctx: ctx},
&AWSSecretsManager{ctx: ctx},
&GoogleSecretManager{ctx: ctx},
}, buildVars)
if err != nil {
log.Fatalf("couldn't merge secrets: %v", err)
}
// print JSON-formatted variables to stdout
output, err := json.Marshal(merged)
if err != nil {
log.Fatalf("couldn't marshal JSON: %v", err)
}
fmt.Println(string(output))
}