From 9b835218d6fe0538c14c2aea576f71d2c21d96e3 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Fri, 17 Jul 2020 10:56:50 -0400 Subject: [PATCH] Add flag to allow logging JSON requests from Ziti CLI. Fixes GH-140 --- doc/release-notes.md | 8 ++++---- ziti/cmd/ziti/cmd/edge_controller/create_ca.go | 2 +- .../cmd/ziti/cmd/edge_controller/create_config.go | 2 +- .../cmd/edge_controller/create_config_type.go | 2 +- .../cmd/edge_controller/create_edge_router.go | 3 ++- .../edge_controller/create_edge_router_policy.go | 2 +- .../ziti/cmd/edge_controller/create_identity.go | 3 +-- .../ziti/cmd/edge_controller/create_service.go | 2 +- .../create_service_edge_router_policy.go | 2 +- .../cmd/edge_controller/create_service_policy.go | 2 +- .../ziti/cmd/edge_controller/create_snapshot.go | 4 ++-- .../ziti/cmd/edge_controller/create_terminator.go | 2 +- ziti/cmd/ziti/cmd/edge_controller/delete.go | 2 +- ziti/cmd/ziti/cmd/edge_controller/list.go | 15 +++++---------- ziti/cmd/ziti/cmd/edge_controller/login.go | 4 ++-- .../ziti/cmd/edge_controller/policy_advisor.go | 4 ++-- ziti/cmd/ziti/cmd/edge_controller/root.go | 6 ++++++ ziti/cmd/ziti/cmd/edge_controller/update.go | 2 +- .../cmd/ziti/cmd/edge_controller/update_config.go | 2 +- .../cmd/edge_controller/update_edge_router.go | 2 +- .../edge_controller/update_edge_router_policy.go | 2 +- .../ziti/cmd/edge_controller/update_identity.go | 2 +- .../edge_controller/update_identity_configs.go | 3 ++- .../ziti/cmd/edge_controller/update_service.go | 2 +- .../update_service_edge_router_policy.go | 2 +- .../cmd/edge_controller/update_service_policy.go | 2 +- .../ziti/cmd/edge_controller/update_terminator.go | 2 +- ziti/cmd/ziti/cmd/edge_controller/verify_ca.go | 6 +++--- ziti/cmd/ziti/cmd/edge_controller/version.go | 2 +- ziti/cmd/ziti/util/rest.go | 9 +++++++-- 30 files changed, 55 insertions(+), 48 deletions(-) diff --git a/doc/release-notes.md b/doc/release-notes.md index c25fbf098..a6ae6fec3 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -1,19 +1,19 @@ # Release 0.15.2 * What's New: - + * [#140](https://github.com/openziti/ziti/issues/140) - Allow logging JSON request for Ziti CLI + * [#148](https://github.com/openziti/ziti/issues/148) - Show isOnline in ziti edge list edge-routers + * [#144](https://github.com/openziti/ziti/issues/144) - Allow ziti-fabric list to use queries. Default to `true limit none` * Bug Fixes: * [#142](https://github.com/openziti/ziti/issues/142) - fix CLI ca create not defaulting identity roles - * [#144](https://github.com/openziti/ziti/issues/144) - ziti-fabric is only returning first 10 results for lists of services, routers and terminators * [#146](https://github.com/openziti/ziti/issues/146) - Export edge router JWT fails sometimes when there are more than 10 edge routers * [#147](https://github.com/openziti/ziti/issues/147) - Fix paging output when using 'limit none' - * [#148](https://github.com/openziti/ziti/issues/148) - Show isOnline in ziti edge list edge-routers * [edge#243](https://github.com/openziti/edge/issue/243) - Session creation only returns 10 edge routers * [edge#245](https://github.com/openziti/edge/issue/245) - fingerprint calculation changed from 0.14 to 0.15. Ensure 0.15 routers can work with 0.14 controllers * [edge#248](https://github.com/openziti/edge/issue/248) - Edge Router Hello can time out on slow networks with many links to establish * [foundation#103](https://github.com/openziti/foundation/issues/103) - Fix config file env injection for lists - + # Release 0.15.1 * What's New: diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_ca.go b/ziti/cmd/ziti/cmd/edge_controller/create_ca.go index 3e58274a7..dd41e2c52 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_ca.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_ca.go @@ -86,11 +86,11 @@ func newCreateCaCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.C // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringToStringVarP(&options.tags, "tags", "t", nil, "Add tags to service definition") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().BoolVarP(&options.authEnabled, "auth", "e", false, "Whether the CA can be used for authentication or not") cmd.Flags().BoolVarP(&options.ottCaEnrollment, "ottca", "o", false, "Whether the CA can be used for one-time-token CA enrollment") cmd.Flags().BoolVarP(&options.autoCaEnrollment, "autoca", "u", false, "Whether the CA can be used for auto CA enrollment") cmd.Flags().StringSliceVarP(&options.identityRoles, "role-attributes", "a", []string{}, "A csv string of role attributes enrolling identities receive") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_config.go b/ziti/cmd/ziti/cmd/edge_controller/create_config.go index a812bf320..09b38f06a 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_config.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_config.go @@ -61,7 +61,7 @@ func newCreateConfigCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cob // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.jsonFile, "json-file", "f", "", "Read config JSON from a file instead of the command line") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_config_type.go b/ziti/cmd/ziti/cmd/edge_controller/create_config_type.go index 4d0fa816c..3e33c5e8c 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_config_type.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_config_type.go @@ -61,7 +61,7 @@ func newCreateConfigTypeCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.schemaFile, "schema-file", "f", "", "Read config type JSON schema from a file instead of the command line") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_edge_router.go b/ziti/cmd/ziti/cmd/edge_controller/create_edge_router.go index 56e01d93e..0f858f977 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_edge_router.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_edge_router.go @@ -59,8 +59,9 @@ func newCreateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new edge router") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringVarP(&options.jwtOutputFile, "jwt-output-file", "o", "", "File to which to output the JWT used for enrolling the edge router") + options.AddCommonFlags(cmd) + return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_edge_router_policy.go b/ziti/cmd/ziti/cmd/edge_controller/create_edge_router_policy.go index 42e163a01..184ba8b30 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_edge_router_policy.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_edge_router_policy.go @@ -59,7 +59,7 @@ func newCreateEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Wr cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVarP(&options.edgeRouterRoles, "edge-router-roles", "e", nil, "Edge router roles of the new edge router policy") cmd.Flags().StringSliceVarP(&options.identityRoles, "identity-roles", "i", nil, "Identity roles of the new edge router policy") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_identity.go b/ziti/cmd/ziti/cmd/edge_controller/create_identity.go index 9631dab96..f6840f29d 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_identity.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_identity.go @@ -77,11 +77,10 @@ func newCreateIdentityOfTypeCmd(idType string, options *createIdentityOptions) * // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().BoolVarP(&options.isAdmin, "admin", "A", false, "Give the new identity admin privileges") cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new identity") cmd.Flags().StringVarP(&options.jwtOutputFile, "jwt-output-file", "o", "", "File to which to output the JWT used for enrolling the identity") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_service.go b/ziti/cmd/ziti/cmd/edge_controller/create_service.go index 27509a38c..01e32ddad 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_service.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_service.go @@ -64,10 +64,10 @@ func newCreateServiceCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *co // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringToStringVarP(&options.tags, "tags", "t", nil, "Add tags to service definition") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Role attributes of the new service") cmd.Flags().StringSliceVarP(&options.configs, "configs", "c", nil, "Configuration id or names to be associated with the new service") cmd.Flags().StringVar(&options.terminatorStrategy, "terminator-strategy", "", "Specifies the terminator strategy for the service") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_service_edge_router_policy.go b/ziti/cmd/ziti/cmd/edge_controller/create_service_edge_router_policy.go index 4f6443a2a..dd8d86e71 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_service_edge_router_policy.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_service_edge_router_policy.go @@ -59,7 +59,7 @@ func newCreateServiceEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOu cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVarP(&options.edgeRouterRoles, "edge-router-roles", "e", nil, "Edge router roles of the new service edge router policy") cmd.Flags().StringSliceVarP(&options.serviceRoles, "service-roles", "s", nil, "Identity roles of the new service edge router policy") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_service_policy.go b/ziti/cmd/ziti/cmd/edge_controller/create_service_policy.go index 0a9f19277..9b22ef736 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_service_policy.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_service_policy.go @@ -62,7 +62,7 @@ func newCreateServicePolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Write cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVarP(&options.serviceRoles, "service-roles", "s", nil, "Service roles of the new service policy") cmd.Flags().StringSliceVarP(&options.identityRoles, "identity-roles", "i", nil, "Identity roles of the new service policy") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_snapshot.go b/ziti/cmd/ziti/cmd/edge_controller/create_snapshot.go index 2ade159e9..0e43b31e3 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_snapshot.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_snapshot.go @@ -53,13 +53,13 @@ func newSnapshotDbCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } // runSnapshotDb create a new config on the Ziti Edge Controller func runSnapshotDb(o *snapshotDbOptions) error { - _, err := util.EdgeControllerUpdate("database/snapshot", "", o.Out, http.MethodPost, false) + _, err := util.EdgeControllerUpdate("database/snapshot", "", o.Out, http.MethodPost, false, false) return err } diff --git a/ziti/cmd/ziti/cmd/edge_controller/create_terminator.go b/ziti/cmd/ziti/cmd/edge_controller/create_terminator.go index a1843724f..c441cc3cd 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/create_terminator.go +++ b/ziti/cmd/ziti/cmd/edge_controller/create_terminator.go @@ -63,10 +63,10 @@ func newCreateTerminatorCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringVar(&options.binding, "binding", "transport", "Set the terminator binding") cmd.Flags().Int32VarP(&options.cost, "cost", "c", 0, "Set the terminator cost") cmd.Flags().StringVarP(&options.precedence, "precedence", "p", "", "Set the terminator precedence ('default', 'required' or 'failed')") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/delete.go b/ziti/cmd/ziti/cmd/edge_controller/delete.go index 67924316c..204e42a26 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/delete.go +++ b/ziti/cmd/ziti/cmd/edge_controller/delete.go @@ -87,7 +87,7 @@ func newDeleteCmdForEntityType(entityType string, command deleteCmdRunner, optio // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/list.go b/ziti/cmd/ziti/cmd/edge_controller/list.go index 3edf2c730..95b24c5d2 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/list.go +++ b/ziti/cmd/ziti/cmd/edge_controller/list.go @@ -179,8 +179,7 @@ func newListCmdForEntityType(entityType string, command listCommandRunner, optio // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } @@ -208,12 +207,11 @@ func newListServicesCmd(options *commonOptions) *cobra.Command { // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringVar(&asIdentity, "as-identity", "", "Allow admins to see services as they would be seen by a different identity") cmd.Flags().StringSliceVar(&configTypes, "config-types", nil, "Override which config types to view on services") cmd.Flags().StringSliceVar(&roleFilters, "role-filters", nil, "Allow filtering by roles") cmd.Flags().StringVar(&roleSemantic, "role-semantic", "", "Specify which roles semantic to use ") + options.AddCommonFlags(cmd) return cmd } @@ -239,10 +237,9 @@ func newListEdgeRoutersCmd(options *commonOptions) *cobra.Command { // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVar(&roleFilters, "role-filters", nil, "Allow filtering by roles") cmd.Flags().StringVar(&roleSemantic, "role-semantic", "", "Specify which roles semantic to use ") + options.AddCommonFlags(cmd) return cmd } @@ -268,10 +265,9 @@ func newListIdentitiesCmd(options *commonOptions) *cobra.Command { // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVar(&roleFilters, "role-filters", nil, "Allow filtering by roles") cmd.Flags().StringVar(&roleSemantic, "role-semantic", "", "Specify which roles semantic to use ") + options.AddCommonFlags(cmd) return cmd } @@ -295,8 +291,7 @@ func newSubListCmdForEntityType(entityType string, subType string, outputF outpu // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/login.go b/ziti/cmd/ziti/cmd/edge_controller/login.go index fc471aa33..780352dd4 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/login.go +++ b/ziti/cmd/ziti/cmd/edge_controller/login.go @@ -19,11 +19,11 @@ package edge_controller import ( "fmt" "github.com/Jeffail/gabs" + "github.com/openziti/foundation/util/term" "github.com/openziti/ziti/ziti/cmd/ziti/cmd/common" cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/openziti/ziti/ziti/cmd/ziti/util" - "github.com/openziti/foundation/util/term" "github.com/spf13/cobra" "io" "path/filepath" @@ -70,7 +70,7 @@ func newLoginCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comm cmd.Flags().StringVarP(&options.Password, "password", "p", "", "password to use for authenticating to the Ziti Edge Controller, if -u is supplied and -p is not, a value will be prompted for") cmd.Flags().StringVarP(&options.Cert, "cert", "c", "", "additional root certificates used by the Ziti Edge Controller") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/policy_advisor.go b/ziti/cmd/ziti/cmd/edge_controller/policy_advisor.go index 030443005..743cce755 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/policy_advisor.go +++ b/ziti/cmd/ziti/cmd/edge_controller/policy_advisor.go @@ -72,7 +72,7 @@ func newPolicyAdvisorIdentitiesCmd(f cmdutil.Factory, out io.Writer, errOut io.W // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) cmd.Flags().BoolVarP(&options.quiet, "quiet", "q", false, "Minimize output by hiding header") return cmd @@ -101,8 +101,8 @@ func newPolicyAdvisorServicesCmd(f cmdutil.Factory, out io.Writer, errOut io.Wri // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().BoolVarP(&options.quiet, "quiet", "q", false, "Minimize output by hiding header") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/root.go b/ziti/cmd/ziti/cmd/edge_controller/root.go index 9e94fc49f..cc895a6a0 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/root.go +++ b/ziti/cmd/ziti/cmd/edge_controller/root.go @@ -37,9 +37,15 @@ func NewCmdEdge(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Comma // commonOptions are common options for edge controller commands type commonOptions struct { common.CommonOptions + OutputJSONRequest bool OutputJSONResponse bool } +func (options *commonOptions) AddCommonFlags(cmd *cobra.Command) { + cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + cmd.Flags().BoolVar(&options.OutputJSONRequest, "output-request-json", false, "Output the full JSON request to the Ziti Edge Controller") +} + // newCmdEdgeController creates a command object for the "edge controller" command func newCmdEdgeController(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { cmd := util.NewEmptyParentCmd("controller", "Interact with a Ziti Edge Controller") diff --git a/ziti/cmd/ziti/cmd/edge_controller/update.go b/ziti/cmd/ziti/cmd/edge_controller/update.go index e92eefb4c..f1f26e71f 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update.go @@ -71,7 +71,7 @@ func deleteEntityOfTypeWithBody(entityType string, body string, options *commonO // updateEntityOfType updates an entity of the given type on the Ziti Edge Controller func updateEntityOfType(entityType string, body string, options *commonOptions, method string) (*gabs.Container, error) { - return util.EdgeControllerUpdate(entityType, body, options.Out, method, options.OutputJSONResponse) + return util.EdgeControllerUpdate(entityType, body, options.Out, method, options.OutputJSONRequest, options.OutputJSONResponse) } func doRequest(entityType string, options *commonOptions, doRequest func(request *resty.Request, url string) (*resty.Response, error)) (*gabs.Container, error) { diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_config.go b/ziti/cmd/ziti/cmd/edge_controller/update_config.go index aad0bed19..f4860257b 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_config.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_config.go @@ -65,7 +65,7 @@ func newUpdateConfigCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cob cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the config") cmd.Flags().StringVarP(&options.data, "data", "d", "", "Set the data of the config") cmd.Flags().StringVarP(&options.jsonFile, "json-file", "f", "", "Read config JSON from a file instead of the command line") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_edge_router.go b/ziti/cmd/ziti/cmd/edge_controller/update_edge_router.go index 77aba67bc..8f9e15e5a 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_edge_router.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_edge_router.go @@ -59,9 +59,9 @@ func newUpdateEdgeRouterCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the edge router") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Set role attributes of the edge router. Use --role-attributes '' to set an empty list") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_edge_router_policy.go b/ziti/cmd/ziti/cmd/edge_controller/update_edge_router_policy.go index 713c7d7b9..f1452cb68 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_edge_router_policy.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_edge_router_policy.go @@ -60,9 +60,9 @@ func newUpdateEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Wr // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the edge router policy") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.edgeRouterRoles, "edge-router-roles", "e", nil, "Edge router roles of the edge router policy") cmd.Flags().StringSliceVarP(&options.identityRoles, "identity-roles", "i", nil, "Identity roles of the edge router policy") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_identity.go b/ziti/cmd/ziti/cmd/edge_controller/update_identity.go index abd464daa..ddff9c802 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_identity.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_identity.go @@ -56,10 +56,10 @@ func newUpdateIdentityCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *c SuggestFor: []string{}, } + options.AddCommonFlags(cmd) // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the identity") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Set role attributes of the identity. Use --role-attributes '' to set an empty list") diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_identity_configs.go b/ziti/cmd/ziti/cmd/edge_controller/update_identity_configs.go index 3279d10ff..d21223544 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_identity_configs.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_identity_configs.go @@ -52,9 +52,10 @@ func newUpdateIdentityConfigsCmd(f cmdutil.Factory, out io.Writer, errOut io.Wri SuggestFor: []string{}, } + options.AddCommonFlags(cmd) + // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().BoolVarP(&options.remove, "remove", "r", false, "Remove the sevice config override") return cmd diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_service.go b/ziti/cmd/ziti/cmd/edge_controller/update_service.go index f500e31aa..40711955b 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_service.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_service.go @@ -61,9 +61,9 @@ func newUpdateServiceCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *co cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the service") cmd.Flags().StringVar(&options.terminatorStrategy, "terminator-strategy", "", "Specifies the terminator strategy for the service") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.roleAttributes, "role-attributes", "a", nil, "Set role attributes of the service. Use --role-attributes '' to set an empty list") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_service_edge_router_policy.go b/ziti/cmd/ziti/cmd/edge_controller/update_service_edge_router_policy.go index 5d0e706fb..3743908e6 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_service_edge_router_policy.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_service_edge_router_policy.go @@ -60,9 +60,9 @@ func newUpdateServiceEdgeRouterPolicyCmd(f cmdutil.Factory, out io.Writer, errOu // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the edge router policy") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.edgeRouterRoles, "edge-router-roles", "e", nil, "Edge router roles of the service edge router policy") cmd.Flags().StringSliceVarP(&options.serviceRoles, "service-roles", "s", nil, "Service roles of the service edge router policy") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_service_policy.go b/ziti/cmd/ziti/cmd/edge_controller/update_service_policy.go index d31e51821..4eae4eb7d 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_service_policy.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_service_policy.go @@ -60,9 +60,9 @@ func newUpdateServicePolicyCmd(f cmdutil.Factory, out io.Writer, errOut io.Write // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) cmd.Flags().StringVarP(&options.name, "name", "n", "", "Set the name of the service policy") - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringSliceVarP(&options.serviceRoles, "service-roles", "s", nil, "Service roles of the service policy") cmd.Flags().StringSliceVarP(&options.identityRoles, "identity-roles", "i", nil, "Identity roles of the service policy") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/update_terminator.go b/ziti/cmd/ziti/cmd/edge_controller/update_terminator.go index bb859598f..036dda589 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/update_terminator.go +++ b/ziti/cmd/ziti/cmd/edge_controller/update_terminator.go @@ -65,12 +65,12 @@ func newUpdateTerminatorCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringVar(&options.router, "router", "", "Set the terminator router") cmd.Flags().StringVar(&options.address, "address", "", "Set the terminator address") cmd.Flags().StringVar(&options.binding, "binding", "", "Set the terminator binding") cmd.Flags().Int32VarP(&options.cost, "cost", "c", 0, "Set the terminator cost") cmd.Flags().StringVarP(&options.precedence, "precedence", "p", "", "Set the terminator precedence ('default', 'required' or 'failed')") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/verify_ca.go b/ziti/cmd/ziti/cmd/edge_controller/verify_ca.go index d22085a69..078a7cdb1 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/verify_ca.go +++ b/ziti/cmd/ziti/cmd/edge_controller/verify_ca.go @@ -26,12 +26,12 @@ import ( "encoding/pem" "errors" "fmt" + nfpem "github.com/openziti/foundation/util/pem" + "github.com/openziti/foundation/util/term" "github.com/openziti/ziti/ziti/cmd/ziti/cmd/common" cmdutil "github.com/openziti/ziti/ziti/cmd/ziti/cmd/factory" cmdhelper "github.com/openziti/ziti/ziti/cmd/ziti/cmd/helpers" "github.com/openziti/ziti/ziti/cmd/ziti/util" - nfpem "github.com/openziti/foundation/util/pem" - "github.com/openziti/foundation/util/term" "github.com/spf13/cobra" "gopkg.in/resty.v1" "io" @@ -124,11 +124,11 @@ func newVerifyCaCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.C // allow interspersing positional args and flags cmd.Flags().SetInterspersed(true) - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") cmd.Flags().StringVarP(&options.certPath, "cert", "c", "", "The path to a cert with the CN set as the verification token and signed by the target CA") cmd.Flags().StringVarP(&options.caCertPath, "cacert", "a", "", "The path to the CA cert that should be used to generate and sign a verification cert") cmd.Flags().StringVarP(&options.caKeyPath, "cakey", "k", "", "The path to the CA key that should be used to generate and sign a verification cert") cmd.Flags().StringVarP(&options.caKeyPassword, "password", "p", "", "The password for the CA key if necessary") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/cmd/edge_controller/version.go b/ziti/cmd/ziti/cmd/edge_controller/version.go index a7fd5810a..16e16a09d 100644 --- a/ziti/cmd/ziti/cmd/edge_controller/version.go +++ b/ziti/cmd/ziti/cmd/edge_controller/version.go @@ -52,7 +52,7 @@ func newVersionCmd(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Co SuggestFor: []string{}, } - cmd.Flags().BoolVarP(&options.OutputJSONResponse, "output-json", "j", false, "Output the full JSON response from the Ziti Edge Controller") + options.AddCommonFlags(cmd) return cmd } diff --git a/ziti/cmd/ziti/util/rest.go b/ziti/cmd/ziti/util/rest.go index 9050c84ac..772791da4 100644 --- a/ziti/cmd/ziti/util/rest.go +++ b/ziti/cmd/ziti/util/rest.go @@ -618,7 +618,7 @@ func EdgeControllerDelete(entityType string, id string, out io.Writer, logJSON b } // EdgeControllerUpdate will update entities of the given type in the given Edge Controller -func EdgeControllerUpdate(entityType string, body string, out io.Writer, method string, logJSON bool) (*gabs.Container, error) { +func EdgeControllerUpdate(entityType string, body string, out io.Writer, method string, logRequestJson, logResponseJSON bool) (*gabs.Container, error) { session := &Session{} if err := session.Load(); err != nil { return nil, err @@ -630,6 +630,11 @@ func EdgeControllerUpdate(entityType string, body string, out io.Writer, method client.SetRootCertificate(session.Cert) } + if logRequestJson { + outputJson(out, []byte(body)) + fmt.Println() + } + resp, err := client. R(). SetHeader("Content-Type", "application/json"). @@ -646,7 +651,7 @@ func EdgeControllerUpdate(entityType string, body string, out io.Writer, method entityType, session.Host, resp.Status(), resp.String()) } - if logJSON { + if logResponseJSON { outputJson(out, resp.Body()) }