-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- list all rules in tenant
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func rulesCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "rules", | ||
Short: "manage rules for clients.", | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(listRulesCmd(cli)) | ||
return cmd | ||
} | ||
|
||
func listRulesCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists your rules", | ||
Long: `Lists the rules in your current tenant.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
rules, err := cli.api.Client.Rule.List() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
cli.renderer.RulesList(rules) | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package display | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
type ruleView struct { | ||
rule management.Rule | ||
} | ||
|
||
func (v *ruleView) AsTableHeader() []string { | ||
return []string{"Id", "Name", "Status", "Order"} | ||
} | ||
|
||
func (v *ruleView) AsTableRow() []string { | ||
return []string{*v.rule.ID, *v.rule.Name, isEnabled(*v.rule.Enabled), fmt.Sprintf("%d", *v.rule.Order)} | ||
} | ||
|
||
func isEnabled(value bool) string { | ||
if value { | ||
return "True" | ||
} | ||
return "False" | ||
} | ||
|
||
func (r *Renderer) RulesList(ruleList *management.RuleList) { | ||
r.Heading(ansi.Bold(r.Tenant), "rules\n") | ||
var res []View | ||
|
||
//@TODO Provide sort options via flags | ||
sort.Slice(ruleList.Rules, func(i, j int) bool { | ||
return ruleList.Rules[i].GetOrder() < ruleList.Rules[j].GetOrder() | ||
}) | ||
|
||
for _, rule := range ruleList.Rules { | ||
res = append(res, &ruleView{ | ||
rule: *rule, | ||
}) | ||
} | ||
|
||
r.Results(res) | ||
|
||
} |