-
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.
- Loading branch information
Showing
3 changed files
with
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"github.com/spf13/cobra" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
func rolesCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "roles", | ||
Short: "Manage resources for roles", | ||
Long: "Manage resources for roles.", | ||
Aliases: []string{"role"}, | ||
} | ||
|
||
cmd.SetUsageTemplate(resourceUsageTemplate()) | ||
cmd.AddCommand(listRolesCmd(cli)) | ||
|
||
return cmd | ||
} | ||
|
||
func listRolesCmd(cli *cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Aliases: []string{"ls"}, | ||
Args: cobra.NoArgs, | ||
Short: "List your roles", | ||
Long: `List your existing roles. To create one try: | ||
auth0 roles create`, | ||
Example: `auth0 roles list | ||
auth0 roles ls`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var list *management.RoleList | ||
|
||
if err := ansi.Waiting(func() error { | ||
var err error | ||
list, err = cli.api.Role.List() | ||
return err | ||
}); err != nil { | ||
return fmt.Errorf("An unexpected error occurred: %w", err) | ||
} | ||
|
||
cli.renderer.RoleList(list.Roles) | ||
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
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,75 @@ | ||
package display | ||
|
||
import ( | ||
"github.com/auth0/auth0-cli/internal/ansi" | ||
"github.com/auth0/auth0-cli/internal/auth0" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
type roleView struct { | ||
Name string | ||
ID string | ||
Description string | ||
} | ||
|
||
func (v *roleView) AsTableHeader() []string { | ||
return []string{"Name", "Role ID", "Description"} | ||
} | ||
|
||
func (v *roleView) AsTableRow() []string { | ||
return []string{ | ||
v.Name, | ||
ansi.Faint(v.ID), | ||
v.Description, | ||
} | ||
} | ||
|
||
func (r *Renderer) RoleList(roles []*management.Role) { | ||
resource := "roles" | ||
|
||
r.Heading(resource) | ||
|
||
if len(roles) == 0 { | ||
r.EmptyState(resource) | ||
r.Infof("Use 'auth0 roles create' to add one") | ||
return | ||
} | ||
|
||
var res []View | ||
for _, role := range roles { | ||
res = append(res, &roleView{ | ||
Name: role.GetName(), | ||
ID: role.GetID(), | ||
Description: role.GetDescription(), | ||
}) | ||
} | ||
|
||
r.Results(res) | ||
} | ||
|
||
func (r *Renderer) RoleGet(role *management.Role) { | ||
r.Heading(ansi.Bold(r.Tenant), "role\n") | ||
r.Results([]View{&roleView{ | ||
Name: auth0.StringValue(role.Name), | ||
ID: auth0.StringValue(role.ID), | ||
Description: auth0.StringValue(role.Description), | ||
}}) | ||
} | ||
|
||
func (r *Renderer) RoleUpdate(role *management.Role) { | ||
r.Heading(ansi.Bold(r.Tenant), "role\n") | ||
r.Results([]View{&roleView{ | ||
Name: auth0.StringValue(role.Name), | ||
ID: auth0.StringValue(role.ID), | ||
Description: auth0.StringValue(role.Description), | ||
}}) | ||
} | ||
|
||
func (r *Renderer) RoleCreate(role *management.Role) { | ||
r.Heading(ansi.Bold(r.Tenant), "role\n") | ||
r.Results([]View{&roleView{ | ||
Name: auth0.StringValue(role.Name), | ||
ID: auth0.StringValue(role.ID), | ||
Description: auth0.StringValue(role.Description), | ||
}}) | ||
} |