MCPcopy
hub / github.com/smallstep/cli / loginAction

Function loginAction

command/ssh/login.go:114–302  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

112}
113
114func loginAction(ctx *cli.Context) error {
115 if err := errs.MinMaxNumberOfArguments(ctx, 0, 1); err != nil {
116 return err
117 }
118
119 // Arguments
120 subject := ctx.Args().First()
121 if subject == "" {
122 subject = ctx.String("identity")
123 }
124
125 principals := ctx.StringSlice("principal")
126 if subject != "" && len(principals) == 0 {
127 principals = []string{subject}
128 }
129
130 comment := ctx.String("comment")
131 if comment == "" {
132 comment = subject
133 }
134
135 // Flags
136 token := ctx.String("token")
137 isAddUser := ctx.Bool("add-user")
138 force := ctx.Bool("force")
139 insecure := ctx.Bool("insecure")
140 validAfter, validBefore, err := flags.ParseTimeDuration(ctx)
141 if err != nil {
142 return err
143 }
144 templateData, err := flags.ParseTemplateData(ctx)
145 if err != nil {
146 return err
147 }
148
149 kty, curve, size, err := utils.GetKeyDetailsFromCLI(ctx, insecure, "kty", "curve", "size")
150 if err != nil {
151 return err
152 }
153
154 // Connect to the SSH agent.
155 // step ssh login requires an ssh agent.
156 agent, err := sshutil.DialAgent()
157 if err != nil {
158 return err
159 }
160
161 // Check for a previous key signed by the CA.
162 if !force {
163 client, err := cautils.NewClient(ctx)
164 if err != nil {
165 return err
166 }
167 opts := []sshutil.AgentOption{
168 sshutil.WithRemoveExpiredCerts(time.Now()),
169 }
170 if roots, err := client.SSHRoots(); err == nil && len(roots.UserKeys) > 0 {
171 userKeys := make([]ssh.PublicKey, len(roots.UserKeys))

Callers

nothing calls this directly

Calls 15

GenerateSSHTokenMethod · 0.95
GetClientMethod · 0.95
ParseTimeDurationFunction · 0.92
ParseTemplateDataFunction · 0.92
GetKeyDetailsFromCLIFunction · 0.92
DialAgentFunction · 0.92
NewClientFunction · 0.92
WithRemoveExpiredCertsFunction · 0.92
WithSignatureKeyFunction · 0.92
NewCertificateFlowFunction · 0.92
tokenEmailFunction · 0.85
tokenSubjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…