@@ -14,40 +14,38 @@ import (
14
14
"unicode"
15
15
)
16
16
17
- func (b * defaultModelBuilder ) buildActions (ctx context.Context , stack core.Stack , ingGroupID GroupID , tgByID map [string ]* elbv2model.TargetGroup ,
18
- protocol elbv2model.Protocol , ing * networking.Ingress , backend EnhancedBackend ) ([]elbv2model.Action , error ) {
17
+ func (t * defaultModelBuildTask ) buildActions (ctx context.Context , protocol elbv2model.Protocol , ing * networking.Ingress , backend EnhancedBackend ) ([]elbv2model.Action , error ) {
19
18
var actions []elbv2model.Action
20
19
if protocol == elbv2model .ProtocolHTTPS {
21
- authAction , err := b .buildAuthAction (ctx , ing , backend )
20
+ authAction , err := t .buildAuthAction (ctx , ing , backend )
22
21
if err != nil {
23
22
return nil , err
24
23
}
25
24
if authAction != nil {
26
25
actions = append (actions , * authAction )
27
26
}
28
27
}
29
- backendAction , err := b .buildBackendAction (ctx , stack , ingGroupID , tgByID , ing , backend .Action )
28
+ backendAction , err := t .buildBackendAction (ctx , ing , backend .Action )
30
29
if err != nil {
31
30
return nil , err
32
31
}
33
32
actions = append (actions , backendAction )
34
33
return actions , nil
35
34
}
36
35
37
- func (b * defaultModelBuilder ) buildBackendAction (ctx context.Context , stack core.Stack , ingGroupID GroupID ,
38
- tgByID map [string ]* elbv2model.TargetGroup , ing * networking.Ingress , actionCfg Action ) (elbv2model.Action , error ) {
36
+ func (t * defaultModelBuildTask ) buildBackendAction (ctx context.Context , ing * networking.Ingress , actionCfg Action ) (elbv2model.Action , error ) {
39
37
switch actionCfg .Type {
40
38
case ActionTypeFixedResponse :
41
- return b .buildFixedResponseAction (ctx , actionCfg )
39
+ return t .buildFixedResponseAction (ctx , actionCfg )
42
40
case ActionTypeRedirect :
43
- return b .buildRedirectAction (ctx , actionCfg )
41
+ return t .buildRedirectAction (ctx , actionCfg )
44
42
case ActionTypeForward :
45
- return b .buildForwardAction (ctx , stack , ingGroupID , tgByID , ing , actionCfg )
43
+ return t .buildForwardAction (ctx , ing , actionCfg )
46
44
}
47
45
return elbv2model.Action {}, errors .Errorf ("unknown action type: %v" , actionCfg .Type )
48
46
}
49
47
50
- func (b * defaultModelBuilder ) buildAuthAction (ctx context.Context , ing * networking.Ingress , backend EnhancedBackend ) (* elbv2model.Action , error ) {
48
+ func (t * defaultModelBuildTask ) buildAuthAction (ctx context.Context , ing * networking.Ingress , backend EnhancedBackend ) (* elbv2model.Action , error ) {
51
49
// if a single service is used as backend, then it's auth configuration via annotation will take priority than ingress.
52
50
svcAndIngAnnotations := ing .Annotations
53
51
if backend .Action .Type == ActionTypeForward && len (backend .Action .ForwardConfig .TargetGroups ) == 1 && backend .Action .ForwardConfig .TargetGroups [0 ].ServiceName != nil {
@@ -57,24 +55,25 @@ func (b *defaultModelBuilder) buildAuthAction(ctx context.Context, ing *networki
57
55
Name : svcName ,
58
56
}
59
57
svc := & corev1.Service {}
60
- if err := b .k8sClient .Get (ctx , svcKey , svc ); err != nil {
58
+ if err := t .k8sClient .Get (ctx , svcKey , svc ); err != nil {
61
59
return nil , err
62
60
}
63
61
svcAndIngAnnotations = algorithm .MergeStringMap (svc .Annotations , svcAndIngAnnotations )
64
62
}
65
- authCfg , err := b .authConfigBuilder .Build (ctx , svcAndIngAnnotations )
63
+
64
+ authCfg , err := t .authConfigBuilder .Build (ctx , svcAndIngAnnotations )
66
65
if err != nil {
67
66
return nil , err
68
67
}
69
68
switch authCfg .Type {
70
69
case AuthTypeCognito :
71
- action , err := b .buildAuthenticateCognitoAction (ctx , authCfg )
70
+ action , err := t .buildAuthenticateCognitoAction (ctx , authCfg )
72
71
if err != nil {
73
72
return nil , err
74
73
}
75
74
return & action , nil
76
75
case AuthTypeOIDC :
77
- action , err := b .buildAuthenticateOIDCAction (ctx , authCfg , ing .Namespace )
76
+ action , err := t .buildAuthenticateOIDCAction (ctx , authCfg , ing .Namespace )
78
77
if err != nil {
79
78
return nil , err
80
79
}
@@ -84,7 +83,7 @@ func (b *defaultModelBuilder) buildAuthAction(ctx context.Context, ing *networki
84
83
}
85
84
}
86
85
87
- func (b * defaultModelBuilder ) buildFixedResponseAction (ctx context.Context , actionCfg Action ) (elbv2model.Action , error ) {
86
+ func (t * defaultModelBuildTask ) buildFixedResponseAction (_ context.Context , actionCfg Action ) (elbv2model.Action , error ) {
88
87
if actionCfg .FixedResponseConfig == nil {
89
88
return elbv2model.Action {}, errors .New ("missing FixedResponseConfig" )
90
89
}
@@ -98,7 +97,7 @@ func (b *defaultModelBuilder) buildFixedResponseAction(ctx context.Context, acti
98
97
}, nil
99
98
}
100
99
101
- func (b * defaultModelBuilder ) buildRedirectAction (ctx context.Context , actionCfg Action ) (elbv2model.Action , error ) {
100
+ func (t * defaultModelBuildTask ) buildRedirectAction (_ context.Context , actionCfg Action ) (elbv2model.Action , error ) {
102
101
if actionCfg .RedirectConfig == nil {
103
102
return elbv2model.Action {}, errors .New ("missing RedirectConfig" )
104
103
}
@@ -115,11 +114,11 @@ func (b *defaultModelBuilder) buildRedirectAction(ctx context.Context, actionCfg
115
114
}, nil
116
115
}
117
116
118
- func (b * defaultModelBuilder ) buildForwardAction (ctx context.Context , stack core.Stack , ingGroupID GroupID ,
119
- tgByID map [string ]* elbv2model.TargetGroup , ing * networking.Ingress , actionCfg Action ) (elbv2model.Action , error ) {
117
+ func (t * defaultModelBuildTask ) buildForwardAction (ctx context.Context , ing * networking.Ingress , actionCfg Action ) (elbv2model.Action , error ) {
120
118
if actionCfg .ForwardConfig == nil {
121
119
return elbv2model.Action {}, errors .New ("missing ForwardConfig" )
122
120
}
121
+
123
122
var targetGroupTuples []elbv2model.TargetGroupTuple
124
123
for _ , tgt := range actionCfg .ForwardConfig .TargetGroups {
125
124
var tgARN core.StringToken
@@ -131,10 +130,10 @@ func (b *defaultModelBuilder) buildForwardAction(ctx context.Context, stack core
131
130
Name : awssdk .StringValue (tgt .ServiceName ),
132
131
}
133
132
svc := & corev1.Service {}
134
- if err := b .k8sClient .Get (ctx , svcKey , svc ); err != nil {
133
+ if err := t .k8sClient .Get (ctx , svcKey , svc ); err != nil {
135
134
return elbv2model.Action {}, err
136
135
}
137
- tg , err := b .buildTargetGroup (ctx , stack , ingGroupID , tgByID , ing , svc , * tgt .ServicePort )
136
+ tg , err := t .buildTargetGroup (ctx , ing , svc , * tgt .ServicePort )
138
137
if err != nil {
139
138
return elbv2model.Action {}, err
140
139
}
@@ -162,7 +161,7 @@ func (b *defaultModelBuilder) buildForwardAction(ctx context.Context, stack core
162
161
}, nil
163
162
}
164
163
165
- func (b * defaultModelBuilder ) buildAuthenticateCognitoAction (ctx context.Context , authCfg AuthConfig ) (elbv2model.Action , error ) {
164
+ func (t * defaultModelBuildTask ) buildAuthenticateCognitoAction (_ context.Context , authCfg AuthConfig ) (elbv2model.Action , error ) {
166
165
if authCfg .IDPConfigCognito == nil {
167
166
return elbv2model.Action {}, errors .New ("missing IDPConfigCognito" )
168
167
}
@@ -182,7 +181,7 @@ func (b *defaultModelBuilder) buildAuthenticateCognitoAction(ctx context.Context
182
181
}, nil
183
182
}
184
183
185
- func (b * defaultModelBuilder ) buildAuthenticateOIDCAction (ctx context.Context , authCfg AuthConfig , namespace string ) (elbv2model.Action , error ) {
184
+ func (t * defaultModelBuildTask ) buildAuthenticateOIDCAction (ctx context.Context , authCfg AuthConfig , namespace string ) (elbv2model.Action , error ) {
186
185
if authCfg .IDPConfigOIDC == nil {
187
186
return elbv2model.Action {}, errors .New ("missing IDPConfigOIDC" )
188
187
}
@@ -192,9 +191,10 @@ func (b *defaultModelBuilder) buildAuthenticateOIDCAction(ctx context.Context, a
192
191
Name : authCfg .IDPConfigOIDC .SecretName ,
193
192
}
194
193
secret := & corev1.Secret {}
195
- if err := b .k8sClient .Get (ctx , secretKey , secret ); err != nil {
194
+ if err := t .k8sClient .Get (ctx , secretKey , secret ); err != nil {
196
195
return elbv2model.Action {}, err
197
196
}
197
+
198
198
clientID := strings .TrimRightFunc (string (secret .Data ["clientId" ]), unicode .IsSpace )
199
199
clientSecret := string (secret .Data ["clientSecret" ])
200
200
return elbv2model.Action {
@@ -215,7 +215,7 @@ func (b *defaultModelBuilder) buildAuthenticateOIDCAction(ctx context.Context, a
215
215
}, nil
216
216
}
217
217
218
- func (b * defaultModelBuilder ) build404Action (ctx context.Context ) elbv2model.Action {
218
+ func (t * defaultModelBuildTask ) build404Action (_ context.Context ) elbv2model.Action {
219
219
return elbv2model.Action {
220
220
Type : elbv2model .ActionTypeFixedResponse ,
221
221
FixedResponseConfig : & elbv2model.FixedResponseActionConfig {
0 commit comments