Exemplo n.º 1
0
func syncVCtoAD() {
	l, err := initLdap()
	if err != nil {
		status.Set("LDAP_CONN_FAILURE")
		log.Println("ERROR: %s\n", err.Error())
	}
	defer l.Close()

	// debug sets ldap to debug mode.
	if debug {
		l.Debug = true
	}

	// Create a new client with the above configuration.
	client := vcapi.NewClient(config)

	// Number of goroutines for wait group
	years := graduationYear - time.Now().Year()
	wg.Add(years + 2)
	log.Println("Checking VC and AD for changes.")

	// Enable all current students LDAP accounts
	go enableCurrentStudents(client, l)

	// Loop through all former students and disable LDAP accounts
	for y := graduationYear; y >= time.Now().Year(); y-- {
		go disableFormerStudents(client, l, y)
	}

	// wait for goroutines to sync up
	wg.Wait()
	status.Set("OK")
}
Exemplo n.º 2
0
func (a VeracrossAPI) getRotation(date *time.Time) (*vcapi.RotationDays, error) {
	config := &vcapi.Config{
		Username:   a.Username, // API Username
		Password:   a.Password, // API Password
		SchoolID:   a.Client,   // Client, school name
		APIVersion: "v2",
	}
	from := date.Format(vcapi.VCTimeFormat)
	to := date.Add(24 * time.Hour).Format(vcapi.VCTimeFormat)
	client := vcapi.NewClient(config)
	opt := &vcapi.ListOptions{
		Params: vcapi.Params{
			"date_from": from,
			"date_to":   to,
		}}
	day, err := client.RotationDays.List(opt)
	if err != nil {
		return nil, err
	}
	return &day[0], nil
}