func()

in groups/service.go [269:306]


func (as *adminService) DeleteGroupsIfNecessary() error {
	g, err := as.client.ListGroups()
	if err != nil {
		return fmt.Errorf("unable to retrieve users in domain: %w", err)
	}

	// aggregate the errors that occured and return them together in the end.
	var errs []error

	for _, g := range g.Groups {
		found := false
		for _, g2 := range groupsConfig.Groups {
			if EmailAddressEquals(g2.EmailId, g.Email) {
				found = true
				break
			}
		}
		if found {
			continue
		}

		// We did not find the group in our groups.xml, so delete the group
		if config.ConfirmChanges {
			log.Printf("Deleting group %s", g.Email)
			err := as.client.DeleteGroup(g.Email)
			if err != nil {
				errs = append(errs, fmt.Errorf("unable to remove group %s : %w", g.Email, err))
				continue
			}
			log.Printf("Removed group %s\n", g.Email)
		} else {
			log.Printf("dry-run: would remove group %s\n", g.Email)
		}

	}

	return utilerrors.NewAggregate(errs)
}