github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/cmd/platform/ldap.go (about)

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