diff --git a/api/apis/integration/integration_suite_test.go b/api/apis/integration/integration_suite_test.go index 1916cbe8b..8e3dd0076 100644 --- a/api/apis/integration/integration_suite_test.go +++ b/api/apis/integration/integration_suite_test.go @@ -68,7 +68,7 @@ var ( rootNamespaceUserRole *rbacv1.ClusterRole rootNamespace string clientFactory repositories.UserK8sClientFactory - nsPermissions *authorization.NamespacePermissions + nsPermissions repositories.NamespacePermissions ) var _ = BeforeSuite(func() { @@ -105,7 +105,7 @@ var _ = BeforeSuite(func() { dynamicClient, err := dynamic.NewForConfig(k8sConfig) Expect(err).NotTo(HaveOccurred()) Expect(dynamicClient).NotTo(BeNil()) - namespaceRetriever = repositories.NewNamespaceRetriver(dynamicClient) + namespaceRetriever = repositories.NewNamespaceRetriever(dynamicClient) Expect(namespaceRetriever).NotTo(BeNil()) rand.Seed(time.Now().UnixNano()) diff --git a/api/authorization/namespace_permissions.go b/api/authorization/namespace_permissions.go index 346556fa5..f8f88164e 100644 --- a/api/authorization/namespace_permissions.go +++ b/api/authorization/namespace_permissions.go @@ -24,29 +24,29 @@ type IdentityProvider interface { GetIdentity(context.Context, Info) (Identity, error) } -type NamespacePermissions struct { +type namespacePermissions struct { privilegedClient client.Client identityProvider IdentityProvider rootNamespace string } -func NewNamespacePermissions(privilegedClient client.Client, identityProvider IdentityProvider, rootNamespace string) *NamespacePermissions { - return &NamespacePermissions{ +func NewNamespacePermissions(privilegedClient client.Client, identityProvider IdentityProvider, rootNamespace string) *namespacePermissions { + return &namespacePermissions{ privilegedClient: privilegedClient, identityProvider: identityProvider, rootNamespace: rootNamespace, } } -func (o *NamespacePermissions) GetAuthorizedOrgNamespaces(ctx context.Context, info Info) (map[string]bool, error) { +func (o *namespacePermissions) GetAuthorizedOrgNamespaces(ctx context.Context, info Info) (map[string]bool, error) { return o.getAuthorizedNamespaces(ctx, info, orgLevel, "Org") } -func (o *NamespacePermissions) GetAuthorizedSpaceNamespaces(ctx context.Context, info Info) (map[string]bool, error) { +func (o *namespacePermissions) GetAuthorizedSpaceNamespaces(ctx context.Context, info Info) (map[string]bool, error) { return o.getAuthorizedNamespaces(ctx, info, spaceLevel, "Space") } -func (o *NamespacePermissions) getAuthorizedNamespaces(ctx context.Context, info Info, orgSpaceLevel, resourceType string) (map[string]bool, error) { +func (o *namespacePermissions) getAuthorizedNamespaces(ctx context.Context, info Info, orgSpaceLevel, resourceType string) (map[string]bool, error) { identity, err := o.identityProvider.GetIdentity(ctx, info) if err != nil { return nil, fmt.Errorf("failed to get identity: %w", err) @@ -84,7 +84,7 @@ func (o *NamespacePermissions) getAuthorizedNamespaces(ctx context.Context, info return authorizedNamespaces, nil } -func (o *NamespacePermissions) AuthorizedIn(ctx context.Context, identity Identity, namespace string) (bool, error) { +func (o *namespacePermissions) AuthorizedIn(ctx context.Context, identity Identity, namespace string) (bool, error) { var rolebindings rbacv1.RoleBindingList err := o.privilegedClient.List(ctx, &rolebindings, client.InNamespace(namespace)) if err != nil { diff --git a/api/authorization/namespace_permissions_test.go b/api/authorization/namespace_permissions_test.go index 07517cd00..b5516b3d3 100644 --- a/api/authorization/namespace_permissions_test.go +++ b/api/authorization/namespace_permissions_test.go @@ -1,6 +1,7 @@ package authorization_test import ( + "code.cloudfoundry.org/cf-k8s-controllers/api/repositories" "context" "errors" "fmt" @@ -20,7 +21,7 @@ import ( var _ = Describe("Namespace Permissions", func() { var ( ctx context.Context - nsPerms *authorization.NamespacePermissions + nsPerms repositories.NamespacePermissions namespaces map[string]bool getErr error authInfo authorization.Info diff --git a/api/main.go b/api/main.go index 52baab5d1..b7884e94b 100644 --- a/api/main.go +++ b/api/main.go @@ -81,7 +81,7 @@ func main() { if err != nil { panic(fmt.Sprintf("could not create dynamic k8s client: %v", err)) } - namespaceRetriever := repositories.NewNamespaceRetriver(dynamicClient) + namespaceRetriever := repositories.NewNamespaceRetriever(dynamicClient) mapper, err := apiutil.NewDynamicRESTMapper(k8sClientConfig) if err != nil { diff --git a/api/repositories/app_repository.go b/api/repositories/app_repository.go index fa3389af8..3a16522fc 100644 --- a/api/repositories/app_repository.go +++ b/api/repositories/app_repository.go @@ -41,10 +41,10 @@ const ( type AppRepo struct { namespaceRetriever NamespaceRetriever userClientFactory UserK8sClientFactory - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions } -func NewAppRepo(namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, authPerms *authorization.NamespacePermissions) *AppRepo { +func NewAppRepo(namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, authPerms NamespacePermissions) *AppRepo { return &AppRepo{ namespaceRetriever: namespaceRetriever, userClientFactory: userClientFactory, @@ -160,7 +160,7 @@ func (f *AppRepo) GetApp(ctx context.Context, authInfo authorization.Info, appGU userClient, err := f.userClientFactory.BuildClient(authInfo) if err != nil { - return AppRecord{}, fmt.Errorf("get-app failed to build user client: %w", err) + return AppRecord{}, fmt.Errorf("failed to build user client: %w", err) } app := workloadsv1alpha1.CFApp{} @@ -395,7 +395,7 @@ func (f *AppRepo) CreateOrPatchAppEnvVars(ctx context.Context, authInfo authoriz func (f *AppRepo) SetCurrentDroplet(ctx context.Context, authInfo authorization.Info, message SetCurrentDropletMessage) (CurrentDropletRecord, error) { userClient, err := f.userClientFactory.BuildClient(authInfo) if err != nil { - return CurrentDropletRecord{}, fmt.Errorf("set-current-droplet: failed to create k8s user client: %w", err) + return CurrentDropletRecord{}, fmt.Errorf("failed to build user client: %w", err) } baseCFApp := &workloadsv1alpha1.CFApp{ diff --git a/api/repositories/app_repository_test.go b/api/repositories/app_repository_test.go index fba36836c..ebc2e32bf 100644 --- a/api/repositories/app_repository_test.go +++ b/api/repositories/app_repository_test.go @@ -9,13 +9,16 @@ import ( "code.cloudfoundry.org/cf-k8s-controllers/api/apierrors" . "code.cloudfoundry.org/cf-k8s-controllers/api/repositories" + "code.cloudfoundry.org/cf-k8s-controllers/api/repositories/fake" workloadsv1alpha1 "code.cloudfoundry.org/cf-k8s-controllers/controllers/apis/workloads/v1alpha1" + "code.cloudfoundry.org/cf-k8s-controllers/controllers/webhooks" "code.cloudfoundry.org/cf-k8s-controllers/tests/matchers" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gstruct" corev1 "k8s.io/api/core/v1" + k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -28,6 +31,324 @@ const ( CFAppStoppedState = "STOPPED" ) +//counterfeiter:generate -o fake -fake-name ClientWithWatch sigs.k8s.io/controller-runtime/pkg/client.WithWatch +var _ = Describe("AppRepository Units", func() { + var ( + testCtx context.Context + appRepo *AppRepo + fakeUserClient fake.ClientWithWatch + fakeFactory fake.UserK8sClientFactory + fakeNamespaceRetriever fake.NamespaceRetriever + fakeNsPerms fake.NamespacePermissions + ) + + BeforeEach(func() { + testCtx = context.Background() + fakeUserClient = fake.ClientWithWatch{} + fakeFactory = fake.UserK8sClientFactory{} + fakeFactory.BuildClientReturns(&fakeUserClient, nil) + fakeNsPerms = fake.NamespacePermissions{} + fakeNamespaceRetriever = fake.NamespaceRetriever{} + appRepo = NewAppRepo(&fakeNamespaceRetriever, &fakeFactory, &fakeNsPerms) + }) + + Describe("GetApp", func() { + var retErr error + const appGUID = "some-app-guid" + + JustBeforeEach(func() { + _, retErr = appRepo.GetApp(testCtx, authInfo, appGUID) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + It("retrieves the app's namespace correctly", func() { + Expect(fakeNamespaceRetriever.NamespaceForCallCount()).To(Equal(1)) + actualCtx, actualObjectGUID, actualObjectType := fakeNamespaceRetriever.NamespaceForArgsForCall(0) + Expect(actualCtx).To(Equal(testCtx)) + Expect(actualObjectGUID).To(Equal(appGUID)) + Expect(actualObjectType).To(Equal("App")) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + }) + + Describe("CreateApp", func() { + var retErr error + JustBeforeEach(func() { + _, retErr = appRepo.CreateApp(testCtx, authInfo, CreateAppMessage{Name: prefixedGUID("app-")}) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(2)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + Expect(fakeFactory.BuildClientArgsForCall(1)).To(Equal(authInfo)) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + + When("the app already exists", func() { + BeforeEach(func() { + fakeUserClient.CreateReturns(&k8serrors.StatusError{ + ErrStatus: metav1.Status{ + Reason: metav1.StatusReason(webhooks.DuplicateAppError.Marshal()), + }}) + }) + + It("reports a uniqueness error", func() { + Expect(retErr).To(matchers.WrapErrorAssignableToTypeOf(apierrors.UniquenessError{})) + }) + }) + + When("a random error occurs", func() { + BeforeEach(func() { + fakeUserClient.CreateReturns(errors.New("something unexpected")) + }) + It("returns the error", func() { + Expect(retErr).To(MatchError(errors.New("something unexpected"))) + }) + }) + + When("we get back a random error while patching the env vars", func() { + BeforeEach(func() { + fakeUserClient.GetReturns(errors.New("shucks")) + }) + It("returns the error", func() { + Expect(retErr).To(MatchError(errors.New("shucks"))) + }) + }) + }) + + Describe("ListApps", func() { + var ( + retErr error + appRecords []AppRecord + ) + + BeforeEach(func() { + retErr = nil + appRecords = []AppRecord{} + }) + + JustBeforeEach(func() { + appRecords, retErr = appRepo.ListApps(testCtx, authInfo, ListAppsMessage{}) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + It("calls the NamespacePermissions with the correct arguments", func() { + Expect(fakeNsPerms.GetAuthorizedSpaceNamespacesCallCount()).To(Equal(1)) + actualCtx, actualAuthInfo := fakeNsPerms.GetAuthorizedSpaceNamespacesArgsForCall(0) + Expect(actualCtx).To(Equal(testCtx)) + Expect(actualAuthInfo).To(Equal(authInfo)) + }) + + When("getting namespaces returns an error", func() { + BeforeEach(func() { + fakeNsPerms.GetAuthorizedSpaceNamespacesReturns(map[string]bool{}, errors.New("something happened")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to list namespaces"))) + Expect(retErr).To(MatchError(ContainSubstring("something happened"))) + }) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + + When("there is a namespace", func() { + BeforeEach(func() { + fakeNsPerms.GetAuthorizedSpaceNamespacesReturns(map[string]bool{"foo": true}, nil) + }) + + When("the user isn't authorized to list apps in the namespace", func() { + BeforeEach(func() { + fakeUserClient.ListReturns(&k8serrors.StatusError{ + ErrStatus: metav1.Status{ + Reason: metav1.StatusReasonForbidden, + }}) + }) + It("returns an empty result set without erroring", func() { + Expect(retErr).NotTo(HaveOccurred()) + Expect(appRecords).To(BeEmpty()) + }) + }) + + When("listing apps fails for other reasons", func() { + BeforeEach(func() { + fakeUserClient.ListReturns(errors.New("random failure")) + }) + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to list apps in namespace foo"))) + Expect(retErr).To(MatchError(ContainSubstring("random failure"))) + }) + }) + }) + }) + + Describe("PatchAppEnvVars", func() { + var retErr error + JustBeforeEach(func() { + _, retErr = appRepo.PatchAppEnvVars(testCtx, authInfo, PatchAppEnvVarsMessage{}) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + + When("we get back a random error while patching the env vars", func() { + BeforeEach(func() { + fakeUserClient.GetReturns(errors.New("shucks")) + }) + It("returns the error", func() { + Expect(retErr).To(MatchError(errors.New("shucks"))) + }) + }) + }) + + Describe("SetCurrentDroplet", func() { + var retErr error + JustBeforeEach(func() { + _, retErr = appRepo.SetCurrentDroplet(testCtx, authInfo, SetCurrentDropletMessage{}) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + }) + + Describe("SetAppDesiredState", func() { + var retErr error + JustBeforeEach(func() { + _, retErr = appRepo.SetAppDesiredState(testCtx, authInfo, SetAppDesiredStateMessage{}) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + }) + + Describe("DeleteApp", func() { + var retErr error + JustBeforeEach(func() { + retErr = appRepo.DeleteApp(testCtx, authInfo, DeleteAppMessage{}) + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeFactory.BuildClientReturns(nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + }) + + Describe("GetAppEnv", func() { + var retErr error + JustBeforeEach(func() { + _, retErr = appRepo.GetAppEnv(testCtx, authInfo, "some-guid") + }) + + It("builds the user client correctly", func() { + Expect(fakeFactory.BuildClientCallCount()).To(Equal(1)) + Expect(fakeFactory.BuildClientArgsForCall(0)).To(Equal(authInfo)) + }) + + When("the client factory reports an error", func() { + BeforeEach(func() { + fakeUserClient.GetStub = func(ctx context.Context, name types.NamespacedName, obj client.Object) error { + cfApp := obj.(*workloadsv1alpha1.CFApp) + cfApp.Spec.EnvSecretName = "foo" + return nil + } + fakeFactory.BuildClientReturnsOnCall(1, nil, errors.New("oh no")) + }) + + It("returns the error", func() { + Expect(retErr).To(MatchError(HavePrefix("failed to build user client"))) + Expect(retErr).To(MatchError(ContainSubstring("oh no"))) + }) + }) + }) +}) + var _ = Describe("AppRepository", func() { var ( testCtx context.Context diff --git a/api/repositories/droplet_repository.go b/api/repositories/droplet_repository.go index 07ccddd34..73e514f09 100644 --- a/api/repositories/droplet_repository.go +++ b/api/repositories/droplet_repository.go @@ -21,13 +21,13 @@ const ( type DropletRepo struct { userClientFactory UserK8sClientFactory namespaceRetriever NamespaceRetriever - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions } func NewDropletRepo( userClientFactory UserK8sClientFactory, namespaceRetriever NamespaceRetriever, - namespacePermissions *authorization.NamespacePermissions, + namespacePermissions NamespacePermissions, ) *DropletRepo { return &DropletRepo{ userClientFactory: userClientFactory, diff --git a/api/repositories/fake/client_with_watch.go b/api/repositories/fake/client_with_watch.go new file mode 100644 index 000000000..0b4398239 --- /dev/null +++ b/api/repositories/fake/client_with_watch.go @@ -0,0 +1,868 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fake + +import ( + "context" + "sync" + + "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type ClientWithWatch struct { + CreateStub func(context.Context, client.Object, ...client.CreateOption) error + createMutex sync.RWMutex + createArgsForCall []struct { + arg1 context.Context + arg2 client.Object + arg3 []client.CreateOption + } + createReturns struct { + result1 error + } + createReturnsOnCall map[int]struct { + result1 error + } + DeleteStub func(context.Context, client.Object, ...client.DeleteOption) error + deleteMutex sync.RWMutex + deleteArgsForCall []struct { + arg1 context.Context + arg2 client.Object + arg3 []client.DeleteOption + } + deleteReturns struct { + result1 error + } + deleteReturnsOnCall map[int]struct { + result1 error + } + DeleteAllOfStub func(context.Context, client.Object, ...client.DeleteAllOfOption) error + deleteAllOfMutex sync.RWMutex + deleteAllOfArgsForCall []struct { + arg1 context.Context + arg2 client.Object + arg3 []client.DeleteAllOfOption + } + deleteAllOfReturns struct { + result1 error + } + deleteAllOfReturnsOnCall map[int]struct { + result1 error + } + GetStub func(context.Context, types.NamespacedName, client.Object) error + getMutex sync.RWMutex + getArgsForCall []struct { + arg1 context.Context + arg2 types.NamespacedName + arg3 client.Object + } + getReturns struct { + result1 error + } + getReturnsOnCall map[int]struct { + result1 error + } + ListStub func(context.Context, client.ObjectList, ...client.ListOption) error + listMutex sync.RWMutex + listArgsForCall []struct { + arg1 context.Context + arg2 client.ObjectList + arg3 []client.ListOption + } + listReturns struct { + result1 error + } + listReturnsOnCall map[int]struct { + result1 error + } + PatchStub func(context.Context, client.Object, client.Patch, ...client.PatchOption) error + patchMutex sync.RWMutex + patchArgsForCall []struct { + arg1 context.Context + arg2 client.Object + arg3 client.Patch + arg4 []client.PatchOption + } + patchReturns struct { + result1 error + } + patchReturnsOnCall map[int]struct { + result1 error + } + RESTMapperStub func() meta.RESTMapper + rESTMapperMutex sync.RWMutex + rESTMapperArgsForCall []struct { + } + rESTMapperReturns struct { + result1 meta.RESTMapper + } + rESTMapperReturnsOnCall map[int]struct { + result1 meta.RESTMapper + } + SchemeStub func() *runtime.Scheme + schemeMutex sync.RWMutex + schemeArgsForCall []struct { + } + schemeReturns struct { + result1 *runtime.Scheme + } + schemeReturnsOnCall map[int]struct { + result1 *runtime.Scheme + } + StatusStub func() client.StatusWriter + statusMutex sync.RWMutex + statusArgsForCall []struct { + } + statusReturns struct { + result1 client.StatusWriter + } + statusReturnsOnCall map[int]struct { + result1 client.StatusWriter + } + UpdateStub func(context.Context, client.Object, ...client.UpdateOption) error + updateMutex sync.RWMutex + updateArgsForCall []struct { + arg1 context.Context + arg2 client.Object + arg3 []client.UpdateOption + } + updateReturns struct { + result1 error + } + updateReturnsOnCall map[int]struct { + result1 error + } + WatchStub func(context.Context, client.ObjectList, ...client.ListOption) (watch.Interface, error) + watchMutex sync.RWMutex + watchArgsForCall []struct { + arg1 context.Context + arg2 client.ObjectList + arg3 []client.ListOption + } + watchReturns struct { + result1 watch.Interface + result2 error + } + watchReturnsOnCall map[int]struct { + result1 watch.Interface + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *ClientWithWatch) Create(arg1 context.Context, arg2 client.Object, arg3 ...client.CreateOption) error { + fake.createMutex.Lock() + ret, specificReturn := fake.createReturnsOnCall[len(fake.createArgsForCall)] + fake.createArgsForCall = append(fake.createArgsForCall, struct { + arg1 context.Context + arg2 client.Object + arg3 []client.CreateOption + }{arg1, arg2, arg3}) + stub := fake.CreateStub + fakeReturns := fake.createReturns + fake.recordInvocation("Create", []interface{}{arg1, arg2, arg3}) + fake.createMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) CreateCallCount() int { + fake.createMutex.RLock() + defer fake.createMutex.RUnlock() + return len(fake.createArgsForCall) +} + +func (fake *ClientWithWatch) CreateCalls(stub func(context.Context, client.Object, ...client.CreateOption) error) { + fake.createMutex.Lock() + defer fake.createMutex.Unlock() + fake.CreateStub = stub +} + +func (fake *ClientWithWatch) CreateArgsForCall(i int) (context.Context, client.Object, []client.CreateOption) { + fake.createMutex.RLock() + defer fake.createMutex.RUnlock() + argsForCall := fake.createArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) CreateReturns(result1 error) { + fake.createMutex.Lock() + defer fake.createMutex.Unlock() + fake.CreateStub = nil + fake.createReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) CreateReturnsOnCall(i int, result1 error) { + fake.createMutex.Lock() + defer fake.createMutex.Unlock() + fake.CreateStub = nil + if fake.createReturnsOnCall == nil { + fake.createReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.createReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) Delete(arg1 context.Context, arg2 client.Object, arg3 ...client.DeleteOption) error { + fake.deleteMutex.Lock() + ret, specificReturn := fake.deleteReturnsOnCall[len(fake.deleteArgsForCall)] + fake.deleteArgsForCall = append(fake.deleteArgsForCall, struct { + arg1 context.Context + arg2 client.Object + arg3 []client.DeleteOption + }{arg1, arg2, arg3}) + stub := fake.DeleteStub + fakeReturns := fake.deleteReturns + fake.recordInvocation("Delete", []interface{}{arg1, arg2, arg3}) + fake.deleteMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) DeleteCallCount() int { + fake.deleteMutex.RLock() + defer fake.deleteMutex.RUnlock() + return len(fake.deleteArgsForCall) +} + +func (fake *ClientWithWatch) DeleteCalls(stub func(context.Context, client.Object, ...client.DeleteOption) error) { + fake.deleteMutex.Lock() + defer fake.deleteMutex.Unlock() + fake.DeleteStub = stub +} + +func (fake *ClientWithWatch) DeleteArgsForCall(i int) (context.Context, client.Object, []client.DeleteOption) { + fake.deleteMutex.RLock() + defer fake.deleteMutex.RUnlock() + argsForCall := fake.deleteArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) DeleteReturns(result1 error) { + fake.deleteMutex.Lock() + defer fake.deleteMutex.Unlock() + fake.DeleteStub = nil + fake.deleteReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) DeleteReturnsOnCall(i int, result1 error) { + fake.deleteMutex.Lock() + defer fake.deleteMutex.Unlock() + fake.DeleteStub = nil + if fake.deleteReturnsOnCall == nil { + fake.deleteReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.deleteReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) DeleteAllOf(arg1 context.Context, arg2 client.Object, arg3 ...client.DeleteAllOfOption) error { + fake.deleteAllOfMutex.Lock() + ret, specificReturn := fake.deleteAllOfReturnsOnCall[len(fake.deleteAllOfArgsForCall)] + fake.deleteAllOfArgsForCall = append(fake.deleteAllOfArgsForCall, struct { + arg1 context.Context + arg2 client.Object + arg3 []client.DeleteAllOfOption + }{arg1, arg2, arg3}) + stub := fake.DeleteAllOfStub + fakeReturns := fake.deleteAllOfReturns + fake.recordInvocation("DeleteAllOf", []interface{}{arg1, arg2, arg3}) + fake.deleteAllOfMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) DeleteAllOfCallCount() int { + fake.deleteAllOfMutex.RLock() + defer fake.deleteAllOfMutex.RUnlock() + return len(fake.deleteAllOfArgsForCall) +} + +func (fake *ClientWithWatch) DeleteAllOfCalls(stub func(context.Context, client.Object, ...client.DeleteAllOfOption) error) { + fake.deleteAllOfMutex.Lock() + defer fake.deleteAllOfMutex.Unlock() + fake.DeleteAllOfStub = stub +} + +func (fake *ClientWithWatch) DeleteAllOfArgsForCall(i int) (context.Context, client.Object, []client.DeleteAllOfOption) { + fake.deleteAllOfMutex.RLock() + defer fake.deleteAllOfMutex.RUnlock() + argsForCall := fake.deleteAllOfArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) DeleteAllOfReturns(result1 error) { + fake.deleteAllOfMutex.Lock() + defer fake.deleteAllOfMutex.Unlock() + fake.DeleteAllOfStub = nil + fake.deleteAllOfReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) DeleteAllOfReturnsOnCall(i int, result1 error) { + fake.deleteAllOfMutex.Lock() + defer fake.deleteAllOfMutex.Unlock() + fake.DeleteAllOfStub = nil + if fake.deleteAllOfReturnsOnCall == nil { + fake.deleteAllOfReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.deleteAllOfReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) Get(arg1 context.Context, arg2 types.NamespacedName, arg3 client.Object) error { + fake.getMutex.Lock() + ret, specificReturn := fake.getReturnsOnCall[len(fake.getArgsForCall)] + fake.getArgsForCall = append(fake.getArgsForCall, struct { + arg1 context.Context + arg2 types.NamespacedName + arg3 client.Object + }{arg1, arg2, arg3}) + stub := fake.GetStub + fakeReturns := fake.getReturns + fake.recordInvocation("Get", []interface{}{arg1, arg2, arg3}) + fake.getMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) GetCallCount() int { + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + return len(fake.getArgsForCall) +} + +func (fake *ClientWithWatch) GetCalls(stub func(context.Context, types.NamespacedName, client.Object) error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = stub +} + +func (fake *ClientWithWatch) GetArgsForCall(i int) (context.Context, types.NamespacedName, client.Object) { + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + argsForCall := fake.getArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) GetReturns(result1 error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = nil + fake.getReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) GetReturnsOnCall(i int, result1 error) { + fake.getMutex.Lock() + defer fake.getMutex.Unlock() + fake.GetStub = nil + if fake.getReturnsOnCall == nil { + fake.getReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.getReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) List(arg1 context.Context, arg2 client.ObjectList, arg3 ...client.ListOption) error { + fake.listMutex.Lock() + ret, specificReturn := fake.listReturnsOnCall[len(fake.listArgsForCall)] + fake.listArgsForCall = append(fake.listArgsForCall, struct { + arg1 context.Context + arg2 client.ObjectList + arg3 []client.ListOption + }{arg1, arg2, arg3}) + stub := fake.ListStub + fakeReturns := fake.listReturns + fake.recordInvocation("List", []interface{}{arg1, arg2, arg3}) + fake.listMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) ListCallCount() int { + fake.listMutex.RLock() + defer fake.listMutex.RUnlock() + return len(fake.listArgsForCall) +} + +func (fake *ClientWithWatch) ListCalls(stub func(context.Context, client.ObjectList, ...client.ListOption) error) { + fake.listMutex.Lock() + defer fake.listMutex.Unlock() + fake.ListStub = stub +} + +func (fake *ClientWithWatch) ListArgsForCall(i int) (context.Context, client.ObjectList, []client.ListOption) { + fake.listMutex.RLock() + defer fake.listMutex.RUnlock() + argsForCall := fake.listArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) ListReturns(result1 error) { + fake.listMutex.Lock() + defer fake.listMutex.Unlock() + fake.ListStub = nil + fake.listReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) ListReturnsOnCall(i int, result1 error) { + fake.listMutex.Lock() + defer fake.listMutex.Unlock() + fake.ListStub = nil + if fake.listReturnsOnCall == nil { + fake.listReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.listReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) Patch(arg1 context.Context, arg2 client.Object, arg3 client.Patch, arg4 ...client.PatchOption) error { + fake.patchMutex.Lock() + ret, specificReturn := fake.patchReturnsOnCall[len(fake.patchArgsForCall)] + fake.patchArgsForCall = append(fake.patchArgsForCall, struct { + arg1 context.Context + arg2 client.Object + arg3 client.Patch + arg4 []client.PatchOption + }{arg1, arg2, arg3, arg4}) + stub := fake.PatchStub + fakeReturns := fake.patchReturns + fake.recordInvocation("Patch", []interface{}{arg1, arg2, arg3, arg4}) + fake.patchMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3, arg4...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) PatchCallCount() int { + fake.patchMutex.RLock() + defer fake.patchMutex.RUnlock() + return len(fake.patchArgsForCall) +} + +func (fake *ClientWithWatch) PatchCalls(stub func(context.Context, client.Object, client.Patch, ...client.PatchOption) error) { + fake.patchMutex.Lock() + defer fake.patchMutex.Unlock() + fake.PatchStub = stub +} + +func (fake *ClientWithWatch) PatchArgsForCall(i int) (context.Context, client.Object, client.Patch, []client.PatchOption) { + fake.patchMutex.RLock() + defer fake.patchMutex.RUnlock() + argsForCall := fake.patchArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4 +} + +func (fake *ClientWithWatch) PatchReturns(result1 error) { + fake.patchMutex.Lock() + defer fake.patchMutex.Unlock() + fake.PatchStub = nil + fake.patchReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) PatchReturnsOnCall(i int, result1 error) { + fake.patchMutex.Lock() + defer fake.patchMutex.Unlock() + fake.PatchStub = nil + if fake.patchReturnsOnCall == nil { + fake.patchReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.patchReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) RESTMapper() meta.RESTMapper { + fake.rESTMapperMutex.Lock() + ret, specificReturn := fake.rESTMapperReturnsOnCall[len(fake.rESTMapperArgsForCall)] + fake.rESTMapperArgsForCall = append(fake.rESTMapperArgsForCall, struct { + }{}) + stub := fake.RESTMapperStub + fakeReturns := fake.rESTMapperReturns + fake.recordInvocation("RESTMapper", []interface{}{}) + fake.rESTMapperMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) RESTMapperCallCount() int { + fake.rESTMapperMutex.RLock() + defer fake.rESTMapperMutex.RUnlock() + return len(fake.rESTMapperArgsForCall) +} + +func (fake *ClientWithWatch) RESTMapperCalls(stub func() meta.RESTMapper) { + fake.rESTMapperMutex.Lock() + defer fake.rESTMapperMutex.Unlock() + fake.RESTMapperStub = stub +} + +func (fake *ClientWithWatch) RESTMapperReturns(result1 meta.RESTMapper) { + fake.rESTMapperMutex.Lock() + defer fake.rESTMapperMutex.Unlock() + fake.RESTMapperStub = nil + fake.rESTMapperReturns = struct { + result1 meta.RESTMapper + }{result1} +} + +func (fake *ClientWithWatch) RESTMapperReturnsOnCall(i int, result1 meta.RESTMapper) { + fake.rESTMapperMutex.Lock() + defer fake.rESTMapperMutex.Unlock() + fake.RESTMapperStub = nil + if fake.rESTMapperReturnsOnCall == nil { + fake.rESTMapperReturnsOnCall = make(map[int]struct { + result1 meta.RESTMapper + }) + } + fake.rESTMapperReturnsOnCall[i] = struct { + result1 meta.RESTMapper + }{result1} +} + +func (fake *ClientWithWatch) Scheme() *runtime.Scheme { + fake.schemeMutex.Lock() + ret, specificReturn := fake.schemeReturnsOnCall[len(fake.schemeArgsForCall)] + fake.schemeArgsForCall = append(fake.schemeArgsForCall, struct { + }{}) + stub := fake.SchemeStub + fakeReturns := fake.schemeReturns + fake.recordInvocation("Scheme", []interface{}{}) + fake.schemeMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) SchemeCallCount() int { + fake.schemeMutex.RLock() + defer fake.schemeMutex.RUnlock() + return len(fake.schemeArgsForCall) +} + +func (fake *ClientWithWatch) SchemeCalls(stub func() *runtime.Scheme) { + fake.schemeMutex.Lock() + defer fake.schemeMutex.Unlock() + fake.SchemeStub = stub +} + +func (fake *ClientWithWatch) SchemeReturns(result1 *runtime.Scheme) { + fake.schemeMutex.Lock() + defer fake.schemeMutex.Unlock() + fake.SchemeStub = nil + fake.schemeReturns = struct { + result1 *runtime.Scheme + }{result1} +} + +func (fake *ClientWithWatch) SchemeReturnsOnCall(i int, result1 *runtime.Scheme) { + fake.schemeMutex.Lock() + defer fake.schemeMutex.Unlock() + fake.SchemeStub = nil + if fake.schemeReturnsOnCall == nil { + fake.schemeReturnsOnCall = make(map[int]struct { + result1 *runtime.Scheme + }) + } + fake.schemeReturnsOnCall[i] = struct { + result1 *runtime.Scheme + }{result1} +} + +func (fake *ClientWithWatch) Status() client.StatusWriter { + fake.statusMutex.Lock() + ret, specificReturn := fake.statusReturnsOnCall[len(fake.statusArgsForCall)] + fake.statusArgsForCall = append(fake.statusArgsForCall, struct { + }{}) + stub := fake.StatusStub + fakeReturns := fake.statusReturns + fake.recordInvocation("Status", []interface{}{}) + fake.statusMutex.Unlock() + if stub != nil { + return stub() + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) StatusCallCount() int { + fake.statusMutex.RLock() + defer fake.statusMutex.RUnlock() + return len(fake.statusArgsForCall) +} + +func (fake *ClientWithWatch) StatusCalls(stub func() client.StatusWriter) { + fake.statusMutex.Lock() + defer fake.statusMutex.Unlock() + fake.StatusStub = stub +} + +func (fake *ClientWithWatch) StatusReturns(result1 client.StatusWriter) { + fake.statusMutex.Lock() + defer fake.statusMutex.Unlock() + fake.StatusStub = nil + fake.statusReturns = struct { + result1 client.StatusWriter + }{result1} +} + +func (fake *ClientWithWatch) StatusReturnsOnCall(i int, result1 client.StatusWriter) { + fake.statusMutex.Lock() + defer fake.statusMutex.Unlock() + fake.StatusStub = nil + if fake.statusReturnsOnCall == nil { + fake.statusReturnsOnCall = make(map[int]struct { + result1 client.StatusWriter + }) + } + fake.statusReturnsOnCall[i] = struct { + result1 client.StatusWriter + }{result1} +} + +func (fake *ClientWithWatch) Update(arg1 context.Context, arg2 client.Object, arg3 ...client.UpdateOption) error { + fake.updateMutex.Lock() + ret, specificReturn := fake.updateReturnsOnCall[len(fake.updateArgsForCall)] + fake.updateArgsForCall = append(fake.updateArgsForCall, struct { + arg1 context.Context + arg2 client.Object + arg3 []client.UpdateOption + }{arg1, arg2, arg3}) + stub := fake.UpdateStub + fakeReturns := fake.updateReturns + fake.recordInvocation("Update", []interface{}{arg1, arg2, arg3}) + fake.updateMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1 + } + return fakeReturns.result1 +} + +func (fake *ClientWithWatch) UpdateCallCount() int { + fake.updateMutex.RLock() + defer fake.updateMutex.RUnlock() + return len(fake.updateArgsForCall) +} + +func (fake *ClientWithWatch) UpdateCalls(stub func(context.Context, client.Object, ...client.UpdateOption) error) { + fake.updateMutex.Lock() + defer fake.updateMutex.Unlock() + fake.UpdateStub = stub +} + +func (fake *ClientWithWatch) UpdateArgsForCall(i int) (context.Context, client.Object, []client.UpdateOption) { + fake.updateMutex.RLock() + defer fake.updateMutex.RUnlock() + argsForCall := fake.updateArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) UpdateReturns(result1 error) { + fake.updateMutex.Lock() + defer fake.updateMutex.Unlock() + fake.UpdateStub = nil + fake.updateReturns = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) UpdateReturnsOnCall(i int, result1 error) { + fake.updateMutex.Lock() + defer fake.updateMutex.Unlock() + fake.UpdateStub = nil + if fake.updateReturnsOnCall == nil { + fake.updateReturnsOnCall = make(map[int]struct { + result1 error + }) + } + fake.updateReturnsOnCall[i] = struct { + result1 error + }{result1} +} + +func (fake *ClientWithWatch) Watch(arg1 context.Context, arg2 client.ObjectList, arg3 ...client.ListOption) (watch.Interface, error) { + fake.watchMutex.Lock() + ret, specificReturn := fake.watchReturnsOnCall[len(fake.watchArgsForCall)] + fake.watchArgsForCall = append(fake.watchArgsForCall, struct { + arg1 context.Context + arg2 client.ObjectList + arg3 []client.ListOption + }{arg1, arg2, arg3}) + stub := fake.WatchStub + fakeReturns := fake.watchReturns + fake.recordInvocation("Watch", []interface{}{arg1, arg2, arg3}) + fake.watchMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3...) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *ClientWithWatch) WatchCallCount() int { + fake.watchMutex.RLock() + defer fake.watchMutex.RUnlock() + return len(fake.watchArgsForCall) +} + +func (fake *ClientWithWatch) WatchCalls(stub func(context.Context, client.ObjectList, ...client.ListOption) (watch.Interface, error)) { + fake.watchMutex.Lock() + defer fake.watchMutex.Unlock() + fake.WatchStub = stub +} + +func (fake *ClientWithWatch) WatchArgsForCall(i int) (context.Context, client.ObjectList, []client.ListOption) { + fake.watchMutex.RLock() + defer fake.watchMutex.RUnlock() + argsForCall := fake.watchArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *ClientWithWatch) WatchReturns(result1 watch.Interface, result2 error) { + fake.watchMutex.Lock() + defer fake.watchMutex.Unlock() + fake.WatchStub = nil + fake.watchReturns = struct { + result1 watch.Interface + result2 error + }{result1, result2} +} + +func (fake *ClientWithWatch) WatchReturnsOnCall(i int, result1 watch.Interface, result2 error) { + fake.watchMutex.Lock() + defer fake.watchMutex.Unlock() + fake.WatchStub = nil + if fake.watchReturnsOnCall == nil { + fake.watchReturnsOnCall = make(map[int]struct { + result1 watch.Interface + result2 error + }) + } + fake.watchReturnsOnCall[i] = struct { + result1 watch.Interface + result2 error + }{result1, result2} +} + +func (fake *ClientWithWatch) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.createMutex.RLock() + defer fake.createMutex.RUnlock() + fake.deleteMutex.RLock() + defer fake.deleteMutex.RUnlock() + fake.deleteAllOfMutex.RLock() + defer fake.deleteAllOfMutex.RUnlock() + fake.getMutex.RLock() + defer fake.getMutex.RUnlock() + fake.listMutex.RLock() + defer fake.listMutex.RUnlock() + fake.patchMutex.RLock() + defer fake.patchMutex.RUnlock() + fake.rESTMapperMutex.RLock() + defer fake.rESTMapperMutex.RUnlock() + fake.schemeMutex.RLock() + defer fake.schemeMutex.RUnlock() + fake.statusMutex.RLock() + defer fake.statusMutex.RUnlock() + fake.updateMutex.RLock() + defer fake.updateMutex.RUnlock() + fake.watchMutex.RLock() + defer fake.watchMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *ClientWithWatch) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ client.WithWatch = new(ClientWithWatch) diff --git a/api/repositories/fake/namespace_permissions.go b/api/repositories/fake/namespace_permissions.go new file mode 100644 index 000000000..bfdde67fd --- /dev/null +++ b/api/repositories/fake/namespace_permissions.go @@ -0,0 +1,284 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fake + +import ( + "context" + "sync" + + "code.cloudfoundry.org/cf-k8s-controllers/api/authorization" + "code.cloudfoundry.org/cf-k8s-controllers/api/repositories" +) + +type NamespacePermissions struct { + AuthorizedInStub func(context.Context, authorization.Identity, string) (bool, error) + authorizedInMutex sync.RWMutex + authorizedInArgsForCall []struct { + arg1 context.Context + arg2 authorization.Identity + arg3 string + } + authorizedInReturns struct { + result1 bool + result2 error + } + authorizedInReturnsOnCall map[int]struct { + result1 bool + result2 error + } + GetAuthorizedOrgNamespacesStub func(context.Context, authorization.Info) (map[string]bool, error) + getAuthorizedOrgNamespacesMutex sync.RWMutex + getAuthorizedOrgNamespacesArgsForCall []struct { + arg1 context.Context + arg2 authorization.Info + } + getAuthorizedOrgNamespacesReturns struct { + result1 map[string]bool + result2 error + } + getAuthorizedOrgNamespacesReturnsOnCall map[int]struct { + result1 map[string]bool + result2 error + } + GetAuthorizedSpaceNamespacesStub func(context.Context, authorization.Info) (map[string]bool, error) + getAuthorizedSpaceNamespacesMutex sync.RWMutex + getAuthorizedSpaceNamespacesArgsForCall []struct { + arg1 context.Context + arg2 authorization.Info + } + getAuthorizedSpaceNamespacesReturns struct { + result1 map[string]bool + result2 error + } + getAuthorizedSpaceNamespacesReturnsOnCall map[int]struct { + result1 map[string]bool + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *NamespacePermissions) AuthorizedIn(arg1 context.Context, arg2 authorization.Identity, arg3 string) (bool, error) { + fake.authorizedInMutex.Lock() + ret, specificReturn := fake.authorizedInReturnsOnCall[len(fake.authorizedInArgsForCall)] + fake.authorizedInArgsForCall = append(fake.authorizedInArgsForCall, struct { + arg1 context.Context + arg2 authorization.Identity + arg3 string + }{arg1, arg2, arg3}) + stub := fake.AuthorizedInStub + fakeReturns := fake.authorizedInReturns + fake.recordInvocation("AuthorizedIn", []interface{}{arg1, arg2, arg3}) + fake.authorizedInMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *NamespacePermissions) AuthorizedInCallCount() int { + fake.authorizedInMutex.RLock() + defer fake.authorizedInMutex.RUnlock() + return len(fake.authorizedInArgsForCall) +} + +func (fake *NamespacePermissions) AuthorizedInCalls(stub func(context.Context, authorization.Identity, string) (bool, error)) { + fake.authorizedInMutex.Lock() + defer fake.authorizedInMutex.Unlock() + fake.AuthorizedInStub = stub +} + +func (fake *NamespacePermissions) AuthorizedInArgsForCall(i int) (context.Context, authorization.Identity, string) { + fake.authorizedInMutex.RLock() + defer fake.authorizedInMutex.RUnlock() + argsForCall := fake.authorizedInArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *NamespacePermissions) AuthorizedInReturns(result1 bool, result2 error) { + fake.authorizedInMutex.Lock() + defer fake.authorizedInMutex.Unlock() + fake.AuthorizedInStub = nil + fake.authorizedInReturns = struct { + result1 bool + result2 error + }{result1, result2} +} + +func (fake *NamespacePermissions) AuthorizedInReturnsOnCall(i int, result1 bool, result2 error) { + fake.authorizedInMutex.Lock() + defer fake.authorizedInMutex.Unlock() + fake.AuthorizedInStub = nil + if fake.authorizedInReturnsOnCall == nil { + fake.authorizedInReturnsOnCall = make(map[int]struct { + result1 bool + result2 error + }) + } + fake.authorizedInReturnsOnCall[i] = struct { + result1 bool + result2 error + }{result1, result2} +} + +func (fake *NamespacePermissions) GetAuthorizedOrgNamespaces(arg1 context.Context, arg2 authorization.Info) (map[string]bool, error) { + fake.getAuthorizedOrgNamespacesMutex.Lock() + ret, specificReturn := fake.getAuthorizedOrgNamespacesReturnsOnCall[len(fake.getAuthorizedOrgNamespacesArgsForCall)] + fake.getAuthorizedOrgNamespacesArgsForCall = append(fake.getAuthorizedOrgNamespacesArgsForCall, struct { + arg1 context.Context + arg2 authorization.Info + }{arg1, arg2}) + stub := fake.GetAuthorizedOrgNamespacesStub + fakeReturns := fake.getAuthorizedOrgNamespacesReturns + fake.recordInvocation("GetAuthorizedOrgNamespaces", []interface{}{arg1, arg2}) + fake.getAuthorizedOrgNamespacesMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *NamespacePermissions) GetAuthorizedOrgNamespacesCallCount() int { + fake.getAuthorizedOrgNamespacesMutex.RLock() + defer fake.getAuthorizedOrgNamespacesMutex.RUnlock() + return len(fake.getAuthorizedOrgNamespacesArgsForCall) +} + +func (fake *NamespacePermissions) GetAuthorizedOrgNamespacesCalls(stub func(context.Context, authorization.Info) (map[string]bool, error)) { + fake.getAuthorizedOrgNamespacesMutex.Lock() + defer fake.getAuthorizedOrgNamespacesMutex.Unlock() + fake.GetAuthorizedOrgNamespacesStub = stub +} + +func (fake *NamespacePermissions) GetAuthorizedOrgNamespacesArgsForCall(i int) (context.Context, authorization.Info) { + fake.getAuthorizedOrgNamespacesMutex.RLock() + defer fake.getAuthorizedOrgNamespacesMutex.RUnlock() + argsForCall := fake.getAuthorizedOrgNamespacesArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *NamespacePermissions) GetAuthorizedOrgNamespacesReturns(result1 map[string]bool, result2 error) { + fake.getAuthorizedOrgNamespacesMutex.Lock() + defer fake.getAuthorizedOrgNamespacesMutex.Unlock() + fake.GetAuthorizedOrgNamespacesStub = nil + fake.getAuthorizedOrgNamespacesReturns = struct { + result1 map[string]bool + result2 error + }{result1, result2} +} + +func (fake *NamespacePermissions) GetAuthorizedOrgNamespacesReturnsOnCall(i int, result1 map[string]bool, result2 error) { + fake.getAuthorizedOrgNamespacesMutex.Lock() + defer fake.getAuthorizedOrgNamespacesMutex.Unlock() + fake.GetAuthorizedOrgNamespacesStub = nil + if fake.getAuthorizedOrgNamespacesReturnsOnCall == nil { + fake.getAuthorizedOrgNamespacesReturnsOnCall = make(map[int]struct { + result1 map[string]bool + result2 error + }) + } + fake.getAuthorizedOrgNamespacesReturnsOnCall[i] = struct { + result1 map[string]bool + result2 error + }{result1, result2} +} + +func (fake *NamespacePermissions) GetAuthorizedSpaceNamespaces(arg1 context.Context, arg2 authorization.Info) (map[string]bool, error) { + fake.getAuthorizedSpaceNamespacesMutex.Lock() + ret, specificReturn := fake.getAuthorizedSpaceNamespacesReturnsOnCall[len(fake.getAuthorizedSpaceNamespacesArgsForCall)] + fake.getAuthorizedSpaceNamespacesArgsForCall = append(fake.getAuthorizedSpaceNamespacesArgsForCall, struct { + arg1 context.Context + arg2 authorization.Info + }{arg1, arg2}) + stub := fake.GetAuthorizedSpaceNamespacesStub + fakeReturns := fake.getAuthorizedSpaceNamespacesReturns + fake.recordInvocation("GetAuthorizedSpaceNamespaces", []interface{}{arg1, arg2}) + fake.getAuthorizedSpaceNamespacesMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *NamespacePermissions) GetAuthorizedSpaceNamespacesCallCount() int { + fake.getAuthorizedSpaceNamespacesMutex.RLock() + defer fake.getAuthorizedSpaceNamespacesMutex.RUnlock() + return len(fake.getAuthorizedSpaceNamespacesArgsForCall) +} + +func (fake *NamespacePermissions) GetAuthorizedSpaceNamespacesCalls(stub func(context.Context, authorization.Info) (map[string]bool, error)) { + fake.getAuthorizedSpaceNamespacesMutex.Lock() + defer fake.getAuthorizedSpaceNamespacesMutex.Unlock() + fake.GetAuthorizedSpaceNamespacesStub = stub +} + +func (fake *NamespacePermissions) GetAuthorizedSpaceNamespacesArgsForCall(i int) (context.Context, authorization.Info) { + fake.getAuthorizedSpaceNamespacesMutex.RLock() + defer fake.getAuthorizedSpaceNamespacesMutex.RUnlock() + argsForCall := fake.getAuthorizedSpaceNamespacesArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *NamespacePermissions) GetAuthorizedSpaceNamespacesReturns(result1 map[string]bool, result2 error) { + fake.getAuthorizedSpaceNamespacesMutex.Lock() + defer fake.getAuthorizedSpaceNamespacesMutex.Unlock() + fake.GetAuthorizedSpaceNamespacesStub = nil + fake.getAuthorizedSpaceNamespacesReturns = struct { + result1 map[string]bool + result2 error + }{result1, result2} +} + +func (fake *NamespacePermissions) GetAuthorizedSpaceNamespacesReturnsOnCall(i int, result1 map[string]bool, result2 error) { + fake.getAuthorizedSpaceNamespacesMutex.Lock() + defer fake.getAuthorizedSpaceNamespacesMutex.Unlock() + fake.GetAuthorizedSpaceNamespacesStub = nil + if fake.getAuthorizedSpaceNamespacesReturnsOnCall == nil { + fake.getAuthorizedSpaceNamespacesReturnsOnCall = make(map[int]struct { + result1 map[string]bool + result2 error + }) + } + fake.getAuthorizedSpaceNamespacesReturnsOnCall[i] = struct { + result1 map[string]bool + result2 error + }{result1, result2} +} + +func (fake *NamespacePermissions) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.authorizedInMutex.RLock() + defer fake.authorizedInMutex.RUnlock() + fake.getAuthorizedOrgNamespacesMutex.RLock() + defer fake.getAuthorizedOrgNamespacesMutex.RUnlock() + fake.getAuthorizedSpaceNamespacesMutex.RLock() + defer fake.getAuthorizedSpaceNamespacesMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *NamespacePermissions) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ repositories.NamespacePermissions = new(NamespacePermissions) diff --git a/api/repositories/fake/namespace_retriever.go b/api/repositories/fake/namespace_retriever.go new file mode 100644 index 000000000..2e4d59f4d --- /dev/null +++ b/api/repositories/fake/namespace_retriever.go @@ -0,0 +1,121 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fake + +import ( + "context" + "sync" + + "code.cloudfoundry.org/cf-k8s-controllers/api/repositories" +) + +type NamespaceRetriever struct { + NamespaceForStub func(context.Context, string, string) (string, error) + namespaceForMutex sync.RWMutex + namespaceForArgsForCall []struct { + arg1 context.Context + arg2 string + arg3 string + } + namespaceForReturns struct { + result1 string + result2 error + } + namespaceForReturnsOnCall map[int]struct { + result1 string + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *NamespaceRetriever) NamespaceFor(arg1 context.Context, arg2 string, arg3 string) (string, error) { + fake.namespaceForMutex.Lock() + ret, specificReturn := fake.namespaceForReturnsOnCall[len(fake.namespaceForArgsForCall)] + fake.namespaceForArgsForCall = append(fake.namespaceForArgsForCall, struct { + arg1 context.Context + arg2 string + arg3 string + }{arg1, arg2, arg3}) + stub := fake.NamespaceForStub + fakeReturns := fake.namespaceForReturns + fake.recordInvocation("NamespaceFor", []interface{}{arg1, arg2, arg3}) + fake.namespaceForMutex.Unlock() + if stub != nil { + return stub(arg1, arg2, arg3) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *NamespaceRetriever) NamespaceForCallCount() int { + fake.namespaceForMutex.RLock() + defer fake.namespaceForMutex.RUnlock() + return len(fake.namespaceForArgsForCall) +} + +func (fake *NamespaceRetriever) NamespaceForCalls(stub func(context.Context, string, string) (string, error)) { + fake.namespaceForMutex.Lock() + defer fake.namespaceForMutex.Unlock() + fake.NamespaceForStub = stub +} + +func (fake *NamespaceRetriever) NamespaceForArgsForCall(i int) (context.Context, string, string) { + fake.namespaceForMutex.RLock() + defer fake.namespaceForMutex.RUnlock() + argsForCall := fake.namespaceForArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 +} + +func (fake *NamespaceRetriever) NamespaceForReturns(result1 string, result2 error) { + fake.namespaceForMutex.Lock() + defer fake.namespaceForMutex.Unlock() + fake.NamespaceForStub = nil + fake.namespaceForReturns = struct { + result1 string + result2 error + }{result1, result2} +} + +func (fake *NamespaceRetriever) NamespaceForReturnsOnCall(i int, result1 string, result2 error) { + fake.namespaceForMutex.Lock() + defer fake.namespaceForMutex.Unlock() + fake.NamespaceForStub = nil + if fake.namespaceForReturnsOnCall == nil { + fake.namespaceForReturnsOnCall = make(map[int]struct { + result1 string + result2 error + }) + } + fake.namespaceForReturnsOnCall[i] = struct { + result1 string + result2 error + }{result1, result2} +} + +func (fake *NamespaceRetriever) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.namespaceForMutex.RLock() + defer fake.namespaceForMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *NamespaceRetriever) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ repositories.NamespaceRetriever = new(NamespaceRetriever) diff --git a/api/repositories/fake/user_k8s_client_factory.go b/api/repositories/fake/user_k8s_client_factory.go new file mode 100644 index 000000000..25e0ed292 --- /dev/null +++ b/api/repositories/fake/user_k8s_client_factory.go @@ -0,0 +1,118 @@ +// Code generated by counterfeiter. DO NOT EDIT. +package fake + +import ( + "sync" + + "code.cloudfoundry.org/cf-k8s-controllers/api/authorization" + "code.cloudfoundry.org/cf-k8s-controllers/api/repositories" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +type UserK8sClientFactory struct { + BuildClientStub func(authorization.Info) (client.WithWatch, error) + buildClientMutex sync.RWMutex + buildClientArgsForCall []struct { + arg1 authorization.Info + } + buildClientReturns struct { + result1 client.WithWatch + result2 error + } + buildClientReturnsOnCall map[int]struct { + result1 client.WithWatch + result2 error + } + invocations map[string][][]interface{} + invocationsMutex sync.RWMutex +} + +func (fake *UserK8sClientFactory) BuildClient(arg1 authorization.Info) (client.WithWatch, error) { + fake.buildClientMutex.Lock() + ret, specificReturn := fake.buildClientReturnsOnCall[len(fake.buildClientArgsForCall)] + fake.buildClientArgsForCall = append(fake.buildClientArgsForCall, struct { + arg1 authorization.Info + }{arg1}) + stub := fake.BuildClientStub + fakeReturns := fake.buildClientReturns + fake.recordInvocation("BuildClient", []interface{}{arg1}) + fake.buildClientMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *UserK8sClientFactory) BuildClientCallCount() int { + fake.buildClientMutex.RLock() + defer fake.buildClientMutex.RUnlock() + return len(fake.buildClientArgsForCall) +} + +func (fake *UserK8sClientFactory) BuildClientCalls(stub func(authorization.Info) (client.WithWatch, error)) { + fake.buildClientMutex.Lock() + defer fake.buildClientMutex.Unlock() + fake.BuildClientStub = stub +} + +func (fake *UserK8sClientFactory) BuildClientArgsForCall(i int) authorization.Info { + fake.buildClientMutex.RLock() + defer fake.buildClientMutex.RUnlock() + argsForCall := fake.buildClientArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *UserK8sClientFactory) BuildClientReturns(result1 client.WithWatch, result2 error) { + fake.buildClientMutex.Lock() + defer fake.buildClientMutex.Unlock() + fake.BuildClientStub = nil + fake.buildClientReturns = struct { + result1 client.WithWatch + result2 error + }{result1, result2} +} + +func (fake *UserK8sClientFactory) BuildClientReturnsOnCall(i int, result1 client.WithWatch, result2 error) { + fake.buildClientMutex.Lock() + defer fake.buildClientMutex.Unlock() + fake.BuildClientStub = nil + if fake.buildClientReturnsOnCall == nil { + fake.buildClientReturnsOnCall = make(map[int]struct { + result1 client.WithWatch + result2 error + }) + } + fake.buildClientReturnsOnCall[i] = struct { + result1 client.WithWatch + result2 error + }{result1, result2} +} + +func (fake *UserK8sClientFactory) Invocations() map[string][][]interface{} { + fake.invocationsMutex.RLock() + defer fake.invocationsMutex.RUnlock() + fake.buildClientMutex.RLock() + defer fake.buildClientMutex.RUnlock() + copiedInvocations := map[string][][]interface{}{} + for key, value := range fake.invocations { + copiedInvocations[key] = value + } + return copiedInvocations +} + +func (fake *UserK8sClientFactory) recordInvocation(key string, args []interface{}) { + fake.invocationsMutex.Lock() + defer fake.invocationsMutex.Unlock() + if fake.invocations == nil { + fake.invocations = map[string][][]interface{}{} + } + if fake.invocations[key] == nil { + fake.invocations[key] = [][]interface{}{} + } + fake.invocations[key] = append(fake.invocations[key], args) +} + +var _ repositories.UserK8sClientFactory = new(UserK8sClientFactory) diff --git a/api/repositories/k8s_client.go b/api/repositories/k8s_client.go index f70bd2deb..36399f70a 100644 --- a/api/repositories/k8s_client.go +++ b/api/repositories/k8s_client.go @@ -14,6 +14,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +//counterfeiter:generate -o fake -fake-name UserK8sClientFactory . UserK8sClientFactory type UserK8sClientFactory interface { BuildClient(authorization.Info) (client.WithWatch, error) } diff --git a/api/repositories/namespace_retriever.go b/api/repositories/namespace_retriever.go index 3f3082edc..2ebce69db 100644 --- a/api/repositories/namespace_retriever.go +++ b/api/repositories/namespace_retriever.go @@ -79,17 +79,22 @@ var ( } ) -type NamespaceRetriever struct { +//counterfeiter:generate -o fake -fake-name NamespaceRetriever . NamespaceRetriever +type NamespaceRetriever interface { + NamespaceFor(ctx context.Context, resourceGUID, resourceType string) (string, error) +} + +type namespaceRetriever struct { client dynamic.Interface } -func NewNamespaceRetriver(client dynamic.Interface) NamespaceRetriever { - return NamespaceRetriever{ +func NewNamespaceRetriever(client dynamic.Interface) NamespaceRetriever { + return &namespaceRetriever{ client: client, } } -func (nr NamespaceRetriever) NamespaceFor(ctx context.Context, resourceGUID, resourceType string) (string, error) { +func (nr namespaceRetriever) NamespaceFor(ctx context.Context, resourceGUID, resourceType string) (string, error) { gvr, ok := ResourceMap[resourceType] if !ok { return "", fmt.Errorf("resource type %q unknown", resourceType) diff --git a/api/repositories/org_repository.go b/api/repositories/org_repository.go index 39a844b1d..426476658 100644 --- a/api/repositories/org_repository.go +++ b/api/repositories/org_repository.go @@ -103,7 +103,7 @@ type OrgRepo struct { rootNamespace string privilegedClient client.WithWatch userClientFactory UserK8sClientFactory - nsPerms *authorization.NamespacePermissions + nsPerms NamespacePermissions timeout time.Duration authEnabled bool } @@ -112,7 +112,7 @@ func NewOrgRepo( rootNamespace string, privilegedClient client.WithWatch, userClientFactory UserK8sClientFactory, - nsPerms *authorization.NamespacePermissions, + nsPerms NamespacePermissions, timeout time.Duration, authEnabled bool, ) *OrgRepo { diff --git a/api/repositories/package_repository.go b/api/repositories/package_repository.go index 16b5bf830..65d1e7897 100644 --- a/api/repositories/package_repository.go +++ b/api/repositories/package_repository.go @@ -35,13 +35,13 @@ const ( type PackageRepo struct { userClientFactory UserK8sClientFactory namespaceRetriever NamespaceRetriever - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions } func NewPackageRepo( userClientFactory UserK8sClientFactory, namespaceRetriever NamespaceRetriever, - authPerms *authorization.NamespacePermissions, + authPerms NamespacePermissions, ) *PackageRepo { return &PackageRepo{ userClientFactory: userClientFactory, diff --git a/api/repositories/process_repository.go b/api/repositories/process_repository.go index a22bc866c..f02d0a9d3 100644 --- a/api/repositories/process_repository.go +++ b/api/repositories/process_repository.go @@ -23,7 +23,7 @@ const ( processPrefix = "cf-proc-" ) -func NewProcessRepo(namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, namespacePermissions *authorization.NamespacePermissions) *ProcessRepo { +func NewProcessRepo(namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, namespacePermissions NamespacePermissions) *ProcessRepo { return &ProcessRepo{ namespaceRetriever: namespaceRetriever, clientFactory: userClientFactory, @@ -34,7 +34,7 @@ func NewProcessRepo(namespaceRetriever NamespaceRetriever, userClientFactory Use type ProcessRepo struct { namespaceRetriever NamespaceRetriever clientFactory UserK8sClientFactory - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions } type ProcessRecord struct { diff --git a/api/repositories/repositories_suite_test.go b/api/repositories/repositories_suite_test.go index a23c4244d..206fcfc60 100644 --- a/api/repositories/repositories_suite_test.go +++ b/api/repositories/repositories_suite_test.go @@ -57,7 +57,7 @@ var ( authInfo authorization.Info rootNamespace string idProvider authorization.IdentityProvider - nsPerms *authorization.NamespacePermissions + nsPerms repositories.NamespacePermissions adminRole *rbacv1.ClusterRole spaceDeveloperRole *rbacv1.ClusterRole spaceManagerRole *rbacv1.ClusterRole @@ -106,7 +106,7 @@ var _ = BeforeSuite(func() { dynamicClient, err := dynamic.NewForConfig(k8sConfig) Expect(err).NotTo(HaveOccurred()) Expect(dynamicClient).NotTo(BeNil()) - namespaceRetriever = repositories.NewNamespaceRetriver(dynamicClient) + namespaceRetriever = repositories.NewNamespaceRetriever(dynamicClient) Expect(namespaceRetriever).NotTo(BeNil()) ctx := context.Background() diff --git a/api/repositories/route_repository.go b/api/repositories/route_repository.go index d95579652..dffe46215 100644 --- a/api/repositories/route_repository.go +++ b/api/repositories/route_repository.go @@ -27,10 +27,10 @@ const ( type RouteRepo struct { namespaceRetriever NamespaceRetriever userClientFactory UserK8sClientFactory - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions } -func NewRouteRepo(namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, authPerms *authorization.NamespacePermissions) *RouteRepo { +func NewRouteRepo(namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, authPerms NamespacePermissions) *RouteRepo { return &RouteRepo{ namespaceRetriever: namespaceRetriever, userClientFactory: userClientFactory, diff --git a/api/repositories/service_binding_repository.go b/api/repositories/service_binding_repository.go index a042cbbac..9913799de 100644 --- a/api/repositories/service_binding_repository.go +++ b/api/repositories/service_binding_repository.go @@ -25,14 +25,14 @@ const ( type ServiceBindingRepo struct { userClientFactory UserK8sClientFactory - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions namespaceRetriever NamespaceRetriever } func NewServiceBindingRepo( namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, - namespacePermissions *authorization.NamespacePermissions, + namespacePermissions NamespacePermissions, ) *ServiceBindingRepo { return &ServiceBindingRepo{ userClientFactory: userClientFactory, diff --git a/api/repositories/service_instance_repository.go b/api/repositories/service_instance_repository.go index 687750de2..e9b26e21a 100644 --- a/api/repositories/service_instance_repository.go +++ b/api/repositories/service_instance_repository.go @@ -33,13 +33,13 @@ type NamespaceGetter interface { type ServiceInstanceRepo struct { namespaceRetriever NamespaceRetriever userClientFactory UserK8sClientFactory - namespacePermissions *authorization.NamespacePermissions + namespacePermissions NamespacePermissions } func NewServiceInstanceRepo( namespaceRetriever NamespaceRetriever, userClientFactory UserK8sClientFactory, - namespacePermissions *authorization.NamespacePermissions, + namespacePermissions NamespacePermissions, ) *ServiceInstanceRepo { return &ServiceInstanceRepo{ namespaceRetriever: namespaceRetriever, diff --git a/api/repositories/types.go b/api/repositories/types.go new file mode 100644 index 000000000..157dcb218 --- /dev/null +++ b/api/repositories/types.go @@ -0,0 +1,13 @@ +package repositories + +import ( + "code.cloudfoundry.org/cf-k8s-controllers/api/authorization" + "context" +) + +//counterfeiter:generate -o fake -fake-name NamespacePermissions . NamespacePermissions +type NamespacePermissions interface { + GetAuthorizedOrgNamespaces(ctx context.Context, info authorization.Info) (map[string]bool, error) + GetAuthorizedSpaceNamespaces(ctx context.Context, info authorization.Info) (map[string]bool, error) + AuthorizedIn(ctx context.Context, identity authorization.Identity, namespace string) (bool, error) +}