-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtls.go
More file actions
132 lines (115 loc) · 3.94 KB
/
tls.go
File metadata and controls
132 lines (115 loc) · 3.94 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package parser
import (
"fmt"
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/internal/completion"
"github.com/drycc/workflow-cli/internal/template"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// NewTLSCommand creates the TLS command
func NewTLSCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "tls",
Short: i18n.T("Manage TLS/SSL settings for applications"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.TLSInfo(app)
},
}
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("Application name"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
cmd.AddCommand(tlsInfoCommand(cmdr))
cmd.AddCommand(tlsIssuerCommand(cmdr))
cmd.AddCommand(tlsAutoCommand(cmdr))
cmd.AddCommand(tlsForceCommand(cmdr))
return cmd
}
func tlsInfoCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "info",
Example: "drycc tls info",
Short: i18n.T("View TLS settings information"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.TLSInfo(app)
},
}
return cmd
}
func tlsForceCommand(cmdr *commands.DryccCmd) *cobra.Command {
tlsActionCompletion := completion.TlsActionCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "force <action>",
Example: template.CustomExample(
"drycc tls force enable",
map[string]string{
"<action>": i18n.T("Action to perform, 'enable' or 'disable'"),
},
),
Args: cobra.ExactArgs(1),
ValidArgs: []string{"enable", "disable"},
Short: i18n.T("Force TLS settings to HTTPS-only redirection"),
ValidArgsFunction: tlsActionCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
action := args[0]
if action == "enable" {
return cmdr.TLSForceEnable(app)
} else if action == "disable" {
return cmdr.TLSForceDisable(app)
}
return fmt.Errorf("invalid action: %s, please use 'enable' or 'disable'", action)
},
}
return cmd
}
func tlsAutoCommand(cmdr *commands.DryccCmd) *cobra.Command {
tlsActionCompletion := completion.TlsActionCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "auto <action>",
Example: template.CustomExample(
"drycc tls auto enable",
map[string]string{
"<action>": i18n.T("Action to perform, 'enable' or 'disable'"),
},
),
Args: cobra.ExactArgs(1),
ValidArgs: []string{"enable", "disable"},
Short: i18n.T("Automatic certificate management"),
ValidArgsFunction: tlsActionCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
action := args[0]
if action == "enable" {
return cmdr.TLSAutoEnable(app)
} else if action == "disable" {
return cmdr.TLSAutoDisable(app)
}
return fmt.Errorf("invalid action: %s, please use 'enable' or 'disable'", action)
},
}
return cmd
}
func tlsIssuerCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
app string
email string
server string
keyID string
keySecret string
}
cmd := &cobra.Command{
Use: "issuer",
Short: i18n.T("Configure automatic certificate management issuer details"),
RunE: func(cmd *cobra.Command, args []string) error {
return cmdr.TLSAutoIssuer(app, flags.email, flags.server, flags.keyID, flags.keySecret)
},
}
cmd.Flags().StringVar(&flags.email, "email", "", i18n.T("ACME account email"))
cmd.Flags().StringVar(&flags.server, "server", "", i18n.T("ACME server URL"))
cmd.Flags().StringVar(&flags.keyID, "key-id", "", i18n.T("CA key ID"))
cmd.Flags().StringVar(&flags.keySecret, "key-secret", "", i18n.T("CA key secret"))
must_flags := []string{"email", "server", "key-id", "key-secret"}
for _, must_flag := range must_flags {
cmd.MarkFlagRequired(must_flag)
}
return cmd
}