1
0
mirror of https://github.com/smallstep/cli.git synced 2025-08-07 16:02:54 +03:00

Add missing command step ssh check-host.

This commit is contained in:
Mariano Cano
2019-10-11 19:01:07 -07:00
committed by max furman
parent dd84d55f87
commit 11fca1cacf

65
command/ssh/checkHost.go Normal file
View File

@@ -0,0 +1,65 @@
package ssh
import (
"fmt"
"os"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
)
func checkHostCommand() cli.Command {
return cli.Command{
Name: "check-host",
Action: command.ActionFunc(checkHostAction),
Usage: "checks if a certificate has been issued for a host",
UsageText: `**step ssh check-host** <hostname>`,
Description: `**step ssh check-host** checks if a certificate has been issued for a host.
This command returns a zero exit status then the server exists, it will return 1
otherwise.
## POSITIONAL ARGUMENTS
<hostname>
: The hostname of the server to check.
## EXAMPLES
Check that internal.example.com exists:
'''
$ step ssh check-host internal.smallstep.com
'''`,
Flags: []cli.Flag{
flags.CaURL,
flags.Root,
flags.Offline,
flags.CaConfig,
},
}
}
func checkHostAction(ctx *cli.Context) error {
if err := errs.NumberOfArguments(ctx, 1); err != nil {
return err
}
client, err := cautils.NewClient(ctx)
if err != nil {
return err
}
resp, err := client.SSHCheckHost(ctx.Args().First())
if err != nil {
return err
}
fmt.Println(resp.Exists)
if !resp.Exists {
os.Exit(1)
}
return nil
}