options.go 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
package ldap

import (
	"github.com/spf13/pflag"
	"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)

type LdapOptions struct {
	Host            string `json:"host,omitempty" yaml:"host,omitempty"`
	ManagerDN       string `json:"managerDN,omitempty" yaml:"managerDN,omitempty"`
	ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword,omitempty"`
	UserSearchBase  string `json:"userSearchBase,omitempty" yaml:"userSearchBase,omitempty"`
	GroupSearchBase string `json:"groupSearchBase,omitempty" yaml:"groupSearchBase,omitempty"`
}

// NewLdapOptions return a default option
// which host field point to nowhere.
func NewLdapOptions() *LdapOptions {
	return &LdapOptions{
		Host:            "",
		ManagerDN:       "cn=admin,dc=example,dc=org",
		UserSearchBase:  "ou=Users,dc=example,dc=org",
		GroupSearchBase: "ou=Groups,dc=example,dc=org",
	}
}

func (l *LdapOptions) Validate() []error {
	errors := []error{}

	return errors
}

func (l *LdapOptions) ApplyTo(options *LdapOptions) {
J
Jeff 已提交
34 35 36 37 38
	if options == nil {
		options = l
		return
	}

J
Jeff 已提交
39 40 41
	if l.Host != "" {
		reflectutils.Override(options, l)
	}
42 43 44 45
}

func (l *LdapOptions) AddFlags(fs *pflag.FlagSet) {
	fs.StringVar(&l.Host, "ldap-host", l.Host, ""+
J
Jeff 已提交
46
		"Ldap service host, if left blank, all of the following ldap options will "+
47 48 49 50 51 52 53 54 55 56 57 58 59 60
		"be ignored and ldap will be disabled.")

	fs.StringVar(&l.ManagerDN, "ldap-manager-dn", l.ManagerDN, ""+
		"Ldap manager account domain name.")

	fs.StringVar(&l.ManagerPassword, "ldap-manager-password", l.ManagerPassword, ""+
		"Ldap manager account password.")

	fs.StringVar(&l.UserSearchBase, "ldap-user-search-base", l.UserSearchBase, ""+
		"Ldap user search base.")

	fs.StringVar(&l.GroupSearchBase, "ldap-group-search-base", l.GroupSearchBase, ""+
		"Ldap group search base.")
}