namespace api + server + refactor

This commit is contained in:
rushtehrani
2020-02-02 11:06:43 -08:00
parent 464888c2be
commit 66a19f1e1b
11 changed files with 736 additions and 19 deletions

View File

@@ -0,0 +1,45 @@
package server
import (
"context"
"github.com/onepanelio/core/api"
"github.com/onepanelio/core/manager"
"github.com/onepanelio/core/model"
"github.com/onepanelio/core/util"
"google.golang.org/grpc/codes"
)
type NamespaceServer struct {
resourceManager *manager.ResourceManager
}
func NewNamespaceServer(resourceManager *manager.ResourceManager) *NamespaceServer {
return &NamespaceServer{resourceManager: resourceManager}
}
func apiNamespace(ns *model.Namespace) (namespace *api.Namespace) {
namespace = &api.Namespace{
Name: ns.Name,
Labels: ns.Labels,
}
return
}
func (s *NamespaceServer) ListNamespaces(ctx context.Context, req *api.ListNamespacesRequest) (*api.ListNamespacesResponse, error) {
namespaces, err := s.resourceManager.ListNamespaces(modelListOptions(req.ListOptions))
if err != nil {
return nil, util.NewUserError(codes.Unknown, "Unknown error.")
}
apiNamespaces := []*api.Namespace{}
for _, ns := range namespaces {
apiNamespaces = append(apiNamespaces, apiNamespace(ns))
}
return &api.ListNamespacesResponse{
Count: int32(len(apiNamespaces)),
Namespaces: apiNamespaces,
}, nil
}