@@ -11,22 +11,36 @@ import (
1111
1212	ocv1 "github.com/operator-framework/operator-controller/api/v1" 
1313	"github.com/operator-framework/operator-controller/internal/operator-controller/authentication" 
14+ 	"github.com/operator-framework/operator-controller/internal/operator-controller/features" 
1415)
1516
16- func  ClusterExtensionUserRestConfigMapper (tokenGetter  * authentication.TokenGetter ) func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
17- 	saRestConfigMapper  :=  serviceAccountRestConfigMapper (tokenGetter )
18- 	synthRestConfigMapper  :=  sythenticUserRestConfigMapper ()
17+ const  syntheticServiceAccountName  =  "olmv1:synthetic" 
18+ 
19+ type  clusterExtensionRestConfigMapper  struct  {
20+ 	saRestConfigMapper         func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error )
21+ 	synthUserRestConfigMapper  func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error )
22+ }
1923
24+ func  (m  * clusterExtensionRestConfigMapper ) mapper () func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
25+ 	synthAuthFeatureEnabled  :=  features .OperatorControllerFeatureGate .Enabled (features .SyntheticPermissions )
2026	return  func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
2127		cExt  :=  o .(* ocv1.ClusterExtension )
22- 		if  cExt .Spec .ServiceAccount   !=   nil  {  //nolint:staticcheck 
23- 			return  saRestConfigMapper (ctx , o , c )
28+ 		if  synthAuthFeatureEnabled   &&   cExt .Spec .ServiceAccount . Name   ==   syntheticServiceAccountName  { 
29+ 			return  m . synthUserRestConfigMapper (ctx , o , c )
2430		}
25- 		return  synthRestConfigMapper (ctx , o , c )
31+ 		return  m .saRestConfigMapper (ctx , o , c )
32+ 	}
33+ }
34+ 
35+ func  ClusterExtensionUserRestConfigMapper (tokenGetter  * authentication.TokenGetter ) func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
36+ 	m  :=  & clusterExtensionRestConfigMapper {
37+ 		saRestConfigMapper :        serviceAccountRestConfigMapper (tokenGetter ),
38+ 		synthUserRestConfigMapper : syntheticUserRestConfigMapper (),
2639	}
40+ 	return  m .mapper ()
2741}
2842
29- func  sythenticUserRestConfigMapper () func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
43+ func  syntheticUserRestConfigMapper () func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
3044	return  func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
3145		cExt  :=  o .(* ocv1.ClusterExtension )
3246		cc  :=  rest .CopyConfig (c )
@@ -41,7 +55,7 @@ func serviceAccountRestConfigMapper(tokenGetter *authentication.TokenGetter) fun
4155	return  func (ctx  context.Context , o  client.Object , c  * rest.Config ) (* rest.Config , error ) {
4256		cExt  :=  o .(* ocv1.ClusterExtension )
4357		saKey  :=  types.NamespacedName {
44- 			Name :      cExt .Spec .ServiceAccount .Name ,  //nolint:staticcheck 
58+ 			Name :      cExt .Spec .ServiceAccount .Name ,
4559			Namespace : cExt .Spec .Namespace ,
4660		}
4761		saConfig  :=  rest .AnonymousClientConfig (c )
0 commit comments