Skip to content

Commit 802494f

Browse files
committed
issuer -> provisioner | Add flags.FirstStringOf
- FirstStringOf returns value of first defined flag in input list
1 parent 1c37ca9 commit 802494f

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

flags/flags.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,21 @@ func parseCaURL(ctx *cli.Context, caURL string) (string, error) {
670670

671671
return fmt.Sprintf("%s://%s", u.Scheme, u.Host), nil
672672
}
673+
674+
// FirstStringOf returns the value of the first defined flag from the input list.
675+
// If no defined flags, returns first flag with non-empty default value.
676+
func FirstStringOf(ctx *cli.Context, flags ...string) string {
677+
// Return first defined flag.
678+
for _, f := range flags {
679+
if ctx.IsSet(f) {
680+
return ctx.String(f)
681+
}
682+
}
683+
// Return first non-empty, default, flag value.
684+
for _, f := range flags {
685+
if val := ctx.String(f); val != "" {
686+
return val
687+
}
688+
}
689+
return ""
690+
}

utils/cautils/bootstrap.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type bootstrapAPIResponse struct {
2828
CaURL string `json:"url"`
2929
Fingerprint string `json:"fingerprint"`
3030
RedirectURL string `json:"redirect-url"`
31-
Issuer string `json:"issuer"`
32-
MinPasswordLength int `json:"min-password-length"`
31+
Provisioner string `json:"issuer,omitempty"`
32+
MinPasswordLength int `json:"min-password-length,omitempty"`
3333
}
3434

3535
// UseContext returns true if contexts should be used, false otherwise.
@@ -57,13 +57,13 @@ type bootstrapOption func(bc *bootstrapContext)
5757
type bootstrapContext struct {
5858
defaultContextName string
5959
redirectURL string
60-
issuer string
60+
provisioner string
6161
minPasswordLength int
6262
}
6363

64-
func withIssuer(issuer string) bootstrapOption {
64+
func withProvisioner(issuer string) bootstrapOption {
6565
return func(bc *bootstrapContext) {
66-
bc.issuer = issuer
66+
bc.provisioner = issuer
6767
}
6868
}
6969

@@ -89,8 +89,8 @@ type bootstrapConfig struct {
8989
CA string `json:"ca-url"`
9090
Fingerprint string `json:"fingerprint"`
9191
Root string `json:"root"`
92-
Redirect string `json:"redirect-url"`
93-
Issuer string `json:"issuer,omitempty"`
92+
Redirect string `json:"redirect-url,omitempty"`
93+
Provisioner string `json:"provisioner,omitempty"`
9494
MinPasswordLength int `json:"min-password-length,omitempty"`
9595
}
9696

@@ -175,8 +175,8 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt
175175
if bc.minPasswordLength > 0 {
176176
bootConf.MinPasswordLength = bc.minPasswordLength
177177
}
178-
if bc.issuer != "" {
179-
bootConf.Issuer = bc.issuer
178+
if bc.provisioner != "" {
179+
bootConf.Provisioner = bc.provisioner
180180
}
181181
b, err := json.MarshalIndent(bootConf, "", " ")
182182
if err != nil {
@@ -283,8 +283,8 @@ func BootstrapTeamAuthority(ctx *cli.Context, team, teamAuthority string) error
283283
withDefaultContextValues(teamAuthority + "." + team),
284284
withRedirectURL(r.RedirectURL),
285285
}
286-
if r.Issuer != "" {
287-
bootOpts = append(bootOpts, withIssuer(r.Issuer))
286+
if r.Provisioner != "" {
287+
bootOpts = append(bootOpts, withProvisioner(r.Provisioner))
288288
}
289289
if r.MinPasswordLength > 0 {
290290
bootOpts = append(bootOpts, withMinPasswordLength(r.MinPasswordLength))

utils/cautils/token_flow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func OfflineTokenFlow(ctx *cli.Context, typ int, subject string, sans []string,
212212
}
213213

214214
kid := ctx.String("kid")
215-
issuer := ctx.String("issuer")
215+
issuer := flags.FirstOf(ctx, "issuer", "provisioner")
216216

217217
// Require issuer and keyFile if ca.json does not exists.
218218
// kid can be passed or created using jwk.Thumbprint.
@@ -326,7 +326,7 @@ func provisionerPrompt(ctx *cli.Context, provisioners provisioner.List) (provisi
326326
}
327327

328328
// Filter by issuer (provisioner name)
329-
if issuer := ctx.String("issuer"); issuer != "" {
329+
if issuer := flags.FirstStringOf(ctx, "issuer", "provisioner"); issuer != "" {
330330
provisioners = provisionerFilter(provisioners, func(p provisioner.Interface) bool {
331331
return p.GetName() == issuer
332332
})

0 commit comments

Comments
 (0)