-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NET-1227: User Cli cmds Update (#3064)
* generalise smtp config * copy over smtp vars * env new line * fix master key api access * comment user tests * fix network and user invite for master key access * remove email sender type * user mgmt commands * check user role on CE * user role nmtcl cmds * user groups commands * fix role and groups command * fix user create cmd * add usage info * rm user role check * fix user update cmd * fix static check
- Loading branch information
1 parent
1924da2
commit 5a4d066
Showing
9 changed files
with
356 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package user | ||
|
||
var ( | ||
username string | ||
password string | ||
admin bool | ||
networks string | ||
groups string | ||
username string | ||
password string | ||
platformID string | ||
admin bool | ||
networkRoles map[string]string | ||
groups []string | ||
) |
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,118 @@ | ||
package user | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/gravitl/netmaker/cli/cmd/commons" | ||
"github.com/gravitl/netmaker/cli/functions" | ||
"github.com/guumaster/tablewriter" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var userGroupCmd = &cobra.Command{ | ||
Use: "group", | ||
Args: cobra.NoArgs, | ||
Short: "Manage User Groups", | ||
Long: `Manage User Groups`, | ||
} | ||
|
||
var userGroupListCmd = &cobra.Command{ | ||
Use: "list", | ||
Args: cobra.NoArgs, | ||
Short: "List all user groups", | ||
Long: `List all user groups`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
data := functions.ListUserGrps() | ||
switch commons.OutputFormat { | ||
case commons.JsonOutput: | ||
functions.PrettyPrint(data) | ||
default: | ||
table := tablewriter.NewWriter(os.Stdout) | ||
h := []string{"ID", "MetaData", "Network Roles"} | ||
table.SetHeader(h) | ||
for _, d := range data { | ||
|
||
roleInfoStr := "" | ||
for netID, netRoleMap := range d.NetworkRoles { | ||
roleList := []string{} | ||
for roleID := range netRoleMap { | ||
roleList = append(roleList, roleID.String()) | ||
} | ||
roleInfoStr += fmt.Sprintf("[%s]: %s", netID, strings.Join(roleList, ",")) | ||
} | ||
e := []string{d.ID.String(), d.MetaData, roleInfoStr} | ||
table.Append(e) | ||
} | ||
table.Render() | ||
} | ||
}, | ||
} | ||
|
||
var userGroupCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Args: cobra.NoArgs, | ||
Short: "create user group", | ||
Long: `create user group`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("CLI doesn't support creation of groups currently. Visit the dashboard to create one or refer to our api documentation https://docs.v2.netmaker.io/reference") | ||
}, | ||
} | ||
|
||
var userGroupDeleteCmd = &cobra.Command{ | ||
Use: "delete [groupID]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "delete user group", | ||
Long: `delete user group`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
resp := functions.DeleteUserGrp(args[0]) | ||
if resp != nil { | ||
fmt.Println(resp.Message) | ||
} | ||
}, | ||
} | ||
|
||
var userGroupGetCmd = &cobra.Command{ | ||
Use: "get [groupID]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "get user group", | ||
Long: `get user group`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
data := functions.GetUserGrp(args[0]) | ||
switch commons.OutputFormat { | ||
case commons.JsonOutput: | ||
functions.PrettyPrint(data) | ||
default: | ||
table := tablewriter.NewWriter(os.Stdout) | ||
h := []string{"ID", "MetaData", "Network Roles"} | ||
table.SetHeader(h) | ||
roleInfoStr := "" | ||
for netID, netRoleMap := range data.NetworkRoles { | ||
roleList := []string{} | ||
for roleID := range netRoleMap { | ||
roleList = append(roleList, roleID.String()) | ||
} | ||
roleInfoStr += fmt.Sprintf("[%s]: %s", netID, strings.Join(roleList, ",")) | ||
} | ||
e := []string{data.ID.String(), data.MetaData, roleInfoStr} | ||
table.Append(e) | ||
table.Render() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(userGroupCmd) | ||
// list roles cmd | ||
userGroupCmd.AddCommand(userGroupListCmd) | ||
|
||
// create roles cmd | ||
userGroupCmd.AddCommand(userGroupCreateCmd) | ||
|
||
// delete role cmd | ||
userGroupCmd.AddCommand(userGroupDeleteCmd) | ||
|
||
// Get Role | ||
userGroupCmd.AddCommand(userGroupGetCmd) | ||
} |
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,121 @@ | ||
package user | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/gravitl/netmaker/cli/cmd/commons" | ||
"github.com/gravitl/netmaker/cli/functions" | ||
"github.com/guumaster/tablewriter" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var userRoleCmd = &cobra.Command{ | ||
Use: "role", | ||
Args: cobra.NoArgs, | ||
Short: "Manage User Roles", | ||
Long: `Manage User Roles`, | ||
} | ||
|
||
// List Roles | ||
var ( | ||
platformRoles bool | ||
) | ||
var userRoleListCmd = &cobra.Command{ | ||
Use: "list", | ||
Args: cobra.NoArgs, | ||
Short: "List all user roles", | ||
Long: `List all user roles`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
data := functions.ListUserRoles() | ||
switch commons.OutputFormat { | ||
case commons.JsonOutput: | ||
functions.PrettyPrint(data) | ||
default: | ||
table := tablewriter.NewWriter(os.Stdout) | ||
h := []string{"ID", "Default", "Dashboard Access", "Full Access"} | ||
|
||
if !platformRoles { | ||
h = append(h, "Network") | ||
} | ||
table.SetHeader(h) | ||
for _, d := range data { | ||
e := []string{d.ID.String(), strconv.FormatBool(d.Default), strconv.FormatBool(d.DenyDashboardAccess), strconv.FormatBool(d.FullAccess)} | ||
if !platformRoles { | ||
e = append(e, d.NetworkID.String()) | ||
} | ||
table.Append(e) | ||
} | ||
table.Render() | ||
} | ||
}, | ||
} | ||
|
||
var userRoleCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Args: cobra.NoArgs, | ||
Short: "create user role", | ||
Long: `create user role`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("CLI doesn't support creation of roles currently. Visit the dashboard to create one or refer to our api documentation https://docs.v2.netmaker.io/reference") | ||
}, | ||
} | ||
|
||
var userRoleDeleteCmd = &cobra.Command{ | ||
Use: "delete [roleID]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "delete user role", | ||
Long: `delete user role`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
resp := functions.DeleteUserRole(args[0]) | ||
if resp != nil { | ||
fmt.Println(resp.Message) | ||
} | ||
}, | ||
} | ||
|
||
var userRoleGetCmd = &cobra.Command{ | ||
Use: "get [roleID]", | ||
Args: cobra.ExactArgs(1), | ||
Short: "get user role", | ||
Long: `get user role`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
d := functions.GetUserRole(args[0]) | ||
switch commons.OutputFormat { | ||
case commons.JsonOutput: | ||
functions.PrettyPrint(d) | ||
default: | ||
table := tablewriter.NewWriter(os.Stdout) | ||
h := []string{"ID", "Default Role", "Dashboard Access", "Full Access"} | ||
|
||
if d.NetworkID != "" { | ||
h = append(h, "Network") | ||
} | ||
table.SetHeader(h) | ||
e := []string{d.ID.String(), strconv.FormatBool(d.Default), strconv.FormatBool(!d.DenyDashboardAccess), strconv.FormatBool(d.FullAccess)} | ||
if !platformRoles { | ||
e = append(e, d.NetworkID.String()) | ||
} | ||
table.Append(e) | ||
table.Render() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(userRoleCmd) | ||
// list roles cmd | ||
userRoleListCmd.Flags().BoolVar(&platformRoles, "platform-roles", true, | ||
"set to false to list network roles. By default it will only list platform roles") | ||
userRoleCmd.AddCommand(userRoleListCmd) | ||
|
||
// create roles cmd | ||
userRoleCmd.AddCommand(userRoleCreateCmd) | ||
|
||
// delete role cmd | ||
userRoleCmd.AddCommand(userRoleDeleteCmd) | ||
|
||
// Get Role | ||
userRoleCmd.AddCommand(userRoleGetCmd) | ||
} |
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
Oops, something went wrong.