diff --git a/command/ca/init.go b/command/ca/init.go index d70d0765..8528de4a 100644 --- a/command/ca/init.go +++ b/command/ca/init.go @@ -479,11 +479,11 @@ func initAction(ctx *cli.Context) (err error) { } ctxAuthority := ctx.String("authority") if ctxAuthority == "" { - ctxAuthority = dnsNames[0] + ctxAuthority = ctxName } ctxProfile := ctx.String("profile") if ctxProfile == "" { - ctxProfile = dnsNames[0] + ctxProfile = ctxName } if err := step.Contexts().Add(&step.Context{ Name: ctxName, diff --git a/utils/cautils/bootstrap.go b/utils/cautils/bootstrap.go index b344221a..d9dfcfcb 100644 --- a/utils/cautils/bootstrap.go +++ b/utils/cautils/bootstrap.go @@ -52,17 +52,13 @@ func WarnContext() { type bootstrapOption func(bc *bootstrapContext) type bootstrapContext struct { - defaultContextName string - defaultAuthorityName string - defaultProfileName string - redirectURL string + defaultContextName string + redirectURL string } func withDefaultContextValues(context, authority, profile string) bootstrapOption { return func(bc *bootstrapContext) { bc.defaultContextName = context - bc.defaultAuthorityName = authority - bc.defaultProfileName = profile } } @@ -97,30 +93,30 @@ func bootstrap(ctx *cli.Context, caURL, fingerprint string, opts ...bootstrapOpt } if UseContext(ctx) { - authority := ctx.String("authority") - if authority == "" { - authority = bc.defaultAuthorityName + ctxName := ctx.String("context") + if ctxName == "" { + ctxName = bc.defaultContextName } - context := ctx.String("context") - if context == "" { - context = bc.defaultContextName + ctxAuthority := ctx.String("authority") + if ctxAuthority == "" { + ctxAuthority = ctxName } - profile := ctx.String("profile") - if profile == "" { - profile = bc.defaultProfileName + ctxProfile := ctx.String("profile") + if ctxProfile == "" { + ctxProfile = ctxName } if err := step.Contexts().Add(&step.Context{ - Name: context, - Profile: profile, - Authority: authority, + Name: ctxName, + Profile: ctxProfile, + Authority: ctxAuthority, }); err != nil { return errors.Wrapf(err, "error adding context: '%s' - {authority: '%s', profile: '%s'}", - context, authority, profile) + ctxName, ctxAuthority, ctxProfile) } - if err := step.Contexts().SaveCurrent(context); err != nil { + if err := step.Contexts().SaveCurrent(ctxName); err != nil { return errors.Wrap(err, "error storing new default context") } - if err := step.Contexts().SetCurrent(context); err != nil { + if err := step.Contexts().SetCurrent(ctxName); err != nil { return errors.Wrap(err, "error setting context '%s'") } } else {