github.com/coincircle/mattermost-server@v4.8.1-0.20180321182714-9d701c704416+incompatible/cmd/commands/ldap.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package commands 5 6 import ( 7 "github.com/mattermost/mattermost-server/cmd" 8 "github.com/mattermost/mattermost-server/model" 9 "github.com/spf13/cobra" 10 ) 11 12 var LdapCmd = &cobra.Command{ 13 Use: "ldap", 14 Short: "LDAP related utilities", 15 } 16 17 var LdapSyncCmd = &cobra.Command{ 18 Use: "sync", 19 Short: "Synchronize now", 20 Long: "Synchronize all LDAP users now.", 21 Example: " ldap sync", 22 RunE: ldapSyncCmdF, 23 } 24 25 func init() { 26 LdapCmd.AddCommand( 27 LdapSyncCmd, 28 ) 29 cmd.RootCmd.AddCommand(LdapCmd) 30 } 31 32 func ldapSyncCmdF(command *cobra.Command, args []string) error { 33 a, err := cmd.InitDBCommandContextCobra(command) 34 if err != nil { 35 return err 36 } 37 38 if ldapI := a.Ldap; ldapI != nil { 39 job, err := ldapI.StartSynchronizeJob(true) 40 if err != nil || job.Status == model.JOB_STATUS_ERROR || job.Status == model.JOB_STATUS_CANCELED { 41 cmd.CommandPrintErrorln("ERROR: AD/LDAP Synchronization please check the server logs") 42 } else { 43 cmd.CommandPrettyPrintln("SUCCESS: AD/LDAP Synchronization Complete") 44 } 45 } 46 47 return nil 48 }