/
groupcreate.go
56 lines (45 loc) · 1.54 KB
/
groupcreate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"github.com/nupplaphil/kopano-ldap/kopano"
"github.com/spf13/cobra"
)
// userCreateCmd represents the usercreate command
var groupCreateCmd = &cobra.Command{
Use: "create",
Short: "Creating an user for Kopano in LDAP.",
Long: `Creating an user for Kopano in LDAP.`,
RunE: func(cmd *cobra.Command, args []string) error {
return runGroupCreate(cmd)
},
}
func init() {
groupCmd.AddCommand(groupCreateCmd)
groupCreateCmd.Flags().StringP("name", "n", "", "The name of the group.")
groupCreateCmd.Flags().BoolP("active", "a", true, "The active state of this group.")
groupCreateCmd.Flags().BoolP("security", "", false, "The active state of this group.")
groupCreateCmd.Flags().BoolP("hidden", "", false, "The active state of this group.")
groupCreateCmd.MarkFlagRequired("name")
}
func runGroupCreate(cmd *cobra.Command) error {
flags := cmd.Flags()
name, _ := flags.GetString("name")
active, _ := flags.GetBool("active")
security, _ := flags.GetBool("security")
hidden, _ := flags.GetBool("hidden")
groupSettings := kopano.NewGroupSettings(name)
groupSettings.Active = active
groupSettings.Security = security
groupSettings.Hidden = hidden
ldapHost, ldapPort, ldapDomain, ldapUser, ldapPW := LdapFlags()
baseDn := kopano.GetBaseDN(ldapDomain)
client, err := kopano.Connect(ldapHost, ldapPort, ldapDomain, ldapUser, ldapPW)
if err != nil {
return err
}
if err := kopano.AddGroup(client, baseDn, groupSettings); err != nil {
return err
} else {
cmd.Printf("group %q successfully created\n", name)
}
return nil
}