Skip to content

Commit

Permalink
Merge pull request #2448 from openziti/cli-fixes
Browse files Browse the repository at this point in the history
cli fixes
  • Loading branch information
plorenz authored Sep 30, 2024
2 parents 81639b7 + bc505b0 commit 6dfaa9b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ziti/cmd/edge/create_edge_router_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/edge/create_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newCreateServiceCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Use: "service <name>",
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
Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/edge/create_service_edge_router_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/edge/create_service_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/edge/create_terminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions ziti/cmd/edge/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.<tagName> 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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{},
}

Expand Down Expand Up @@ -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{},
}

Expand Down Expand Up @@ -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{},
}

Expand Down Expand Up @@ -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{},
}

Expand Down
30 changes: 16 additions & 14 deletions ziti/cmd/edge/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6dfaa9b

Please sign in to comment.