devlopment branch (#1736)

This commit is contained in:
zryfish
2020-01-02 20:52:00 +08:00
committed by GitHub
parent ff0ffe8650
commit eceadec69c
440 changed files with 61524 additions and 3699 deletions

View File

@@ -23,13 +23,13 @@ import (
"k8s.io/klog"
)
type LdapClient struct {
type Client struct {
pool Pool
options *LdapOptions
options *Options
}
// panic if cannot connect to ldap service
func NewLdapClient(options *LdapOptions, stopCh <-chan struct{}) (*LdapClient, error) {
func NewLdapClient(options *Options, stopCh <-chan struct{}) (*Client, error) {
pool, err := NewChannelPool(8, 64, "kubesphere", func(s string) (ldap.Client, error) {
conn, err := ldap.Dial("tcp", options.Host)
if err != nil {
@@ -44,7 +44,7 @@ func NewLdapClient(options *LdapOptions, stopCh <-chan struct{}) (*LdapClient, e
return nil, err
}
client := &LdapClient{
client := &Client{
pool: pool,
options: options,
}
@@ -59,7 +59,7 @@ func NewLdapClient(options *LdapOptions, stopCh <-chan struct{}) (*LdapClient, e
return client, nil
}
func (l *LdapClient) NewConn() (ldap.Client, error) {
func (l *Client) NewConn() (ldap.Client, error) {
if l.pool == nil {
err := fmt.Errorf("ldap connection pool is not initialized")
klog.Errorln(err)
@@ -81,10 +81,10 @@ func (l *LdapClient) NewConn() (ldap.Client, error) {
return conn, nil
}
func (l *LdapClient) GroupSearchBase() string {
func (l *Client) GroupSearchBase() string {
return l.options.GroupSearchBase
}
func (l *LdapClient) UserSearchBase() string {
func (l *Client) UserSearchBase() string {
return l.options.UserSearchBase
}

View File

@@ -5,7 +5,7 @@ import (
"kubesphere.io/kubesphere/pkg/utils/reflectutils"
)
type LdapOptions struct {
type Options struct {
Host string `json:"host,omitempty" yaml:"host"`
ManagerDN string `json:"managerDN,omitempty" yaml:"managerDN"`
ManagerPassword string `json:"managerPassword,omitempty" yaml:"managerPassword"`
@@ -15,8 +15,8 @@ type LdapOptions struct {
// NewLdapOptions return a default option
// which host field point to nowhere.
func NewLdapOptions() *LdapOptions {
return &LdapOptions{
func NewLdapOptions() *Options {
return &Options{
Host: "",
ManagerDN: "cn=admin,dc=example,dc=org",
UserSearchBase: "ou=Users,dc=example,dc=org",
@@ -24,32 +24,32 @@ func NewLdapOptions() *LdapOptions {
}
}
func (l *LdapOptions) Validate() []error {
func (l *Options) Validate() []error {
errors := []error{}
return errors
}
func (l *LdapOptions) ApplyTo(options *LdapOptions) {
func (l *Options) ApplyTo(options *Options) {
if l.Host != "" {
reflectutils.Override(options, l)
}
}
func (l *LdapOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&l.Host, "ldap-host", l.Host, ""+
func (l *Options) AddFlags(fs *pflag.FlagSet, s *Options) {
fs.StringVar(&l.Host, "ldap-host", s.Host, ""+
"Ldap service host, if left blank, all of the following ldap options will "+
"be ignored and ldap will be disabled.")
fs.StringVar(&l.ManagerDN, "ldap-manager-dn", l.ManagerDN, ""+
fs.StringVar(&l.ManagerDN, "ldap-manager-dn", s.ManagerDN, ""+
"Ldap manager account domain name.")
fs.StringVar(&l.ManagerPassword, "ldap-manager-password", l.ManagerPassword, ""+
fs.StringVar(&l.ManagerPassword, "ldap-manager-password", s.ManagerPassword, ""+
"Ldap manager account password.")
fs.StringVar(&l.UserSearchBase, "ldap-user-search-base", l.UserSearchBase, ""+
fs.StringVar(&l.UserSearchBase, "ldap-user-search-base", s.UserSearchBase, ""+
"Ldap user search base.")
fs.StringVar(&l.GroupSearchBase, "ldap-group-search-base", l.GroupSearchBase, ""+
fs.StringVar(&l.GroupSearchBase, "ldap-group-search-base", s.GroupSearchBase, ""+
"Ldap group search base.")
}