forked from TrueCloudLab/certificates
update the help and usage information
This commit is contained in:
parent
f6546f160f
commit
95d4d9c4c1
2 changed files with 195 additions and 54 deletions
29
Gopkg.lock
generated
29
Gopkg.lock
generated
|
@ -123,6 +123,22 @@
|
||||||
revision = "15d26544def341f036c5f8dca987a4cbe575032c"
|
revision = "15d26544def341f036c5f8dca987a4cbe575032c"
|
||||||
version = "v1.2.1"
|
version = "v1.2.1"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:8baa3b16f20963c54e296627ea1dabfd79d1b486f81baf8759e99d73bddf2687"
|
||||||
|
name = "github.com/samfoo/ansi"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "b6bd2ded7189ce35bc02233b554eb56a5146af73"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:def689e73e9252f6f7fe66834a76751a41b767e03daab299e607e7226c58a855"
|
||||||
|
name = "github.com/shurcooL/sanitized_anchor_name"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "86672fcb3f950f35f2e675df2240550f2a50762f"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:3f53e9e4dfbb664cd62940c9c4b65a2171c66acd0b7621a1a6b8e78513525a52"
|
digest = "1:3f53e9e4dfbb664cd62940c9c4b65a2171c66acd0b7621a1a6b8e78513525a52"
|
||||||
name = "github.com/sirupsen/logrus"
|
name = "github.com/sirupsen/logrus"
|
||||||
|
@ -141,7 +157,7 @@
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "ca-commands"
|
branch = "ca-commands"
|
||||||
digest = "1:41e2386e08278707d5a20237c10a2c82f4658de64593fe070652c11bb3880812"
|
digest = "1:1731f58ec5ba2770296fb304504798c6f06059bd4645fd85f207de7be0b3add0"
|
||||||
name = "github.com/smallstep/cli"
|
name = "github.com/smallstep/cli"
|
||||||
packages = [
|
packages = [
|
||||||
"crypto/keys",
|
"crypto/keys",
|
||||||
|
@ -151,11 +167,13 @@
|
||||||
"crypto/x509util",
|
"crypto/x509util",
|
||||||
"errs",
|
"errs",
|
||||||
"jose",
|
"jose",
|
||||||
|
"pkg/blackfriday",
|
||||||
"pkg/x509",
|
"pkg/x509",
|
||||||
|
"usage",
|
||||||
"utils",
|
"utils",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "e2cf66cdd8f458a28ed9c5a6efc78fcc5500bdd0"
|
revision = "f6b9a18d11bd82c79876b18e57cd475e87be5fcc"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -190,9 +208,11 @@
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:5afed8b82638da362e14321ec6175b96351226f6662707801a0ec740bfd29840"
|
digest = "1:acfafa29853fd970d5d5ac6ca3b7350b5aef5999196d32bb9b049e21c8caf726"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = [
|
packages = [
|
||||||
|
"html",
|
||||||
|
"html/atom",
|
||||||
"http/httpguts",
|
"http/httpguts",
|
||||||
"http2",
|
"http2",
|
||||||
"http2/hpack",
|
"http2/hpack",
|
||||||
|
@ -295,9 +315,12 @@
|
||||||
"github.com/smallstep/cli/crypto/randutil",
|
"github.com/smallstep/cli/crypto/randutil",
|
||||||
"github.com/smallstep/cli/crypto/tlsutil",
|
"github.com/smallstep/cli/crypto/tlsutil",
|
||||||
"github.com/smallstep/cli/crypto/x509util",
|
"github.com/smallstep/cli/crypto/x509util",
|
||||||
|
"github.com/smallstep/cli/errs",
|
||||||
"github.com/smallstep/cli/jose",
|
"github.com/smallstep/cli/jose",
|
||||||
"github.com/smallstep/cli/pkg/x509",
|
"github.com/smallstep/cli/pkg/x509",
|
||||||
|
"github.com/smallstep/cli/usage",
|
||||||
"github.com/tsenart/deadcode",
|
"github.com/tsenart/deadcode",
|
||||||
|
"github.com/urfave/cli",
|
||||||
"golang.org/x/net/http2",
|
"golang.org/x/net/http2",
|
||||||
"gopkg.in/square/go-jose.v2",
|
"gopkg.in/square/go-jose.v2",
|
||||||
"gopkg.in/square/go-jose.v2/jwt",
|
"gopkg.in/square/go-jose.v2/jwt",
|
||||||
|
|
|
@ -2,12 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
@ -15,52 +16,138 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/smallstep/certificates/authority"
|
"github.com/smallstep/certificates/authority"
|
||||||
"github.com/smallstep/certificates/ca"
|
"github.com/smallstep/certificates/ca"
|
||||||
|
"github.com/smallstep/cli/errs"
|
||||||
|
"github.com/smallstep/cli/usage"
|
||||||
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is set by an LDFLAG at build time representing the git tag or commit
|
// commit and buildTime are filled in during build by the Makefile
|
||||||
// for the current release
|
var (
|
||||||
var Version = "N/A"
|
BuildTime = "N/A"
|
||||||
|
Version = "N/A"
|
||||||
|
)
|
||||||
|
|
||||||
// BuildTime is set by an LDFLAG at build time representing the timestamp at
|
// Version returns the current version of the binary.
|
||||||
// the time of build
|
func version() string {
|
||||||
var BuildTime = "N/A"
|
out := Version
|
||||||
|
if out == "N/A" {
|
||||||
func usage() {
|
out = "0000000-dev"
|
||||||
fmt.Fprintf(os.Stderr, "Usage: %s [options] <config.json>\n\n", path.Base(os.Args[0]))
|
}
|
||||||
flag.PrintDefaults()
|
return fmt.Sprintf("Smallstep CLI/%s (%s/%s)",
|
||||||
|
out, runtime.GOOS, runtime.GOARCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printVersion() {
|
// ReleaseDate returns the time of when the binary was built.
|
||||||
version, buildTime := Version, BuildTime
|
func releaseDate() string {
|
||||||
if version == "N/A" {
|
out := BuildTime
|
||||||
version = "0000000-dev"
|
if out == "N/A" {
|
||||||
|
out = time.Now().UTC().Format("2006-01-02 15:04 MST")
|
||||||
}
|
}
|
||||||
if buildTime == "N/A" {
|
|
||||||
buildTime = time.Now().UTC().Format("2006-01-02 15:04 MST")
|
return out
|
||||||
}
|
}
|
||||||
fmt.Printf("Smallstep CA/%s (%s/%s)\n", version, runtime.GOOS, runtime.GOARCH)
|
|
||||||
fmt.Printf("Release Date: %s\n", buildTime)
|
// Print version and release date.
|
||||||
|
func printFullVersion() {
|
||||||
|
fmt.Printf("%s\n", version())
|
||||||
|
fmt.Printf("Release Date: %s\n", releaseDate())
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var version bool
|
// Override global framework components
|
||||||
var configFile, passFile string
|
cli.VersionPrinter = func(c *cli.Context) {
|
||||||
flag.StringVar(&passFile, "password-file", "", "path to file containing a password")
|
printFullVersion()
|
||||||
flag.BoolVar(&version, "version", false, "print version and exit")
|
}
|
||||||
flag.Usage = usage
|
cli.AppHelpTemplate = usage.AppHelpTemplate
|
||||||
flag.Parse()
|
cli.SubcommandHelpTemplate = usage.SubcommandHelpTemplate
|
||||||
|
cli.CommandHelpTemplate = usage.CommandHelpTemplate
|
||||||
|
cli.HelpPrinter = usage.HelpPrinter
|
||||||
|
cli.FlagNamePrefixer = usage.FlagNamePrefixer
|
||||||
|
cli.FlagStringer = stringifyFlag
|
||||||
|
|
||||||
if version {
|
// Configure cli app
|
||||||
printVersion()
|
app := cli.NewApp()
|
||||||
os.Exit(0)
|
app.Name = "step-ca"
|
||||||
|
app.HelpName = "step-ca"
|
||||||
|
app.Version = version()
|
||||||
|
app.Usage = "an online certificate authority for secure automated certificate management"
|
||||||
|
app.UsageText = `**step-ca** <config> [**--password-file**=<file>] [**--version**]`
|
||||||
|
app.Description = `**step-ca** runs the Step Online Certificate Authority
|
||||||
|
(Step CA) using the given configuration.
|
||||||
|
|
||||||
|
See the README.md for more detailed configuration documentation.
|
||||||
|
|
||||||
|
## POSITIONAL ARGUMENTS
|
||||||
|
|
||||||
|
<config>
|
||||||
|
: File that configures the operation of the Step CA; this file is generated
|
||||||
|
when you initialize the Step CA using 'step ca init'
|
||||||
|
|
||||||
|
## EXIT CODES
|
||||||
|
|
||||||
|
This command will run indefinitely on success and return \>0 if any error occurs.
|
||||||
|
|
||||||
|
## EXAMPLES
|
||||||
|
|
||||||
|
These examples assume that you have already initialized your PKI by running
|
||||||
|
'step ca init'. If you have not completed this step please see the 'Getting Started'
|
||||||
|
section of the README.
|
||||||
|
|
||||||
|
Run the Step CA and prompt for password:
|
||||||
|
'''
|
||||||
|
$ step-ca $STEPPATH/config/ca.json
|
||||||
|
'''
|
||||||
|
|
||||||
|
Run the Step CA and read the password from a file - this is useful for
|
||||||
|
automating deployment:
|
||||||
|
'''
|
||||||
|
$ step-ca $STEPPATH/config/ca.json --password-file ./password.txt
|
||||||
|
'''`
|
||||||
|
app.Flags = append(app.Flags, []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "password-file",
|
||||||
|
Usage: `path to the <file> containing the password to decrypt the
|
||||||
|
intermediate private key.`,
|
||||||
|
},
|
||||||
|
}...)
|
||||||
|
app.Copyright = "(c) 2018 Smallstep Labs, Inc."
|
||||||
|
|
||||||
|
// All non-successful output should be written to stderr
|
||||||
|
app.Writer = os.Stdout
|
||||||
|
app.ErrWriter = os.Stderr
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
cli.Command{
|
||||||
|
Name: "version",
|
||||||
|
Usage: "Displays the current version of the cli",
|
||||||
|
// Command prints out the current version of the tool
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
printFullVersion()
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag.NArg() != 1 {
|
// Start the golang debug logger if environment variable is set.
|
||||||
flag.Usage()
|
// See https://golang.org/pkg/net/http/pprof/
|
||||||
os.Exit(1)
|
debugProfAddr := os.Getenv("STEP_PROF_ADDR")
|
||||||
|
if debugProfAddr != "" {
|
||||||
|
go func() {
|
||||||
|
log.Println(http.ListenAndServe(debugProfAddr, nil))
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
configFile = flag.Arg(0)
|
app.Action = func(ctx *cli.Context) error {
|
||||||
|
passFile := ctx.String("password-file")
|
||||||
|
|
||||||
|
// If zero cmd line args show help, if >1 cmd line args show error.
|
||||||
|
if ctx.NArg() == 0 {
|
||||||
|
return cli.ShowAppHelp(ctx)
|
||||||
|
}
|
||||||
|
if err := errs.NumberOfArguments(ctx, 1); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
configFile := ctx.Args().Get(0)
|
||||||
config, err := authority.LoadConfiguration(configFile)
|
config, err := authority.LoadConfiguration(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
@ -83,6 +170,17 @@ func main() {
|
||||||
if err = srv.Run(); err != nil && err != http.ErrServerClosed {
|
if err = srv.Run(); err != nil && err != http.ErrServerClosed {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
if os.Getenv("STEPDEBUG") == "1" {
|
||||||
|
fmt.Fprintf(os.Stderr, "%+v\n", err)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
}
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fatal writes the passed error on the standard error and exits with the exit
|
// fatal writes the passed error on the standard error and exits with the exit
|
||||||
|
@ -96,3 +194,23 @@ func fatal(err error) {
|
||||||
}
|
}
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flagValue(f cli.Flag) reflect.Value {
|
||||||
|
fv := reflect.ValueOf(f)
|
||||||
|
for fv.Kind() == reflect.Ptr {
|
||||||
|
fv = reflect.Indirect(fv)
|
||||||
|
}
|
||||||
|
return fv
|
||||||
|
}
|
||||||
|
|
||||||
|
var placeholderString = regexp.MustCompile(`<.*?>`)
|
||||||
|
|
||||||
|
func stringifyFlag(f cli.Flag) string {
|
||||||
|
fv := flagValue(f)
|
||||||
|
usage := fv.FieldByName("Usage").String()
|
||||||
|
placeholder := placeholderString.FindString(usage)
|
||||||
|
if placeholder == "" {
|
||||||
|
placeholder = "<value>"
|
||||||
|
}
|
||||||
|
return cli.FlagNamePrefixer(fv.FieldByName("Name").String(), placeholder) + "\t" + usage
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue