|
@@ -1,6 +1,8 @@
|
|
package user
|
|
package user
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "strings"
|
|
|
|
+
|
|
"github.com/gravitl/netmaker/cli/functions"
|
|
"github.com/gravitl/netmaker/cli/functions"
|
|
"github.com/gravitl/netmaker/models"
|
|
"github.com/gravitl/netmaker/models"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
@@ -12,18 +14,41 @@ var userCreateCmd = &cobra.Command{
|
|
Short: "Create a new user",
|
|
Short: "Create a new user",
|
|
Long: `Create a new user`,
|
|
Long: `Create a new user`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
- user := &models.User{UserName: username, Password: password, IsAdmin: admin}
|
|
|
|
|
|
+ user := &models.User{UserName: username, Password: password, PlatformRoleID: models.UserRoleID(platformID)}
|
|
|
|
+ if len(networkRoles) > 0 {
|
|
|
|
+ netRolesMap := make(map[models.NetworkID]map[models.UserRoleID]struct{})
|
|
|
|
+ for netID, netRoles := range networkRoles {
|
|
|
|
+ roleMap := make(map[models.UserRoleID]struct{})
|
|
|
|
+ for _, roleID := range strings.Split(netRoles, ",") {
|
|
|
|
+ roleMap[models.UserRoleID(roleID)] = struct{}{}
|
|
|
|
+ }
|
|
|
|
+ netRolesMap[models.NetworkID(netID)] = roleMap
|
|
|
|
+ }
|
|
|
|
+ user.NetworkRoles = netRolesMap
|
|
|
|
+ }
|
|
|
|
+ if len(groups) > 0 {
|
|
|
|
+ grMap := make(map[models.UserGroupID]struct{})
|
|
|
|
+ for _, groupID := range groups {
|
|
|
|
+ grMap[models.UserGroupID(groupID)] = struct{}{}
|
|
|
|
+ }
|
|
|
|
+ user.UserGroups = grMap
|
|
|
|
+ }
|
|
|
|
+
|
|
functions.PrettyPrint(functions.CreateUser(user))
|
|
functions.PrettyPrint(functions.CreateUser(user))
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
|
|
+
|
|
userCreateCmd.Flags().StringVar(&username, "name", "", "Name of the user")
|
|
userCreateCmd.Flags().StringVar(&username, "name", "", "Name of the user")
|
|
userCreateCmd.Flags().StringVar(&password, "password", "", "Password of the user")
|
|
userCreateCmd.Flags().StringVar(&password, "password", "", "Password of the user")
|
|
|
|
+ userCreateCmd.Flags().StringVarP(&platformID, "platform-id", "r", models.ServiceUser.String(),
|
|
|
|
+ "Platform Role of the user; run `nmctl roles list` to see available user roles")
|
|
userCreateCmd.MarkFlagRequired("name")
|
|
userCreateCmd.MarkFlagRequired("name")
|
|
userCreateCmd.MarkFlagRequired("password")
|
|
userCreateCmd.MarkFlagRequired("password")
|
|
- userCreateCmd.Flags().BoolVar(&admin, "admin", false, "Make the user an admin ?")
|
|
|
|
- userCreateCmd.Flags().StringVar(&networks, "networks", "", "List of networks the user will access to (comma separated)")
|
|
|
|
- userCreateCmd.Flags().StringVar(&groups, "groups", "", "List of user groups the user will be part of (comma separated)")
|
|
|
|
|
|
+ userCreateCmd.PersistentFlags().StringToStringVarP(&networkRoles, "network-roles", "n", make(map[string]string),
|
|
|
|
+ "Mapping of networkID and list of roles user will be part of (comma separated)")
|
|
|
|
+ userCreateCmd.Flags().BoolVar(&admin, "admin", false, "Make the user an admin ? (deprecated v0.25.0 onwards)")
|
|
|
|
+ userCreateCmd.Flags().StringArrayVarP(&groups, "groups", "g", nil, "List of user groups the user will be part of (comma separated)")
|
|
rootCmd.AddCommand(userCreateCmd)
|
|
rootCmd.AddCommand(userCreateCmd)
|
|
}
|
|
}
|