1
0
mirror of https://github.com/smallstep/cli.git synced 2025-08-09 03:22:43 +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

@@ -12,18 +12,19 @@ import (
"time"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/command/version"
"github.com/smallstep/cli/config"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/usage"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/step"
// Enabled commands
_ "github.com/smallstep/cli/command/base64"
_ "github.com/smallstep/cli/command/beta"
_ "github.com/smallstep/cli/command/ca"
_ "github.com/smallstep/cli/command/certificate"
_ "github.com/smallstep/cli/command/context"
_ "github.com/smallstep/cli/command/crypto"
_ "github.com/smallstep/cli/command/fileserver"
_ "github.com/smallstep/cli/command/oauth"
@@ -48,8 +49,8 @@ var Version = "N/A"
var BuildTime = "N/A"
func init() {
config.Set("Smallstep CLI", Version, BuildTime)
ca.UserAgent = config.Version()
step.Set("Smallstep CLI", Version, BuildTime)
ca.UserAgent = step.Version()
rand.Seed(time.Now().UnixNano())
}
@@ -71,7 +72,7 @@ func main() {
app.Name = "step"
app.HelpName = "step"
app.Usage = "plumbing for distributed systems"
app.Version = config.Version()
app.Version = step.Version()
app.Commands = command.Retrieve()
app.Flags = append(app.Flags, cli.HelpFlag)
app.EnableBashCompletion = true
@@ -120,8 +121,8 @@ func main() {
func panicHandler() {
if r := recover(); r != nil {
if os.Getenv("STEPDEBUG") == "1" {
fmt.Fprintf(os.Stderr, "%s\n", config.Version())
fmt.Fprintf(os.Stderr, "Release Date: %s\n\n", config.ReleaseDate())
fmt.Fprintf(os.Stderr, "%s\n", step.Version())
fmt.Fprintf(os.Stderr, "Release Date: %s\n\n", step.ReleaseDate())
panic(r)
} else {
fmt.Fprintln(os.Stderr, "Something unexpected happened.")

View File

@@ -8,9 +8,9 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func init() {
@@ -28,7 +28,7 @@ Encode to base64 using the standard encoding:
'''
$ echo -n This is the string to encode | step base64
VGhpcyBpcyB0aGUgc3RyaW5nIHRvIGVuY29kZQ==
$ step base64 This is the string to encode
$ step base64 This is the string to encode
VGhpcyBpcyB0aGUgc3RyaW5nIHRvIGVuY29kZQ==
'''

View File

@@ -1,9 +1,9 @@
package beta
import (
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/command/ca"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
// init creates and registers the ca command

View File

@@ -9,8 +9,6 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/config"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
@@ -19,6 +17,8 @@ import (
"github.com/smallstep/cli/utils/cautils"
"github.com/smallstep/truststore"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/step"
)
func bootstrapCommand() cli.Command {
@@ -99,7 +99,7 @@ func bootstrapAction(ctx *cli.Context) error {
fingerprint := strings.TrimSpace(ctx.String("fingerprint"))
team := ctx.String("team")
rootFile := pki.GetRootCAPath()
configFile := filepath.Join(config.StepPath(), "config", "defaults.json")
configFile := filepath.Join(step.Path(), "config", "defaults.json")
redirectURL := ctx.String("redirect-url")
switch {

View File

@@ -5,11 +5,11 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/command/ca/admin"
"github.com/smallstep/cli/command/ca/provisioner"
"github.com/smallstep/cli/command/ca/provisionerbeta"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
// init creates and registers the ca command

View File

@@ -4,7 +4,6 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
@@ -12,6 +11,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func certificateCommand() cli.Command {

View File

@@ -9,13 +9,13 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
type flowType int

View File

@@ -14,7 +14,6 @@ import (
"github.com/smallstep/certificates/cas/apiv1"
"github.com/smallstep/certificates/kms"
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/ui"
@@ -23,6 +22,8 @@ import (
// Enable azurekms
_ "github.com/smallstep/certificates/kms/azurekms"
"go.step.sm/cli-utils/command"
)
func initCommand() cli.Command {

View File

@@ -22,7 +22,6 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/crypto/x509util"
"github.com/smallstep/cli/errs"
@@ -32,6 +31,7 @@ import (
"github.com/smallstep/cli/utils/cautils"
"github.com/smallstep/cli/utils/sysutils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func renewCertificateCommand() cli.Command {

View File

@@ -16,7 +16,6 @@ import (
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/crypto/x509util"
"github.com/smallstep/cli/errs"
@@ -25,6 +24,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ocsp"
)

View File

@@ -10,12 +10,12 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func rootComand() cli.Command {

View File

@@ -6,7 +6,6 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certificates/api"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
@@ -14,6 +13,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func signCertificateCommand() cli.Command {

View File

@@ -6,12 +6,12 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/pki"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func tokenCommand() cli.Command {

View File

@@ -5,12 +5,12 @@ import (
"io/ioutil"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func bundleCommand() cli.Command {

View File

@@ -1,8 +1,8 @@
package certificate
import (
"github.com/smallstep/cli/command"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
// Command returns the cli.Command for jwt and related subcommands.

View File

@@ -7,7 +7,6 @@ import (
"time"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
@@ -15,6 +14,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/crypto/x509util"
)

View File

@@ -7,12 +7,12 @@ import (
"os"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func formatCommand() cli.Command {

View File

@@ -6,11 +6,11 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certinfo"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/truststore"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func installCommand() cli.Command {

View File

@@ -7,11 +7,11 @@ import (
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func keyCommand() cli.Command {
@@ -20,11 +20,11 @@ func keyCommand() cli.Command {
Action: command.ActionFunc(keyAction),
Usage: "print public key embedded in a certificate",
UsageText: "**step certificate key** <crt-file> [**--out**=<file>]",
Description: `**step certificate key** prints the public key embedded in a certificate or
Description: `**step certificate key** prints the public key embedded in a certificate or
a certificate signing request. If <crt-file> is a certificate bundle, only the
first block will be taken into account.
The command will print a public or a decrypted private key if <crt-file>
The command will print a public or a decrypted private key if <crt-file>
contains only a key.
## POSITIONAL ARGUMENTS

View File

@@ -5,13 +5,13 @@ import (
"crypto/x509"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"software.sslmate.com/src/go-pkcs12"
)

View File

@@ -10,9 +10,9 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/smallstep/cli/config"
"github.com/smallstep/cli/usage"
"github.com/urfave/cli"
"go.step.sm/cli-utils/step"
)
// IgnoreEnvVar is a value added to a flag EnvVar to avoid the use of
@@ -61,7 +61,7 @@ func IsForce() bool {
func getConfigVars(ctx *cli.Context) error {
configFile := ctx.GlobalString("config")
if configFile == "" {
configFile = filepath.Join(config.StepPath(), "config", "defaults.json")
configFile = filepath.Join(step.Path(), "config", "defaults.json")
}
b, err := ioutil.ReadFile(configFile)

View File

@@ -0,0 +1,56 @@
package context
import (
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
// init creates and registers the ca command
func init() {
cmd := cli.Command{
Name: "context",
Usage: "manage certificate authority contexts",
UsageText: "**step context** <subcommand> [arguments] [global-flags] [subcommand-flags]",
Description: `**step context** command group provides facilities to manage certificate
authority contexts.
## EXAMPLES
'''
$ cat $(step path --base)/contexts.json
{
"alpha-one": {
"authority": "alpha-one.ca.smallstep.com",
"profile": "alpha-one"
},
"alpha-two": {
"authority": "alpha-two.ca.smallstep.com",
"profile": "alpha-two"
},
"beta": {
"authority": "beta.ca.smallstep.com",
"profile": "beta"
}
}
'''
Set the default certificate authority context:
'''
$ step context set alpha-one
'''
List the available certificate authority contexts:
'''
$ step context list
alpha-one
alpha-two
beta
'''`,
Subcommands: cli.Commands{
setCommand(),
listCommand(),
},
}
command.Register(cmd)
}

45
command/context/list.go Normal file
View File

@@ -0,0 +1,45 @@
package context
import (
"github.com/smallstep/cli/ui"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/step"
)
func listCommand() cli.Command {
return cli.Command{
Name: "list",
Usage: "list available certificate authority contexts",
UsageText: "**step context list**",
Description: `**step context list** command lists available certificate authority contexts.
## EXAMPLES
List all certificate authority contexts:
'''
$ step context list
alpha-one.ca.smallstep.com
alpha-two.ca.smallstep.com
beta.ca.smallstep.com
'''`,
Action: command.ActionFunc(listAction),
}
}
func listAction(ctx *cli.Context) error {
cm := step.GetContextMap()
def := step.GetCurrentContext()
if def != nil {
ui.Printf("▶ %s\n", def.Name)
}
for k := range cm {
if k == def.Name {
continue
}
ui.Println(k)
}
return nil
}

57
command/context/set.go Normal file
View File

@@ -0,0 +1,57 @@
package context
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/smallstep/cli/errs"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/fileutil"
"go.step.sm/cli-utils/step"
)
func setCommand() cli.Command {
return cli.Command{
Name: "set",
Usage: "set the default certificate authority context",
UsageText: "**step context set**",
Description: `**step context set** command sets the default certificate authority context.
## EXAMPLES
Set the default certificate authority context:
'''
$ step context set alpha-one
'''`,
Action: command.ActionFunc(setAction),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force",
Usage: `Create the JWK key pair for the provisioner.`,
Hidden: true,
},
},
}
}
func setAction(ctx *cli.Context) error {
ctxStr := ctx.Args().Get(0)
if _, ok := step.GetContext(ctxStr); !ok {
return errors.Errorf("context '%s' not found", ctxStr)
}
type currentCtxType struct {
Context string `json:"context"`
}
def := currentCtxType{Context: ctxStr}
b, err := json.Marshal(def)
if err != nil {
return err
}
ctx.Set("force", "true")
if err = fileutil.WriteFile(step.CurrentContextFile(), b, 0644); err != nil {
return errs.FileError(err, step.CurrentContextFile())
}
return nil
}

View File

@@ -9,13 +9,13 @@ import (
"github.com/pkg/errors"
"github.com/urfave/cli"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/jose"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"go.step.sm/cli-utils/command"
)
func changePassCommand() cli.Command {

View File

@@ -1,7 +1,6 @@
package crypto
import (
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/command/crypto/hash"
"github.com/smallstep/cli/command/crypto/jose"
"github.com/smallstep/cli/command/crypto/jwe"
@@ -14,6 +13,7 @@ import (
"github.com/smallstep/cli/command/crypto/otp"
"github.com/smallstep/cli/command/crypto/winpe"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func init() {

View File

@@ -8,7 +8,6 @@ import (
"fmt"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/randutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
@@ -16,6 +15,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
const (

View File

@@ -13,11 +13,11 @@ import (
"os"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -11,7 +11,6 @@ import (
"os"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
@@ -19,6 +18,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -9,11 +9,11 @@ import (
"math/big"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func inspectCommand() cli.Command {

View File

@@ -4,13 +4,13 @@ import (
"encoding/pem"
"os"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/crypto/keyutil"
)

View File

@@ -2,7 +2,6 @@ package crypto
import (
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
@@ -11,6 +10,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func createKeyPairCommand() cli.Command {

View File

@@ -7,12 +7,12 @@ import (
"os"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/nacl/box"
)

View File

@@ -7,12 +7,12 @@ import (
"os"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/nacl/sign"
)

View File

@@ -8,11 +8,11 @@ import (
"github.com/pquerna/otp"
"github.com/pquerna/otp/totp"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func generateCommand() cli.Command {

View File

@@ -13,8 +13,8 @@ import (
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/smallstep/cli/command"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func init() {

View File

@@ -19,7 +19,6 @@ import (
"time"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/randutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/exec"
@@ -27,6 +26,7 @@ import (
"github.com/smallstep/cli/jose"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
// These are the OAuth2.0 client IDs from the Step CLI. This application is

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
}),
}

View File

@@ -15,7 +15,6 @@ import (
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/certificates/ca/identity"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/crypto/sshutil"
@@ -25,6 +24,7 @@ import (
"github.com/smallstep/cli/utils"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/ssh"
)

View File

@@ -9,13 +9,13 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certificates/ca"
caErrs "github.com/smallstep/certificates/errs"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/jose"
"github.com/smallstep/cli/token"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func checkHostCommand() cli.Command {

View File

@@ -11,14 +11,14 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/config"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/step"
"golang.org/x/crypto/ssh"
)
@@ -177,7 +177,7 @@ func configAction(ctx *cli.Context) (recoverErr error) {
data := map[string]string{
"GOOS": runtime.GOOS,
"StepPath": config.StepPath(),
"StepPath": step.Path(),
}
if len(sets) > 0 {
for _, s := range sets {
@@ -256,7 +256,7 @@ func configAction(ctx *cli.Context) (recoverErr error) {
if ctx.Bool("dry-run") {
for _, t := range templates {
ui.Printf("{{ \"%s\" | bold }}\n", config.StepAbs(t.Path))
ui.Printf("{{ \"%s\" | bold }}\n", step.Abs(t.Path))
fmt.Println(string(t.Content))
}
return nil
@@ -266,7 +266,7 @@ func configAction(ctx *cli.Context) (recoverErr error) {
if err := t.Write(); err != nil {
return err
}
ui.Printf(`{{ "%s" | green }} {{ "%s" | bold }}`+"\n", ui.IconGood, config.StepAbs(t.Path))
ui.Printf(`{{ "%s" | green }} {{ "%s" | bold }}`+"\n", ui.IconGood, step.Abs(t.Path))
}
return nil

View File

@@ -3,11 +3,11 @@ package ssh
import (
"fmt"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func fingerPrintCommand() cli.Command {

View File

@@ -6,11 +6,11 @@ import (
"text/tabwriter"
"github.com/smallstep/certificates/ca"
"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"
"go.step.sm/cli-utils/command"
)
func hostsCommand() cli.Command {

View File

@@ -6,11 +6,11 @@ import (
"os"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -4,10 +4,10 @@ import (
"fmt"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
)
func listCommand() cli.Command {

View File

@@ -8,7 +8,6 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
@@ -16,6 +15,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -4,12 +4,12 @@ import (
"fmt"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -13,7 +13,6 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/errs"
@@ -21,6 +20,7 @@ import (
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -8,7 +8,6 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca/identity"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/pemutil"
"github.com/smallstep/cli/errs"
@@ -17,6 +16,7 @@ import (
"github.com/smallstep/cli/utils"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -9,13 +9,13 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -8,13 +8,13 @@ import (
"github.com/smallstep/certificates/api"
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/cli/command"
cmdca "github.com/smallstep/cli/command/ca"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/flags"
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -9,7 +9,6 @@ import (
"github.com/smallstep/certificates/authority/provisioner"
"github.com/smallstep/certificates/ca"
"github.com/smallstep/certificates/errs"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/crypto/keys"
"github.com/smallstep/cli/crypto/sshutil"
"github.com/smallstep/cli/flags"
@@ -17,6 +16,7 @@ import (
"github.com/smallstep/cli/ui"
"github.com/smallstep/cli/utils/cautils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/command"
"golang.org/x/crypto/ssh"
)

View File

@@ -5,8 +5,8 @@ import (
"github.com/urfave/cli"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/config"
"go.step.sm/cli-utils/command"
"go.step.sm/cli-utils/step"
)
func init() {
@@ -23,7 +23,7 @@ func init() {
// Command prints out the current version of the tool
func Command(c *cli.Context) error {
fmt.Printf("%s\n", config.Version())
fmt.Printf("Release Date: %s\n", config.ReleaseDate())
fmt.Printf("%s\n", step.Version())
fmt.Printf("Release Date: %s\n", step.ReleaseDate())
return nil
}

View File

@@ -1,136 +0,0 @@
package config
import (
"fmt"
"log"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
"time"
)
// version and buildTime are filled in during build by the Makefile
var (
name = "Smallstep CLI"
buildTime = "N/A"
commit = "N/A"
)
// StepPathEnv defines the name of the environment variable that can overwrite
// the default configuration path.
const StepPathEnv = "STEPPATH"
// HomeEnv defines the name of the environment variable that can overwrite the
// default home directory.
const HomeEnv = "HOME"
// stepPath will be populated in init() with the proper STEPPATH.
var stepPath string
// homePath will be populated in init() with the proper HOME.
var homePath string
// StepPath returns the path for the step configuration directory, this is
// defined by the environment variable STEPPATH or if this is not set it will
// default to '$HOME/.step'.
func StepPath() string {
return stepPath
}
// Home returns the user home directory using the environment variable HOME or
// the os/user package.
func Home() string {
return homePath
}
// StepAbs returns the given path relative to the StepPath if it's not an
// absolute path, relative to the home directory using the special string "~/",
// or relative to the working directory using "./"
//
// Relative paths like 'certs/root_ca.crt' will be converted to
// '$STEPPATH/certs/root_ca.crt', but paths like './certs/root_ca.crt' will be
// relative to the current directory. Home relative paths like
// ~/certs/root_ca.crt will be converted to '$HOME/certs/root_ca.crt'. And
// absolute paths like '/certs/root_ca.crt' will remain the same.
func StepAbs(path string) string {
if filepath.IsAbs(path) {
return path
}
// Windows accept both \ and /
slashed := filepath.ToSlash(path)
switch {
case strings.HasPrefix(slashed, "~/"):
return filepath.Join(homePath, path[2:])
case strings.HasPrefix(slashed, "./"), strings.HasPrefix(slashed, "../"):
if abs, err := filepath.Abs(path); err == nil {
return abs
}
return path
default:
return filepath.Join(stepPath, path)
}
}
func init() {
l := log.New(os.Stderr, "", 0)
// Get home path from environment or from the user object.
homePath = os.Getenv(HomeEnv)
if homePath == "" {
usr, err := user.Current()
if err == nil && usr.HomeDir != "" {
homePath = usr.HomeDir
} else {
l.Fatalf("Error obtaining home directory, please define environment variable %s.", HomeEnv)
}
}
// Get step path from environment or relative to home.
stepPath = os.Getenv(StepPathEnv)
if stepPath == "" {
stepPath = filepath.Join(homePath, ".step")
}
// Check for presence or attempt to create it if necessary.
//
// Some environments (e.g. third party docker images) might fail creating
// the directory, so this should not panic if it can't.
if fi, err := os.Stat(stepPath); err != nil {
os.MkdirAll(stepPath, 0700)
} else if !fi.IsDir() {
l.Fatalf("File '%s' is not a directory.", stepPath)
}
// cleanup
homePath = filepath.Clean(homePath)
stepPath = filepath.Clean(stepPath)
}
// Set updates the Version and ReleaseDate
func Set(n, v, t string) {
name = n
buildTime = t
commit = v
}
// Version returns the current version of the binary
func Version() string {
out := commit
if commit == "N/A" {
out = "0000000-dev"
}
return fmt.Sprintf("%s/%s (%s/%s)",
name, out, runtime.GOOS, runtime.GOARCH)
}
// ReleaseDate returns the time of when the binary was built
func ReleaseDate() string {
out := buildTime
if buildTime == "N/A" {
out = time.Now().UTC().Format("2006-01-02 15:04 MST")
}
return out
}

View File

@@ -10,7 +10,7 @@ import (
"strings"
"github.com/pkg/errors"
"github.com/smallstep/cli/config"
"go.step.sm/cli-utils/step"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
"golang.org/x/term"
@@ -182,7 +182,7 @@ func NewShell(user, address string, opts ...ShellOption) (*Shell, error) {
address = formatAddress(address)
// Use known_host as HostKeyCallback
knownHosts, err := knownhosts.New(filepath.Join(config.Home(), ".ssh", "known_hosts"))
knownHosts, err := knownhosts.New(filepath.Join(step.Home(), ".ssh", "known_hosts"))
if err != nil {
return nil, errors.Wrap(err, "error reading known_hosts")
}

View File

@@ -10,10 +10,10 @@ import (
"github.com/pkg/errors"
"github.com/smallstep/certificates/api"
"github.com/smallstep/cli/config"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/utils"
"github.com/urfave/cli"
"go.step.sm/cli-utils/step"
)
var (
@@ -199,7 +199,7 @@ but can accept a different configuration file using **--ca-config** flag.`,
Name: "ca-config",
Usage: `The certificate authority configuration <file>. Defaults to
$STEPPATH/config/ca.json`,
Value: filepath.Join(config.StepPath(), "config", "ca.json"),
Value: filepath.Join(step.Path(), "config", "ca.json"),
}
// AdminCert is a cli.Flag used to pass the x5c header certificate for a JWT.

8
go.mod
View File

@@ -25,6 +25,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.5
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352
go.step.sm/cli-utils v0.6.0
go.step.sm/crypto v0.11.0
go.step.sm/linkedca v0.7.0
golang.org/x/crypto v0.0.0-20210915214749-c084706c2272
@@ -36,8 +37,11 @@ require (
software.sslmate.com/src/go-pkcs12 v0.0.0-20201103104416-57fc603b7f52
)
// replace github.com/smallstep/certificates => ../certificates
replace github.com/smallstep/certificates => ../certificates
// replace github.com/smallstep/certinfo => ../certinfo
// replace go.step.sm/linkedca => ../linkedca
// replace go.step.sm/cli-utils => ../cli-utils
replace go.step.sm/cli-utils => ../cli-utils
// replace go.step.sm/crypto => ../crypto

3
go.sum
View File

@@ -954,8 +954,11 @@ go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52l
go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw=
go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
<<<<<<< HEAD
go.step.sm/cli-utils v0.6.0 h1:sH4FxBcjmbxyilKXheSyJuKF/QjpojpiW90ERwUWOgQ=
go.step.sm/cli-utils v0.6.0/go.mod h1:jklBMavFl2PbmGlyxgax08ZnB0uWpadjuOlSKKXz+0U=
=======
>>>>>>> 264c0e5 (Initial step path contexts commit)
go.step.sm/crypto v0.9.0/go.mod h1:+CYG05Mek1YDqi5WK0ERc6cOpKly2i/a5aZmU1sfGj0=
go.step.sm/crypto v0.11.0 h1:VDpeVgEmqme/FK2w5QINxkOQ1FWOm/Wi2TwQXiacKr8=
go.step.sm/crypto v0.11.0/go.mod h1:5YzQ85BujYBu6NH18jw7nFjwuRnDch35nLzH0ES5sKg=

View File

@@ -11,9 +11,9 @@ import (
"time"
"github.com/pkg/errors"
"github.com/smallstep/cli/command"
"github.com/smallstep/cli/errs"
"github.com/smallstep/cli/ui"
"go.step.sm/cli-utils/command"
)
var (