-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathpath.go
More file actions
107 lines (91 loc) · 2.27 KB
/
path.go
File metadata and controls
107 lines (91 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package path
import (
"fmt"
"github.com/urfave/cli"
"github.com/smallstep/cli-utils/command"
"github.com/smallstep/cli-utils/step"
)
func init() {
cmd := cli.Command{
Name: "path",
Usage: "print the configured step path and exit",
UsageText: "**step path** [**--base**] [**--profile**]",
Description: `**step path** command prints the configured step path and exits.
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 {
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
}),
}
command.Register(cmd)
}