-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
107 lines (97 loc) · 3.81 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"log"
"math/rand"
"os"
"os/signal"
"strings"
"syscall"
"time"
"golang.org/x/crypto/ssh/terminal"
"code.cloudfoundry.org/cli/plugin"
"github.com/alphagov/paas-cf-conduit/logging"
"github.com/spf13/cobra"
)
var (
NonInteractive bool
ConduitNoDelete bool
ConduitExistingApp bool
ConduitReuse bool
ConduitAppName string
ConduitOrg string
ConduitSpace string
ConduitLocalPort int64
ApiEndpoint string
ApiToken string
ApiInsecure bool
RawBindParameters string
CipherSuites []string
MinTLSVersion string
shutdown chan struct{}
)
func init() {
shutdown = make(chan struct{})
go func() {
sig := make(chan os.Signal, 3)
signal.Notify(sig, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGHUP)
<-sig
close(shutdown)
for range sig {
log.Println("...shutting down")
}
}()
}
func GenerateRandomString(length int) string {
seed := rand.NewSource(time.Now().UnixNano())
generator := rand.New(seed)
bytes := make([]byte, length)
for i := 0; i < length; i++ {
r := generator.Intn(36)
if r <= 25 {
bytes[i] = byte(97 + r) // a = 97 and z = 97+25,
} else {
bytes[i] = byte(22 + r) // 0 = 22+26 and 9 = 22+36
}
}
return string(bytes)
}
func main() {
if terminal.IsTerminal(int(os.Stdout.Fd())) && terminal.IsTerminal(int(os.Stderr.Fd())) {
NonInteractive = false
} else {
NonInteractive = true
}
cmd := &cobra.Command{Use: "cf"}
cmd.PersistentFlags().BoolVarP(&logging.Verbose, "verbose", "", false, "verbose output")
cmd.PersistentFlags().BoolVarP(&NonInteractive, "no-interactive", "", NonInteractive, "disable progress indicator and status output")
cmd.PersistentFlags().StringVarP(&ConduitOrg, "org", "o", "", "target org (defaults to currently targeted org)")
cmd.PersistentFlags().StringVarP(&ConduitSpace, "space", "s", "", "target space (defaults to currently targeted space)")
cmd.PersistentFlags().BoolVarP(&ConduitExistingApp, "existing-app", "e", false, "use an existing app (named by --app-name) instead of creating one")
cmd.PersistentFlags().BoolVarP(&ConduitNoDelete, "no-delete", "k", false, "don't delete app on conduit shutdown (implied by --existing-app)")
cmd.PersistentFlags().BoolVarP(&ConduitReuse, "reuse", "r", false, "deprecated alias for --no-delete")
cmd.PersistentFlags().MarkDeprecated("reuse", "please use --no-delete instead")
cmd.PersistentFlags().MarkHidden("reuse")
cmd.PersistentFlags().StringVarP(&ConduitAppName, "app-name", "n", "", "app name to use for tunnelling app (must not exist unless --existing-app is used)")
cmd.PersistentFlags().Int64VarP(&ConduitLocalPort, "local-port", "p", 7080, "start selecting local ports from")
cmd.PersistentFlags().StringVar(&ApiEndpoint, "endpoint", "", "set API endpoint")
cmd.PersistentFlags().MarkHidden("endpoint")
cmd.PersistentFlags().StringVar(&ApiToken, "token", "", "set API token")
cmd.PersistentFlags().MarkHidden("token")
cmd.PersistentFlags().BoolVar(&ApiInsecure, "insecure", false, "allow insecure API endpoint")
cmd.PersistentFlags().MarkHidden("insecure")
cmd.PersistentFlags().StringVarP(&RawBindParameters, "bind-parameters", "c", "{}", "bind parameters in JSON format")
cmd.PersistentFlags().StringSliceVar(&CipherSuites, "cipher-suites", []string{}, "list of cipher suites to use")
cmd.PersistentFlags().StringVar(&MinTLSVersion, "minimum-tls-version", "", "set minimum TLS version (e.g. TLS13)")
cmd.AddCommand(ConnectService)
cmd.AddCommand(Uninstall)
if len(CipherSuites) == 0 && os.Getenv("CF_CONDUIT_CIPHERSUITES") != "" {
CipherSuites = strings.Split(os.Getenv("CF_CONDUIT_CIPHERSUITES"), ",")
}
if MinTLSVersion == "" {
MinTLSVersion = "TLS12"
if os.Getenv("CF_CONDUIT_MIN_TLS_VERSION") != "" {
MinTLSVersion = os.Getenv("CF_CONDUIT_MIN_TLS_VERSION")
}
}
plugin.Start(&Plugin{cmd})
}