diff --git a/ziti/cmd/edge/create_edge_router_policy.go b/ziti/cmd/edge/create_edge_router_policy.go index a36f66b98..b23b4a149 100644 --- a/ziti/cmd/edge/create_edge_router_policy.go +++ b/ziti/cmd/edge/create_edge_router_policy.go @@ -57,7 +57,7 @@ func NewCreateEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra.Comman cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVar(&options.edgeRouterRoles, "edge-router-roles", nil, "Edge router roles of the new edge router policy") cmd.Flags().StringSliceVar(&options.identityRoles, "identity-roles", nil, "Identity roles of the new edge router policy") - cmd.Flags().StringVar(&options.semantic, "semantic", "AllOf", "Semantic dictating how multiple attributes should be interpreted. Valid values: AnyOf, AllOf") + cmd.Flags().StringVar(&options.semantic, "semantic", "AnyOf", "Semantic dictating how multiple attributes should be interpreted. Valid values: AnyOf, AllOf") options.AddCommonFlags(cmd) return cmd diff --git a/ziti/cmd/edge/create_service.go b/ziti/cmd/edge/create_service.go index 92c942d61..3da20171f 100644 --- a/ziti/cmd/edge/create_service.go +++ b/ziti/cmd/edge/create_service.go @@ -44,7 +44,7 @@ func newCreateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command { Use: "service ", Short: "creates a service managed by the Ziti Edge Controller", Long: "creates a service managed by the Ziti Edge Controller", - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { options.Cmd = cmd options.Args = args diff --git a/ziti/cmd/edge/create_service_edge_router_policy.go b/ziti/cmd/edge/create_service_edge_router_policy.go index 555ebd3e5..e9cfb90c9 100644 --- a/ziti/cmd/edge/create_service_edge_router_policy.go +++ b/ziti/cmd/edge/create_service_edge_router_policy.go @@ -57,7 +57,7 @@ func NewCreateServiceEdgeRouterPolicyCmd(out io.Writer, errOut io.Writer) *cobra cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVar(&options.edgeRouterRoles, "edge-router-roles", nil, "Edge router roles of the new service edge router policy") cmd.Flags().StringSliceVar(&options.serviceRoles, "service-roles", nil, "Identity roles of the new service edge router policy") - cmd.Flags().StringVar(&options.semantic, "semantic", "AllOf", "Semantic dictating how multiple attributes should be interpreted. Valid values: AnyOf, AllOf") + cmd.Flags().StringVar(&options.semantic, "semantic", "AnyOf", "Semantic dictating how multiple attributes should be interpreted. Valid values: AnyOf, AllOf") options.AddCommonFlags(cmd) return cmd diff --git a/ziti/cmd/edge/create_service_policy.go b/ziti/cmd/edge/create_service_policy.go index ccf0f516b..0b6f7a0b0 100644 --- a/ziti/cmd/edge/create_service_policy.go +++ b/ziti/cmd/edge/create_service_policy.go @@ -61,7 +61,7 @@ func newCreateServicePolicyCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd.Flags().SetInterspersed(true) cmd.Flags().StringSliceVar(&options.serviceRoles, "service-roles", nil, "Service roles of the new service policy") cmd.Flags().StringSliceVar(&options.identityRoles, "identity-roles", nil, "Identity roles of the new service policy") - cmd.Flags().StringVar(&options.semantic, "semantic", "AllOf", "Semantic dictating how multiple attributes should be interpreted. Valid values: AnyOf, AllOf") + cmd.Flags().StringVar(&options.semantic, "semantic", "AnyOf", "Semantic dictating how multiple attributes should be interpreted. Valid values: AnyOf, AllOf") cmd.Flags().StringSliceVarP(&options.postureCheckRoles, "posture-check-roles", "p", nil, "Posture check roles of the new service policy") options.AddCommonFlags(cmd) diff --git a/ziti/cmd/edge/create_terminator.go b/ziti/cmd/edge/create_terminator.go index 2932dd4a4..5c8494880 100644 --- a/ziti/cmd/edge/create_terminator.go +++ b/ziti/cmd/edge/create_terminator.go @@ -19,8 +19,8 @@ package edge import ( "fmt" "github.com/Jeffail/gabs" - "github.com/openziti/ziti/router/xgress_edge_transport" "github.com/openziti/foundation/v2/stringz" + "github.com/openziti/ziti/router/xgress_edge_transport" "github.com/openziti/ziti/ziti/cmd/api" cmdhelper "github.com/openziti/ziti/ziti/cmd/helpers" "github.com/spf13/cobra" diff --git a/ziti/cmd/edge/list.go b/ziti/cmd/edge/list.go index a3bb60560..fc5a6282e 100644 --- a/ziti/cmd/edge/list.go +++ b/ziti/cmd/edge/list.go @@ -42,6 +42,19 @@ import ( "github.com/spf13/cobra" ) +const filterExamplesTemplate = " # use skip and limit for paging\n" + + " ziti edge list %s 'skip 10 limit 10'\n\n" + + " # fields can be filtered using =, !=, <, >, <=, >=, in, between, contains and icontains (for case insensitive searches) \n" + + " ziti edge list configs 'name = \"test\"'\n\n" + + " # filters can be combined using and, or and parenthesis\n" + + " ziti edge list service-policies 'name in [\"echo-dial\", \"echo-bind\"] and semantic=\"AllOf\"'\n\n" + + " # roleAttributes is a list and requires a set function like anyOf, allOf, count and isEmpty\n" + + " ziti edge list identities 'anyOf(roleAttributes) contains \"echo\" skip 5 limit 20'\n\n" + + " # datetimes are specified using the RFC3339 format\n" + + " ziti edge list services 'name contains \"test\" or createdAt > datetime(2000-01-02T03:04:05Z)'\n\n" + + " # entities can be searched by tag, using tag. with some filter\n" + + " ziti edge list edge-routers 'tags.foo = \"bar\"'" + // newListCmd creates a command object for the "controller list" command func newListCmd(out io.Writer, errOut io.Writer) *cobra.Command { cmd := &cobra.Command{ @@ -52,6 +65,7 @@ func newListCmd(out io.Writer, errOut io.Writer) *cobra.Command { err := cmd.Help() cmdhelper.CheckErr(err) }, + Example: fmt.Sprintf(filterExamplesTemplate, "services"), } newOptions := func() *api.Options { @@ -187,6 +201,7 @@ func newListCmdForEntityType(entityType string, command listCommandRunner, optio cmdhelper.CheckErr(err) }, SuggestFor: []string{}, + Example: fmt.Sprintf(filterExamplesTemplate, entityType), } // allow interspersing positional args and flags @@ -215,6 +230,7 @@ func newListServicesCmd(options *api.Options) *cobra.Command { err := runListServices(asIdentity, configTypes, roleFilters, roleSemantic, options) cmdhelper.CheckErr(err) }, + Example: fmt.Sprintf(filterExamplesTemplate, "services"), SuggestFor: []string{}, } @@ -247,6 +263,7 @@ func newListEdgeRoutersCmd(options *api.Options) *cobra.Command { err := runListEdgeRouters(roleFilters, roleSemantic, options) cmdhelper.CheckErr(err) }, + Example: fmt.Sprintf(filterExamplesTemplate, "edge-routers"), SuggestFor: []string{}, } @@ -276,6 +293,7 @@ func newListIdentitiesCmd(options *api.Options) *cobra.Command { err := runListIdentities(roleFilters, roleSemantic, options) cmdhelper.CheckErr(err) }, + Example: fmt.Sprintf(filterExamplesTemplate, "identities"), SuggestFor: []string{}, } @@ -303,6 +321,7 @@ func newSubListCmdForEntityType(entityType string, subType string, outputF outpu err := runListChildren(entityType, subType, options, outputF) cmdhelper.CheckErr(err) }, + Example: fmt.Sprintf(filterExamplesTemplate, "service configs"), SuggestFor: []string{}, } diff --git a/ziti/cmd/edge/login.go b/ziti/cmd/edge/login.go index bed5c45a6..636e109b3 100644 --- a/ziti/cmd/edge/login.go +++ b/ziti/cmd/edge/login.go @@ -211,25 +211,27 @@ func (o *LoginOptions) Run() error { body = container.String() } - jsonParsed, err := login(o, host, body) + if o.Token == "" { + jsonParsed, err := login(o, host, body) - if err != nil { - return err - } + if err != nil { + return err + } - if !jsonParsed.ExistsP("data.token") { - return fmt.Errorf("no session token returned from login request to %v. Received: %v", host, jsonParsed.String()) - } + if !jsonParsed.ExistsP("data.token") { + return fmt.Errorf("no session token returned from login request to %v. Received: %v", host, jsonParsed.String()) + } - var ok bool - o.Token, ok = jsonParsed.Path("data.token").Data().(string) + var ok bool + o.Token, ok = jsonParsed.Path("data.token").Data().(string) - if !ok { - return fmt.Errorf("session token returned from login request to %v is not in the expected format. Received: %v", host, jsonParsed.String()) - } + if !ok { + return fmt.Errorf("session token returned from login request to %v is not in the expected format. Received: %v", host, jsonParsed.String()) + } - if !o.OutputJSONResponse { - o.Printf("Token: %v\n", o.Token) + if !o.OutputJSONResponse { + o.Printf("Token: %v\n", o.Token) + } } loginIdentity := &util.RestClientEdgeIdentity{