[WIP] API refactor (#1737)
* refactor openpitrix API Signed-off-by: hongming <talonwan@yunify.com> * add openpitrix mock client Signed-off-by: hongming <talonwan@yunify.com> * refactor tenant API Signed-off-by: hongming <talonwan@yunify.com> * refactor IAM API Signed-off-by: hongming <talonwan@yunify.com> * refactor IAM API Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
@@ -119,7 +119,7 @@ type ClientSet struct {
|
||||
redisClient cache.Interface
|
||||
s3Client s3.Interface
|
||||
prometheusClient *prometheus.Client
|
||||
openpitrixClient *openpitrix.Client
|
||||
openpitrixClient openpitrix.Client
|
||||
kubesphereClient *kubesphere.Client
|
||||
elasticSearchClient *esclient.ElasticSearchClient
|
||||
}
|
||||
@@ -292,7 +292,7 @@ func (cs *ClientSet) S3() (s3.Interface, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cs *ClientSet) OpenPitrix() (*openpitrix.Client, error) {
|
||||
func (cs *ClientSet) OpenPitrix() (openpitrix.Client, error) {
|
||||
var err error
|
||||
|
||||
if cs.csoptions.openPitrixOptions == nil ||
|
||||
|
||||
@@ -85,7 +85,7 @@ func (c *channelPool) Get() (*PoolConn, error) {
|
||||
return nil, ErrClosed
|
||||
}
|
||||
|
||||
// wrap our connections with our ldap.Client implementation (wrapConn
|
||||
// wrap our connections with our ldap.PoolClient implementation (wrapConn
|
||||
// method) that puts the connection back to the pool if it's closed.
|
||||
select {
|
||||
case conn := <-conns:
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/go-ldap/ldap"
|
||||
)
|
||||
|
||||
// PoolConn implements Client to override the Close() method
|
||||
// PoolConn implements PoolClient to override the Close() method
|
||||
type PoolConn struct {
|
||||
Conn ldap.Client
|
||||
c *channelPool
|
||||
|
||||
@@ -23,13 +23,19 @@ import (
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
type Client interface {
|
||||
NewConn() (ldap.Client, error)
|
||||
GroupSearchBase() string
|
||||
UserSearchBase() string
|
||||
}
|
||||
|
||||
type poolClient struct {
|
||||
pool Pool
|
||||
options *Options
|
||||
}
|
||||
|
||||
// panic if cannot connect to ldap service
|
||||
func NewLdapClient(options *Options, stopCh <-chan struct{}) (*Client, 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 +50,7 @@ func NewLdapClient(options *Options, stopCh <-chan struct{}) (*Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := &Client{
|
||||
client := &poolClient{
|
||||
pool: pool,
|
||||
options: options,
|
||||
}
|
||||
@@ -59,7 +65,7 @@ func NewLdapClient(options *Options, stopCh <-chan struct{}) (*Client, error) {
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (l *Client) NewConn() (ldap.Client, error) {
|
||||
func (l *poolClient) NewConn() (ldap.Client, error) {
|
||||
if l.pool == nil {
|
||||
err := fmt.Errorf("ldap connection pool is not initialized")
|
||||
klog.Errorln(err)
|
||||
@@ -81,10 +87,10 @@ func (l *Client) NewConn() (ldap.Client, error) {
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (l *Client) GroupSearchBase() string {
|
||||
func (l *poolClient) GroupSearchBase() string {
|
||||
return l.options.GroupSearchBase
|
||||
}
|
||||
|
||||
func (l *Client) UserSearchBase() string {
|
||||
func (l *poolClient) UserSearchBase() string {
|
||||
return l.options.UserSearchBase
|
||||
}
|
||||
|
||||
2017
pkg/simple/client/openpitrix/mock.go
Normal file
2017
pkg/simple/client/openpitrix/mock.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -30,16 +30,17 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
KubernetesProvider = "kubernetes"
|
||||
Unknown = "-"
|
||||
DeploySuffix = "-Deployment"
|
||||
DaemonSuffix = "-DaemonSet"
|
||||
StateSuffix = "-StatefulSet"
|
||||
SystemUsername = "system"
|
||||
SystemUserPath = ":system"
|
||||
RuntimeAnnotationKey = "openpitrix_runtime"
|
||||
KubernetesProvider = "kubernetes"
|
||||
Unknown = "-"
|
||||
DeploySuffix = "-Deployment"
|
||||
DaemonSuffix = "-DaemonSet"
|
||||
StateSuffix = "-StatefulSet"
|
||||
SystemUsername = "system"
|
||||
SystemUserPath = ":system"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
type Client interface {
|
||||
pb.RuntimeManagerClient
|
||||
pb.ClusterManagerClient
|
||||
pb.AppManagerClient
|
||||
@@ -49,14 +50,14 @@ type Interface interface {
|
||||
pb.RepoIndexerClient
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
runtime pb.RuntimeManagerClient
|
||||
cluster pb.ClusterManagerClient
|
||||
app pb.AppManagerClient
|
||||
repo pb.RepoManagerClient
|
||||
category pb.CategoryManagerClient
|
||||
attachment pb.AttachmentManagerClient
|
||||
repoIndexer pb.RepoIndexerClient
|
||||
type client struct {
|
||||
pb.RuntimeManagerClient
|
||||
pb.ClusterManagerClient
|
||||
pb.AppManagerClient
|
||||
pb.RepoManagerClient
|
||||
pb.CategoryManagerClient
|
||||
pb.AttachmentManagerClient
|
||||
pb.RepoIndexerClient
|
||||
}
|
||||
|
||||
func parseToHostPort(endpoint string) (string, int, error) {
|
||||
@@ -133,7 +134,7 @@ func newAppManagerClient(endpoint string) (pb.AppManagerClient, error) {
|
||||
return pb.NewAppManagerClient(conn), nil
|
||||
}
|
||||
|
||||
func NewOpenPitrixClient(options *Options) (*Client, error) {
|
||||
func NewOpenPitrixClient(options *Options) (Client, error) {
|
||||
|
||||
runtimeMangerClient, err := newRuntimeManagerClient(options.RuntimeManagerEndpoint)
|
||||
|
||||
@@ -184,42 +185,18 @@ func NewOpenPitrixClient(options *Options) (*Client, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := Client{
|
||||
runtime: runtimeMangerClient,
|
||||
cluster: clusterManagerClient,
|
||||
repo: repoManagerClient,
|
||||
app: appManagerClient,
|
||||
category: categoryManagerClient,
|
||||
attachment: attachmentManagerClient,
|
||||
repoIndexer: repoIndexerClient,
|
||||
client := client{
|
||||
RuntimeManagerClient: runtimeMangerClient,
|
||||
ClusterManagerClient: clusterManagerClient,
|
||||
RepoManagerClient: repoManagerClient,
|
||||
AppManagerClient: appManagerClient,
|
||||
CategoryManagerClient: categoryManagerClient,
|
||||
AttachmentManagerClient: attachmentManagerClient,
|
||||
RepoIndexerClient: repoIndexerClient,
|
||||
}
|
||||
|
||||
return &client, nil
|
||||
}
|
||||
func (c *Client) Runtime() pb.RuntimeManagerClient {
|
||||
return c.runtime
|
||||
}
|
||||
func (c *Client) App() pb.AppManagerClient {
|
||||
return c.app
|
||||
}
|
||||
func (c *Client) Cluster() pb.ClusterManagerClient {
|
||||
return c.cluster
|
||||
}
|
||||
func (c *Client) Category() pb.CategoryManagerClient {
|
||||
return c.category
|
||||
}
|
||||
|
||||
func (c *Client) Repo() pb.RepoManagerClient {
|
||||
return c.repo
|
||||
}
|
||||
|
||||
func (c *Client) RepoIndexer() pb.RepoIndexerClient {
|
||||
return c.repoIndexer
|
||||
}
|
||||
|
||||
func (c *Client) Attachment() pb.AttachmentManagerClient {
|
||||
return c.attachment
|
||||
}
|
||||
|
||||
func SystemContext() context.Context {
|
||||
ctx := context.Background()
|
||||
Reference in New Issue
Block a user