<commit_before>package vault

import (
	"errors"
	"strings"
)

type LDAPGroup struct {
	Name     string
	Policies []string
}

type LDAPUser struct {
	Name     string
	Policies []string
	Groups   []string
}

func (auth AuthInfo) ListLDAPGroups() ([]LDAPGroup, error) {
	client, err := auth.Client()
	if err != nil {
		return nil, err
	}
	logical := client.Logical()

	resp, err := logical.List("auth/ldap/groups")
	if err != nil {
		return nil, err
	}
	raw, ok := resp.Data["keys"].([]interface{})
	if !ok {
		return nil, errors.New("Failed to fetch LDAP group names")
	}

	// ignore any group names that somehow can't be type asserted to string
	var groups []string
	for _, each := range raw {
		if group, ok := each.(string); ok {
			groups = append(groups, group)
		}
	}

	results := make([]LDAPGroup, len(groups))
	for i, group := range groups {
		results[i] = LDAPGroup{
			Name: group,
		}

		// fetch group's policies
		resp, err := logical.Read("auth/ldap/groups/" + group)
		if err == nil && resp != nil {
			if raw, ok := resp.Data["policies"]; ok {
				if policies, ok := raw.([]string); ok {<commit_msg>Fixed a panic on empty LDAP configs. Fixed #169<commit_after>package vault

import (
	"errors"
	"strings"
)

type LDAPGroup struct {
	Name     string
	Policies []string
}

type LDAPUser struct {
	Name     string
	Policies []string
	Groups   []string
}

func (auth AuthInfo) ListLDAPGroups() ([]LDAPGroup, error) {
	client, err := auth.Client()
	if err != nil {
		return nil, err
	}
	logical := client.Logical()

	resp, err := logical.List("auth/ldap/groups")
	if err != nil {
		return nil, err
	}

	// if there are no ldap groups, return an empty slice
	if _, ok := resp.Data["keys"]; !ok {
		return []LDAPGroup{}, nil
	}

	raw, ok := resp.Data["keys"].([]interface{})
	if !ok {
		return nil, errors.New("Failed to fetch LDAP group names")
	}

	// ignore any group names that somehow can't be type asserted to string
	var groups []string
	for _, each := range raw {
		if group, ok := each.(string); ok {
			groups = append(groups, group)
		}
	}

	results := make([]LDAPGroup, len(groups))
	for i, group := range groups {
		results[i] = LDAPGroup{
			Name: group,
		}

		// fetch group's policies
		resp, err := logical.Read("auth/ldap/groups/" + group)
		if err == nil && resp != nil {
			if raw, ok := resp.Data["policies"]; ok {
				if policies, ok := raw.([]string); ok {
{'fraction_non_alphanumeric': 0.1507537688442211, 'fraction_numerical': 0.001256281407035176, 'mean_word_length': 3.2967625899280577, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1492122', 'n_tokens_mistral': 869, 'n_tokens_neox': 816, 'n_words': 267}