@@ -11,22 +11,36 @@ import (
11
11
12
12
ocv1 "github.com/operator-framework/operator-controller/api/v1"
13
13
"github.com/operator-framework/operator-controller/internal/operator-controller/authentication"
14
+ "github.com/operator-framework/operator-controller/internal/operator-controller/features"
14
15
)
15
16
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
+ }
19
23
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 )
20
26
return func (ctx context.Context , o client.Object , c * rest.Config ) (* rest.Config , error ) {
21
27
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 )
24
30
}
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 (),
26
39
}
40
+ return m .mapper ()
27
41
}
28
42
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 ) {
30
44
return func (ctx context.Context , o client.Object , c * rest.Config ) (* rest.Config , error ) {
31
45
cExt := o .(* ocv1.ClusterExtension )
32
46
cc := rest .CopyConfig (c )
@@ -41,7 +55,7 @@ func serviceAccountRestConfigMapper(tokenGetter *authentication.TokenGetter) fun
41
55
return func (ctx context.Context , o client.Object , c * rest.Config ) (* rest.Config , error ) {
42
56
cExt := o .(* ocv1.ClusterExtension )
43
57
saKey := types.NamespacedName {
44
- Name : cExt .Spec .ServiceAccount .Name , //nolint:staticcheck
58
+ Name : cExt .Spec .ServiceAccount .Name ,
45
59
Namespace : cExt .Spec .Namespace ,
46
60
}
47
61
saConfig := rest .AnonymousClientConfig (c )
0 commit comments