Skip to content

Commit

Permalink
drop MemberClusterService interface & rename the implementation (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Nov 14, 2024
1 parent 738daee commit 2238b65
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 224 deletions.
5 changes: 0 additions & 5 deletions pkg/application/service/factory/service_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/pkg/log"
"github.com/codeready-toolchain/registration-service/pkg/namespaced"
clusterservice "github.com/codeready-toolchain/registration-service/pkg/proxy/service"
signupservice "github.com/codeready-toolchain/registration-service/pkg/signup/service"
verificationservice "github.com/codeready-toolchain/registration-service/pkg/verification/service"
)
Expand Down Expand Up @@ -51,10 +50,6 @@ func (s *ServiceFactory) defaultServiceContextProducer() servicecontext.ServiceC
}
}

func (s *ServiceFactory) MemberClusterService() service.MemberClusterService {
return clusterservice.NewMemberClusterService(s.getContext().Client(), s.getContext().Services().SignupService())
}

func (s *ServiceFactory) SignupService() service.SignupService {
return s.signupServiceFunc(s.signupServiceOptions...)
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/application/service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package service

import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/registration-service/pkg/proxy/access"
"github.com/codeready-toolchain/registration-service/pkg/signup"
"github.com/gin-gonic/gin"
)
Expand All @@ -20,12 +19,7 @@ type VerificationService interface {
VerifyActivationCode(ctx *gin.Context, userID, username, code string) error
}

type MemberClusterService interface {
GetClusterAccess(userID, username, workspace, proxyPluginName string, publicViewerEnabled bool) (*access.ClusterAccess, error)
}

type Services interface {
SignupService() SignupService
VerificationService() VerificationService
MemberClusterService() MemberClusterService
}
35 changes: 15 additions & 20 deletions pkg/proxy/service/cluster_service.go → pkg/proxy/members.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package proxy

import (
"context"
Expand All @@ -20,29 +20,24 @@ import (
"k8s.io/apimachinery/pkg/types"
)

type Option func(f *ServiceImpl)

// ServiceImpl represents the implementation of the member cluster service.
type ServiceImpl struct { // nolint:revive
// MemberClusters is a type that helps with retrieving access to a specific member cluster
type MemberClusters struct { // nolint:revive
namespaced.Client
SignupService service.SignupService
GetMembersFunc cluster.GetMemberClustersFunc
}

// NewMemberClusterService creates a service object for performing toolchain cluster related activities.
func NewMemberClusterService(client namespaced.Client, signupService service.SignupService, options ...Option) service.MemberClusterService {
si := &ServiceImpl{
// NewMemberClusters creates an instance of the MemberClusters type
func NewMemberClusters(client namespaced.Client, signupService service.SignupService, getMembersFunc cluster.GetMemberClustersFunc) *MemberClusters {
si := &MemberClusters{
Client: client,
SignupService: signupService,
GetMembersFunc: cluster.GetMemberClusters,
}
for _, o := range options {
o(si)
GetMembersFunc: getMembersFunc,
}
return si
}

func (s *ServiceImpl) GetClusterAccess(userID, username, workspace, proxyPluginName string, publicViewerEnabled bool) (*access.ClusterAccess, error) {
func (s *MemberClusters) GetClusterAccess(userID, username, workspace, proxyPluginName string, publicViewerEnabled bool) (*access.ClusterAccess, error) {
// if workspace is not provided then return the default space access
if workspace == "" {
return s.getClusterAccessForDefaultWorkspace(userID, username, proxyPluginName)
Expand All @@ -52,7 +47,7 @@ func (s *ServiceImpl) GetClusterAccess(userID, username, workspace, proxyPluginN
}

// getSpaceAccess retrieves space access for an user
func (s *ServiceImpl) getSpaceAccess(userID, username, workspace, proxyPluginName string, publicViewerEnabled bool) (*access.ClusterAccess, error) {
func (s *MemberClusters) getSpaceAccess(userID, username, workspace, proxyPluginName string, publicViewerEnabled bool) (*access.ClusterAccess, error) {
// retrieve the user's complaint name
complaintUserName, err := s.getUserSignupComplaintName(userID, username, publicViewerEnabled)
if err != nil {
Expand All @@ -70,7 +65,7 @@ func (s *ServiceImpl) getSpaceAccess(userID, username, workspace, proxyPluginNam
return s.accessForSpace(space, complaintUserName, proxyPluginName)
}

func (s *ServiceImpl) getUserSignupComplaintName(userID, username string, publicViewerEnabled bool) (string, error) {
func (s *MemberClusters) getUserSignupComplaintName(userID, username string, publicViewerEnabled bool) (string, error) {
// if PublicViewer is enabled and the requested user is the PublicViewer, than no lookup is required
if publicViewerEnabled && username == toolchainv1alpha1.KubesawAuthenticatedUsername {
return username, nil
Expand All @@ -86,7 +81,7 @@ func (s *ServiceImpl) getUserSignupComplaintName(userID, username string, public
}

// getClusterAccessForDefaultWorkspace retrieves the cluster for the user's default workspace
func (s *ServiceImpl) getClusterAccessForDefaultWorkspace(userID, username, proxyPluginName string) (*access.ClusterAccess, error) {
func (s *MemberClusters) getClusterAccessForDefaultWorkspace(userID, username, proxyPluginName string) (*access.ClusterAccess, error) {
// retrieve the UserSignup from cache
userSignup, err := s.getSignupFromInformerForProvisionedUser(userID, username)
if err != nil {
Expand All @@ -97,7 +92,7 @@ func (s *ServiceImpl) getClusterAccessForDefaultWorkspace(userID, username, prox
return s.accessForCluster(userSignup.APIEndpoint, userSignup.ClusterName, userSignup.CompliantUsername, proxyPluginName)
}

func (s *ServiceImpl) getSignupFromInformerForProvisionedUser(userID, username string) (*signup.Signup, error) {
func (s *MemberClusters) getSignupFromInformerForProvisionedUser(userID, username string) (*signup.Signup, error) {
// don't check for usersignup complete status, since it might cause the proxy blocking the request
// and returning an error when quick transitions from ready to provisioning are happening.
userSignup, err := s.SignupService.GetSignup(nil, userID, username, false)
Expand All @@ -115,7 +110,7 @@ func (s *ServiceImpl) getSignupFromInformerForProvisionedUser(userID, username s
return userSignup, nil
}

func (s *ServiceImpl) accessForSpace(space *toolchainv1alpha1.Space, username, proxyPluginName string) (*access.ClusterAccess, error) {
func (s *MemberClusters) accessForSpace(space *toolchainv1alpha1.Space, username, proxyPluginName string) (*access.ClusterAccess, error) {
// Get the target member
members := s.GetMembersFunc()
if len(members) == 0 {
Expand All @@ -138,7 +133,7 @@ func (s *ServiceImpl) accessForSpace(space *toolchainv1alpha1.Space, username, p
return nil, errs.New(errMsg)
}

func (s *ServiceImpl) accessForCluster(apiEndpoint, clusterName, username, proxyPluginName string) (*access.ClusterAccess, error) {
func (s *MemberClusters) accessForCluster(apiEndpoint, clusterName, username, proxyPluginName string) (*access.ClusterAccess, error) {
// Get the target member
members := s.GetMembersFunc()
if len(members) == 0 {
Expand All @@ -161,7 +156,7 @@ func (s *ServiceImpl) accessForCluster(apiEndpoint, clusterName, username, proxy
return nil, errs.New("no member cluster found for the user")
}

func (s *ServiceImpl) getMemberURL(proxyPluginName string, member *cluster.CachedToolchainCluster) (*url.URL, error) {
func (s *MemberClusters) getMemberURL(proxyPluginName string, member *cluster.CachedToolchainCluster) (*url.URL, error) {
if member == nil {
return nil, errs.New("nil member provided")
}
Expand Down
Loading

0 comments on commit 2238b65

Please sign in to comment.