-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathflags.go
173 lines (164 loc) · 5.36 KB
/
flags.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// SPDX-License-Identifier: Apache-2.0
package scm
import (
"context"
"fmt"
"strings"
"github.com/urfave/cli/v3"
"github.com/go-vela/server/constants"
)
// Flags represents all supported command line
// interface (CLI) flags for the scm.
//
// https://pkg.go.dev/github.com/urfave/cli?tab=doc#Flag
var Flags = []cli.Flag{
// SCM Flags
&cli.StringFlag{
Name: "scm.driver",
Usage: "driver to be used for the version control system",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_DRIVER"),
cli.EnvVar("SCM_DRIVER"),
cli.File("/vela/scm/driver"),
),
Value: constants.DriverGithub,
},
&cli.StringFlag{
Name: "scm.addr",
Usage: "fully qualified url (<scheme>://<host>) for the version control system",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_ADDR"),
cli.EnvVar("SCM_ADDR"),
cli.File("/vela/scm/addr"),
),
Value: "https://github.com",
Action: func(_ context.Context, _ *cli.Command, v string) error {
if !strings.Contains(v, "://") {
return fmt.Errorf("scm address must be fully qualified (<scheme>://<host>)")
}
if strings.HasSuffix(v, "/") {
return fmt.Errorf("scm address must not have trailing slash")
}
return nil
},
},
&cli.StringFlag{
Name: "scm.client",
Usage: "OAuth client id from version control system",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_CLIENT"),
cli.EnvVar("SCM_CLIENT"),
cli.File("/vela/scm/client"),
),
Required: true,
},
&cli.StringFlag{
Name: "scm.secret",
Usage: "OAuth client secret from version control system",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_SECRET"),
cli.EnvVar("SCM_SECRET"),
cli.File("/vela/scm/secret"),
),
Required: true,
},
&cli.BoolFlag{
Name: "vela-disable-webhook-validation",
Usage: "determines whether or not webhook validation is disabled. useful for local development.",
Sources: cli.EnvVars("VELA_DISABLE_WEBHOOK_VALIDATION"),
Value: false,
},
&cli.StringFlag{
Name: "scm.context",
Usage: "context for commit status in version control system",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_CONTEXT"),
cli.EnvVar("SCM_CONTEXT"),
cli.File("/vela/scm/context"),
),
Value: "continuous-integration/vela",
},
&cli.StringSliceFlag{
Name: "scm.scopes",
Usage: "OAuth scopes to be used for the version control system",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_SCOPES"),
cli.EnvVar("SCM_SCOPES"),
cli.File("/vela/scm/scopes"),
),
Value: []string{"repo", "repo:status", "user:email", "read:user", "read:org"},
},
&cli.StringFlag{
Name: "scm.webhook.addr",
Usage: "Alternative or proxy server address as a fully qualified url (<scheme>://<host>). " +
"Use this when the Vela server address that the scm provider can send webhooks to " +
"differs from the server address the UI and oauth flows use, such as when the server " +
"is behind a Firewall or NAT, or when using something like ngrok to forward webhooks. " +
"(defaults to VELA_ADDR).",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_WEBHOOK_ADDR"),
cli.EnvVar("SCM_WEBHOOK_ADDR"),
cli.File("/vela/scm/webhook_addr"),
),
},
&cli.IntFlag{
Name: "scm.app.id",
Usage: "set ID for the SCM App integration (GitHub App)",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_APP_ID"),
cli.EnvVar("SCM_APP_ID"),
cli.File("/vela/scm/app_id"),
),
Action: func(_ context.Context, cmd *cli.Command, v int64) error {
if v > 0 {
if !cmd.Bool("vela-disable-webhook-validation") && cmd.String("scm.app.webhook-secret") == "" {
return fmt.Errorf("webhook-validation enabled and app ID provided but no app webhook secret is provided")
}
if cmd.String("scm.app.private-key") == "" && cmd.String("scm.app.private-key.path") == "" {
return fmt.Errorf("app ID provided but no app private key is provided")
}
if cmd.String("scm.app.private-key") != "" && cmd.String("scm.app.private-key.path") != "" {
return fmt.Errorf("app ID provided but both app private key and app private key path are provided")
}
}
return nil
},
},
&cli.StringFlag{
Name: "scm.app.private-key",
Usage: "set value of base64 encoded SCM App integration (GitHub App) private key",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_APP_PRIVATE_KEY"),
cli.EnvVar("SCM_APP_PRIVATE_KEY"),
cli.File("/vela/scm/app_private_key"),
),
},
&cli.StringFlag{
Name: "scm.app.private-key.path",
Usage: "set filepath to the SCM App integration (GitHub App) private key",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_APP_PRIVATE_KEY_PATH"),
cli.EnvVar("SCM_APP_PRIVATE_KEY_PATH"),
cli.File("/vela/scm/app_private_key_path"),
),
},
&cli.StringFlag{
Name: "scm.app.webhook-secret",
Usage: "set value of SCM App integration webhook secret",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_APP_WEBHOOK_SECRET"),
cli.EnvVar("SCM_APP_WEBHOOK_SECRET"),
cli.File("/vela/scm/app_webhook_secret"),
),
},
&cli.StringSliceFlag{
Name: "scm.app.permissions",
Usage: "SCM App integration (GitHub App) permissions to be used as the allowed set of possible installation token permissions",
Sources: cli.NewValueSourceChain(
cli.EnvVar("VELA_SCM_APP_PERMISSIONS"),
cli.EnvVar("SCM_APP_PERMISSIONS"),
cli.File("/vela/scm/app/permissions"),
),
Value: []string{"contents:read", "checks:write"},
},
}