Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package repository permissions endpoint #5604

Merged
merged 16 commits into from
Nov 17, 2022
Prev Previous commit
Next Next commit
Added Flux and Kapp
Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
  • Loading branch information
Rafa Castelblanque committed Nov 2, 2022
commit b6a28d7b52eff9b8f5f04031ae8bbaa136e5531c
38 changes: 36 additions & 2 deletions cmd/kubeapps-apis/plugins/fluxv2/packages/v1alpha1/server.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ package main
import (
"context"
"fmt"
"github.com/vmware-tanzu/kubeapps/cmd/kubeapps-apis/plugins/pkg/resources"

"github.com/vmware-tanzu/kubeapps/cmd/kubeapps-apis/plugins/pkg/helm"

@@ -635,8 +636,41 @@ func (s *Server) DeletePackageRepository(ctx context.Context, request *corev1.De
}
}

func (s *Server) GetPackageRepositoryPermissions(context.Context, *corev1.GetPackageRepositoryPermissionsRequest) (*corev1.GetPackageRepositoryPermissionsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetPackageRepositoryPermissions not implemented")
func (s *Server) GetPackageRepositoryPermissions(ctx context.Context, request *corev1.GetPackageRepositoryPermissionsRequest) (*corev1.GetPackageRepositoryPermissionsResponse, error) {
log.Infof("+fluxv2 GetPackageRepositoryPermissions [%v]", request)

cluster := request.GetContext().GetCluster()
typedClient, err := s.clientGetter.Typed(ctx, cluster)
if err != nil {
return nil, err
}

resource := schema.GroupResource{
Group: sourcev1.GroupVersion.Group,
Resource: fluxHelmRepositories,
}

permissions := &corev1.PackageRepositoriesPermissions{
Plugin: GetPluginDetail(),
}

// Global permissions
permissions.Global, err = resources.GetPermissionsOnResource(ctx, typedClient, resource, "")
if err != nil {
return nil, err
}

// Namespace permissions
if request.GetContext().GetNamespace() != "" {
permissions.Namespace, err = resources.GetPermissionsOnResource(ctx, typedClient, resource, request.GetContext().GetNamespace())
if err != nil {
return nil, err
}
}

return &corev1.GetPackageRepositoryPermissionsResponse{
Permissions: []*corev1.PackageRepositoriesPermissions{permissions},
}, nil
}

// This endpoint exists only for integration unit tests
Original file line number Diff line number Diff line change
@@ -5,7 +5,10 @@ package main

import (
"context"
packagingv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1"
"github.com/vmware-tanzu/kubeapps/cmd/kubeapps-apis/plugins/pkg/resources"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"

corev1 "github.com/vmware-tanzu/kubeapps/cmd/kubeapps-apis/gen/core/packages/v1alpha1"
"github.com/vmware-tanzu/kubeapps/cmd/kubeapps-apis/plugins/pkg/statuserror"
@@ -320,6 +323,39 @@ func (s *Server) DeletePackageRepository(ctx context.Context, request *corev1.De
return response, nil
}

func (s *Server) GetPackageRepositoryPermissions(context.Context, *corev1.GetPackageRepositoryPermissionsRequest) (*corev1.GetPackageRepositoryPermissionsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetPackageRepositoryPermissions not implemented")
func (s *Server) GetPackageRepositoryPermissions(ctx context.Context, request *corev1.GetPackageRepositoryPermissionsRequest) (*corev1.GetPackageRepositoryPermissionsResponse, error) {
log.Infof("+kapp-controller GetPackageRepositoryPermissions [%v]", request)

cluster := request.GetContext().GetCluster()
typedClient, err := s.clientGetter.Typed(ctx, cluster)
if err != nil {
return nil, err
}

resource := schema.GroupResource{
Group: packagingv1alpha1.SchemeGroupVersion.Group,
Resource: pkgRepositoriesResource,
}

permissions := &corev1.PackageRepositoriesPermissions{
Plugin: GetPluginDetail(),
}

// Global permissions
permissions.Global, err = resources.GetPermissionsOnResource(ctx, typedClient, resource, "")
if err != nil {
return nil, err
}

// Namespace permissions
if request.GetContext().GetNamespace() != "" {
permissions.Namespace, err = resources.GetPermissionsOnResource(ctx, typedClient, resource, request.GetContext().GetNamespace())
if err != nil {
return nil, err
}
}

return &corev1.GetPackageRepositoryPermissionsResponse{
Permissions: []*corev1.PackageRepositoriesPermissions{permissions},
}, nil
}