
Change-Id: Ifa8cc0e4abb798c63c9d4ac9297e3e32443125e4 Implements: blueprint auth-controller-framework Signed-off-by: mozhuli <21621232@zju.edu.cn>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package auth
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
|
"k8s.io/client-go/dynamic"
|
|
"k8s.io/client-go/pkg/api"
|
|
"k8s.io/client-go/rest"
|
|
)
|
|
|
|
const (
|
|
TPRGroup = "stackube.kubernetes.io"
|
|
TPRVersion = "v1"
|
|
)
|
|
|
|
type AuthInterface interface {
|
|
RESTClient() rest.Interface
|
|
TenantsGetter
|
|
//TODO: add networkgetter
|
|
}
|
|
|
|
type AuthClient struct {
|
|
restClient rest.Interface
|
|
dynamicClient *dynamic.Client
|
|
}
|
|
|
|
func (c *AuthClient) Tenants(namespace string) TenantInterface {
|
|
return newTenants(c.restClient, c.dynamicClient, namespace)
|
|
}
|
|
|
|
func (c *AuthClient) RESTClient() rest.Interface {
|
|
return c.restClient
|
|
}
|
|
|
|
func NewForConfig(c *rest.Config) (*AuthClient, error) {
|
|
config := *c
|
|
setConfigDefaults(&config)
|
|
client, err := rest.RESTClientFor(&config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
dynamicClient, err := dynamic.NewClient(&config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &AuthClient{client, dynamicClient}, nil
|
|
}
|
|
|
|
func setConfigDefaults(config *rest.Config) {
|
|
config.GroupVersion = &schema.GroupVersion{
|
|
Group: TPRGroup,
|
|
Version: TPRVersion,
|
|
}
|
|
config.APIPath = "/apis"
|
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
|
return
|
|
}
|