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

Initial step path contexts commit

- move config and command packages to cli-utils
This commit is contained in:
max furman
2021-07-22 23:26:02 -07:00
parent deb91a4ac4
commit 860c213b97
59 changed files with 327 additions and 216 deletions

View File

@@ -3,21 +3,101 @@ package path
import (
"fmt"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/config"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/step"
)
func init() {
cmd := cli.Command{
Name: "path",
Usage: "print the configured step path and exit",
UsageText: "step path",
UsageText: "**step path** [**--base**] [**--profile**]",
Description: `**step path** command prints the configured step path and exits.
The default step path of $HOME/.step can be overridden with the **STEPPATH** environment variable.`,
When using contexts to manage 'step-ca' environments, this command will return
the current authority path. If no current context is configured this command the
default step path of $HOME/.step, which can be overridden with the **STEPPATH**
environment variable.
## EXAMPLES
Get the path with no current context configured:
'''
$ step path
/Users/max/.step
'''
Get the path with no current context and environment variable STEPPATH overriding the default:
'''
$ export STEPPATH=/tmp/step
$ step path
/tmp/step
'''
Get the path with a current context (configured at $STEPPATH/current-context.json):
'''
$ cat $(step path --base)/current-context.json
{"context": "machine.step-internal.net"}
$ step path
/Users/max/.step/authorities/machine.step-internal.net
'''
Get the base path:
'''
$ step path --base
/Users/max/.step
'''
Get the base path with environment variable STEPPATH overriding the default:
'''
$ export STEPPATH=/tmp/step
$ step path --base
/tmp/step
'''
Get the path of the current profile:
'''
$ cat $(step path --base)/current-context.json
{"context": "ca.acme.net"}
$ cat $(step path --base)/contexts.json
{
"ca.beta.net": {
"profile": "beta-corp",
"authority": "machine.beta.net"
},
"ca.acme.net": {
"profile": "example-corp",
"authority": "machine.acme.net"
}
}
$ step path --profile
/Users/max/.step/profiles/beta-corp
'''
`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "base",
Usage: "Return the base of the step path",
},
cli.BoolFlag{
Name: "profile",
Usage: "Return the base path of the currently configured default profile",
},
},
Action: cli.ActionFunc(func(ctx *cli.Context) error {
fmt.Println(config.StepPath())
if ctx.Bool("base") {
fmt.Println(step.BasePath())
return nil
}
if ctx.Bool("profile") {
fmt.Println(step.ProfilePath())
return nil
}
fmt.Println(step.Path())
return nil
}),
}