mirror of
https://github.com/niusmallnan/steve.git
synced 2025-06-26 14:41:35 +00:00
Add apigroups
This commit is contained in:
parent
de50acc048
commit
59a6ee577e
71
pkg/resources/apigroups/apigroup.go
Normal file
71
pkg/resources/apigroups/apigroup.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package apigroups
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rancher/norman/pkg/data"
|
||||||
|
"github.com/rancher/norman/pkg/store/empty"
|
||||||
|
"github.com/rancher/norman/pkg/types"
|
||||||
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/client-go/discovery"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register(schemas *types.Schemas, discovery discovery.DiscoveryInterface) {
|
||||||
|
schemas.MustImportAndCustomize(v1.APIGroup{}, func(schema *types.Schema) {
|
||||||
|
schema.CollectionMethods = []string{http.MethodGet}
|
||||||
|
schema.ResourceMethods = []string{http.MethodGet}
|
||||||
|
schema.Store = NewStore(discovery)
|
||||||
|
schema.Formatter = func(request *types.APIRequest, resource *types.RawResource) {
|
||||||
|
resource.ID = data.Object(resource.Values).String("name")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type Store struct {
|
||||||
|
empty.Store
|
||||||
|
|
||||||
|
discovery discovery.DiscoveryInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStore(discovery discovery.DiscoveryInterface) types.Store {
|
||||||
|
return &Store{
|
||||||
|
Store: empty.Store{},
|
||||||
|
discovery: discovery,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Store) ByID(apiOp *types.APIRequest, schema *types.Schema, id string) (types.APIObject, error) {
|
||||||
|
groupList, err := e.discovery.ServerGroups()
|
||||||
|
if err != nil {
|
||||||
|
return types.APIObject{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if id == "core" {
|
||||||
|
id = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, group := range groupList.Groups {
|
||||||
|
if group.Name == id {
|
||||||
|
return types.ToAPI(group), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.APIObject{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Store) List(apiOp *types.APIRequest, schema *types.Schema, opt *types.QueryOptions) (types.APIObject, error) {
|
||||||
|
groupList, err := e.discovery.ServerGroups()
|
||||||
|
if err != nil {
|
||||||
|
return types.APIObject{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result []interface{}
|
||||||
|
for _, item := range groupList.Groups {
|
||||||
|
if item.Name == "" {
|
||||||
|
item.Name = "core"
|
||||||
|
}
|
||||||
|
result = append(result, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.ToAPI(result), nil
|
||||||
|
}
|
@ -2,20 +2,23 @@ package resources
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rancher/naok/pkg/accesscontrol"
|
"github.com/rancher/naok/pkg/accesscontrol"
|
||||||
|
"github.com/rancher/naok/pkg/resources/apigroups"
|
||||||
"github.com/rancher/naok/pkg/resources/common"
|
"github.com/rancher/naok/pkg/resources/common"
|
||||||
"github.com/rancher/naok/pkg/resources/counts"
|
"github.com/rancher/naok/pkg/resources/counts"
|
||||||
"github.com/rancher/naok/pkg/resources/schema"
|
"github.com/rancher/naok/pkg/resources/schema"
|
||||||
"github.com/rancher/norman/pkg/store/proxy"
|
"github.com/rancher/norman/pkg/store/proxy"
|
||||||
"github.com/rancher/norman/pkg/subscribe"
|
"github.com/rancher/norman/pkg/subscribe"
|
||||||
"github.com/rancher/norman/pkg/types"
|
"github.com/rancher/norman/pkg/types"
|
||||||
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SchemaFactory(getter proxy.ClientGetter, as *accesscontrol.AccessStore) *schema.Collection {
|
func SchemaFactory(getter proxy.ClientGetter, as *accesscontrol.AccessStore, k8s kubernetes.Interface) *schema.Collection {
|
||||||
baseSchema := types.EmptySchemas()
|
baseSchema := types.EmptySchemas()
|
||||||
collection := schema.NewCollection(baseSchema, as)
|
collection := schema.NewCollection(baseSchema, as)
|
||||||
|
|
||||||
counts.Register(baseSchema)
|
counts.Register(baseSchema)
|
||||||
subscribe.Register(baseSchema)
|
subscribe.Register(baseSchema)
|
||||||
|
apigroups.Register(baseSchema, k8s.Discovery())
|
||||||
|
|
||||||
common.Register(collection, getter)
|
common.Register(collection, getter)
|
||||||
|
|
||||||
|
@ -56,7 +56,8 @@ func Run(ctx context.Context, cfg Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sf := resources.SchemaFactory(cf,
|
sf := resources.SchemaFactory(cf,
|
||||||
accesscontrol.NewAccessStore(rbac.Rbac().V1()))
|
accesscontrol.NewAccessStore(rbac.Rbac().V1()),
|
||||||
|
k8s)
|
||||||
|
|
||||||
schema.Register(ctx,
|
schema.Register(ctx,
|
||||||
k8s.Discovery(),
|
k8s.Discovery(),
|
||||||
|
Loading…
Reference in New Issue
Block a user