<commit_before>// BaruwaAPI Golang bindings for Baruwa REST API
// Copyright (C) 2019 <NAME> <<EMAIL>>

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

// Package api Golang bindings for Baruwa REST API
package api

import (
	"fmt"
	"net/url"

	"github.com/google/go-querystring/query"
)

// LDAPSettings holds Domain LDAP settings
type LDAPSettings struct {
	ID                int    `json:"id,omitempty"`
	Basedn            string `json:"basedn"`
	NameAttribute     string `json:"nameattribute"`
	EmailAttribute    string `json:"emailattribute"`
	BindDN            string `json:"binddn"`
	BindPw            string `json:"bindpw"`
	UseTLS            bool   `json:"usetls"`
	UseSearch         bool   `json:"usesearch"`
	SearchFilter      string `json:"searchfilter"`
	SearchScope       string `json:"search_scope"`
	EmailSearchFilter string `json:"emailsearchfilter"`
	EmailSearchDcope  string `json:"emailsearch_scope"`
}

// GetLDAPSettings returns a domain LDAP settings
// https://www.baruwa.com/docs/api/#retrieve-ad-ldap-settings
func (c *Client) GetLDAPSettings(domainid, serverid, settingsid int) (settings *LDAPSettings, err error) {
	if domainid <= 0 {
		err = fmt.Errorf("The domainid param should be > 0")
		return
	}

	if serverid <= 0 {
		err = fmt.Errorf("The serverid param should be > 0")
		return
	}

	if settingsid <= 0 {
		err = fmt.Errorf("The settingsid param should be > 0")
		return
	}

	err = c.get(fmt.Sprintf("ldapsettings/%d/%d/%d", domainid, serverid, settingsid), settings)

	return
}

// CreateLDAPSettings creates a domain LDAP settings
// https://www.baruwa.com/docs/api/#create-ad-ldap-settings
func (c *Client) CreateLDAPSettings(domainid, serverid int, settings *LDAPSettings) (err error) {
	var v url.Values

	if domainid <= 0 {
		err = fmt.Errorf("The domainid param should be > 0")
		return
	}

	if serverid <= 0 {
		err = fmt.Errorf("The serverid param should be > 0")
		return
	}

	if v, err = query.Values(settings); err != nil {
		return
	}<commit_msg>FIX: Check for null settings<commit_after>// BaruwaAPI Golang bindings for Baruwa REST API
// Copyright (C) 2019 <NAME> <<EMAIL>>

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

// Package api Golang bindings for Baruwa REST API
package api

import (
	"fmt"
	"net/url"

	"github.com/google/go-querystring/query"
)

// LDAPSettings holds Domain LDAP settings
type LDAPSettings struct {
	ID                int    `json:"id,omitempty"`
	Basedn            string `json:"basedn"`
	NameAttribute     string `json:"nameattribute"`
	EmailAttribute    string `json:"emailattribute"`
	BindDN            string `json:"binddn"`
	BindPw            string `json:"bindpw"`
	UseTLS            bool   `json:"usetls"`
	UseSearch         bool   `json:"usesearch"`
	SearchFilter      string `json:"searchfilter"`
	SearchScope       string `json:"search_scope"`
	EmailSearchFilter string `json:"emailsearchfilter"`
	EmailSearchDcope  string `json:"emailsearch_scope"`
}

// GetLDAPSettings returns a domain LDAP settings
// https://www.baruwa.com/docs/api/#retrieve-ad-ldap-settings
func (c *Client) GetLDAPSettings(domainid, serverid, settingsid int) (settings *LDAPSettings, err error) {
	if domainid <= 0 {
		err = fmt.Errorf("The domainid param should be > 0")
		return
	}

	if serverid <= 0 {
		err = fmt.Errorf("The serverid param should be > 0")
		return
	}

	if settingsid <= 0 {
		err = fmt.Errorf("The settingsid param should be > 0")
		return
	}

	err = c.get(fmt.Sprintf("ldapsettings/%d/%d/%d", domainid, serverid, settingsid), settings)

	return
}

// CreateLDAPSettings creates a domain LDAP settings
// https://www.baruwa.com/docs/api/#create-ad-ldap-settings
func (c *Client) CreateLDAPSettings(domainid, serverid int, settings *LDAPSettings) (err error) {
	var v url.Values

	if domainid <= 0 {
		err = fmt.Errorf("The domainid param should be > 0")
		return
	}

	if serverid <= 0 {
		err = fmt.Errorf("The serverid param should be > 0")
		return
	}

	if settings == nil {
		err = fmt.Errorf("The settings param cannot be nil")
		return
	}

	if v, err = query.Values(settings); err != nil {
		return
	}
{'fraction_non_alphanumeric': 0.1191827468785471, 'fraction_numerical': 0.008172531214528945, 'mean_word_length': 3.3884462151394423, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '1523817', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1398, 'n_words': 440}