diff --git a/cmd/user/add.go b/cmd/user/add.go index 596c27f..9bcda0c 100644 --- a/cmd/user/add.go +++ b/cmd/user/add.go @@ -1,6 +1,7 @@ package user import ( + "errors" "fmt" "log" "strconv" @@ -8,6 +9,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" ldap "gopkg.in/ldap.v2" + + "git.metaunix.net/metaunix.net/muldap/lib/util" ) func init() { @@ -32,6 +35,18 @@ var userAddCmd = &cobra.Command{ Short: "Add an LDAP user to the directory", Long: `Create and add an LDAP user resource to your directory.`, Run: func(cmd *cobra.Command, args []string) { + // chck if a user id was provided + if flagUserUsername == "" { + uidErr := errors.New("You must supply a user ID") + log.Fatal(uidErr) + } + + // check if the provided user id is valid + if util.ContainsString(viper.GetStringSlice("user.uid_reserved"), flagUserUsername) { + uidErr := errors.New("The user ID name that you provided is in the reserved list") + log.Fatal(uidErr) + } + // create new LDAP connection l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", viper.GetString("host"), viper.GetInt("port"))) if err != nil {