@@ -111,40 +111,47 @@ func (r *AuthPolicyReconciler) desiredAuthConfig(ctx context.Context, ap *api.Au
111
111
// hosts
112
112
authConfig .Spec .Hosts = hosts
113
113
114
+ commonSpec := ap .Spec .CommonSpec ()
115
+
114
116
// named patterns
115
- if namedPatterns := ap . GetNamedPatterns () ; len (namedPatterns ) > 0 {
117
+ if namedPatterns := commonSpec . NamedPatterns ; len (namedPatterns ) > 0 {
116
118
authConfig .Spec .NamedPatterns = namedPatterns
117
119
}
118
120
119
121
// top-level conditions
120
- topLevelConditionsFromRouteSelectors , err := authorinoConditionsFromRouteSelectors (route , ap )
122
+ topLevelConditionsFromRouteSelectors , err := authorinoConditionsFromRouteSelectors (route , commonSpec )
121
123
if err != nil {
122
124
return nil , err
123
125
}
124
126
if len (topLevelConditionsFromRouteSelectors ) == 0 {
125
127
topLevelConditionsFromRouteSelectors = authorinoConditionsFromHTTPRoute (route )
126
128
}
127
- if len (topLevelConditionsFromRouteSelectors ) > 0 || len (ap .GetConditions ()) > 0 {
128
- authConfig .Spec .Conditions = append (ap .GetConditions (), topLevelConditionsFromRouteSelectors ... )
129
+ if len (topLevelConditionsFromRouteSelectors ) > 0 || len (commonSpec .Conditions ) > 0 {
130
+ authConfig .Spec .Conditions = append (commonSpec .Conditions , topLevelConditionsFromRouteSelectors ... )
131
+ }
132
+
133
+ // return early if authScheme is nil
134
+ if commonSpec .AuthScheme == nil {
135
+ return authConfig , nil
129
136
}
130
137
131
138
// authentication
132
- if authentication := ap . GetAuthScheme () .Authentication ; len (authentication ) > 0 {
139
+ if authentication := commonSpec . AuthScheme .Authentication ; len (authentication ) > 0 {
133
140
authConfig .Spec .Authentication = authorinoSpecsFromConfigs (authentication , func (config api.AuthenticationSpec ) authorinoapi.AuthenticationSpec { return config .AuthenticationSpec })
134
141
}
135
142
136
143
// metadata
137
- if metadata := ap . GetAuthScheme () .Metadata ; len (metadata ) > 0 {
144
+ if metadata := commonSpec . AuthScheme .Metadata ; len (metadata ) > 0 {
138
145
authConfig .Spec .Metadata = authorinoSpecsFromConfigs (metadata , func (config api.MetadataSpec ) authorinoapi.MetadataSpec { return config .MetadataSpec })
139
146
}
140
147
141
148
// authorization
142
- if authorization := ap . GetAuthScheme () .Authorization ; len (authorization ) > 0 {
149
+ if authorization := commonSpec . AuthScheme .Authorization ; len (authorization ) > 0 {
143
150
authConfig .Spec .Authorization = authorinoSpecsFromConfigs (authorization , func (config api.AuthorizationSpec ) authorinoapi.AuthorizationSpec { return config .AuthorizationSpec })
144
151
}
145
152
146
153
// response
147
- if response := ap . GetAuthScheme () .Response ; response != nil {
154
+ if response := commonSpec . AuthScheme .Response ; response != nil {
148
155
authConfig .Spec .Response = & authorinoapi.ResponseSpec {
149
156
Unauthenticated : response .Unauthenticated ,
150
157
Unauthorized : response .Unauthorized ,
@@ -160,7 +167,7 @@ func (r *AuthPolicyReconciler) desiredAuthConfig(ctx context.Context, ap *api.Au
160
167
}
161
168
162
169
// callbacks
163
- if callbacks := ap . GetAuthScheme () .Callbacks ; len (callbacks ) > 0 {
170
+ if callbacks := commonSpec . AuthScheme .Callbacks ; len (callbacks ) > 0 {
164
171
authConfig .Spec .Callbacks = authorinoSpecsFromConfigs (callbacks , func (config api.CallbackSpec ) authorinoapi.CallbackSpec { return config .CallbackSpec })
165
172
}
166
173
@@ -187,8 +194,10 @@ func authorinoSpecsFromConfigs[T, U any](configs map[string]U, extractAuthorinoS
187
194
}
188
195
189
196
func mergeConditionsFromRouteSelectorsIntoConfigs (ap * api.AuthPolicy , route * gatewayapiv1.HTTPRoute , authConfig * authorinoapi.AuthConfig ) (* authorinoapi.AuthConfig , error ) {
197
+ commonSpec := ap .Spec .CommonSpec ()
198
+
190
199
// authentication
191
- for name , config := range ap . GetAuthScheme () .Authentication {
200
+ for name , config := range commonSpec . AuthScheme .Authentication {
192
201
conditions , err := authorinoConditionsFromRouteSelectors (route , config )
193
202
if err != nil {
194
203
return nil , err
@@ -202,7 +211,7 @@ func mergeConditionsFromRouteSelectorsIntoConfigs(ap *api.AuthPolicy, route *gat
202
211
}
203
212
204
213
// metadata
205
- for name , config := range ap . GetAuthScheme () .Metadata {
214
+ for name , config := range commonSpec . AuthScheme .Metadata {
206
215
conditions , err := authorinoConditionsFromRouteSelectors (route , config )
207
216
if err != nil {
208
217
return nil , err
@@ -216,7 +225,7 @@ func mergeConditionsFromRouteSelectorsIntoConfigs(ap *api.AuthPolicy, route *gat
216
225
}
217
226
218
227
// authorization
219
- for name , config := range ap . GetAuthScheme () .Authorization {
228
+ for name , config := range commonSpec . AuthScheme .Authorization {
220
229
conditions , err := authorinoConditionsFromRouteSelectors (route , config )
221
230
if err != nil {
222
231
return nil , err
@@ -230,7 +239,7 @@ func mergeConditionsFromRouteSelectorsIntoConfigs(ap *api.AuthPolicy, route *gat
230
239
}
231
240
232
241
// response
233
- if response := ap . GetAuthScheme () .Response ; response != nil {
242
+ if response := commonSpec . AuthScheme .Response ; response != nil {
234
243
// response success headers
235
244
for name , config := range response .Success .Headers {
236
245
conditions , err := authorinoConditionsFromRouteSelectors (route , config )
@@ -261,7 +270,7 @@ func mergeConditionsFromRouteSelectorsIntoConfigs(ap *api.AuthPolicy, route *gat
261
270
}
262
271
263
272
// callbacks
264
- for name , config := range ap . GetAuthScheme () .Callbacks {
273
+ for name , config := range commonSpec . AuthScheme .Callbacks {
265
274
conditions , err := authorinoConditionsFromRouteSelectors (route , config )
266
275
if err != nil {
267
276
return nil , err
0 commit comments