From b2ca9127a3473e57fefbf5ee1a4644dd7657d0a5 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Fri, 20 Aug 2021 10:09:52 -0400 Subject: [PATCH] ziti unwrap now defaults the output file names --- CHANGELOG.md | 1 + ziti/cmd/ziti/cmd/unwrap_identity.go | 33 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 345a65b54..d0ddff113 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Bug fix: Fabric v0.16.93 fixes `xgress.GetCircuit` to provide a `ctrl not ready` error response when requests arrive before the router is fully online. * Bug fix: Ziti CLI will no longer truncate paths on logins with explicit URLs * Bug fix: Ziti CLI will now correctly check the proper lengths of sha512 hashes in hex format +* Feature: Ziti CLI `unwrap` command for identity json files will now default the output file names * Feature: Ziti CLI improvements * New interactive tutorial covering creating your first service. Run using: `ziti edge tutorial first-service` * You can now delete multiple entities at once, by providing multiple ids. Ex: `ziti edge delete services one two` or `ziti edge delete service one two` will both work. diff --git a/ziti/cmd/ziti/cmd/unwrap_identity.go b/ziti/cmd/ziti/cmd/unwrap_identity.go index 1b15c32c2..35af53697 100644 --- a/ziti/cmd/ziti/cmd/unwrap_identity.go +++ b/ziti/cmd/ziti/cmd/unwrap_identity.go @@ -18,15 +18,30 @@ type IdentityConfigFile struct { } func NewUnwrapIdentityFileCommand(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { - return &cobra.Command{ - Use: "unwrap ", + outCertFile := "" + outKeyFile := "" + outCaFile := "" + + cmd := &cobra.Command{ + Use: "unwrap ", Short: "unwrap a Ziti Identity file into its separate pieces (supports PEM only)", - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { identityFile := args[0] - outCertFile := args[1] - outKeyFile := args[2] - outCaFile := args[3] + + rootFileName := strings.TrimSuffix(identityFile, ".json") + + if outCertFile == "" { + outCertFile = rootFileName + ".cert" + } + + if outKeyFile == "" { + outKeyFile = rootFileName + ".key" + } + + if outCaFile == "" { + outCaFile = rootFileName + ".ca" + } identityJson, err := ioutil.ReadFile(identityFile) @@ -72,4 +87,10 @@ func NewUnwrapIdentityFileCommand(f cmdutil.Factory, out io.Writer, errOut io.Wr } }, } + + cmd.Flags().StringVarP(&outCertFile, "cert", "", "", "output certificate file, defaults to ./.cert") + cmd.Flags().StringVarP(&outKeyFile, "key", "", "", "output private key file, defaults to ./.key") + cmd.Flags().StringVarP(&outCaFile, "ca", "", "", "output ca bundle file, defaults to ./.ca") + + return cmd }