Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Sep 4, 2024
1 parent 11a32e6 commit 3d43aef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
49 changes: 21 additions & 28 deletions controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf

interfacedResponseConfigs := make([]auth.AuthConfigEvaluator, 0)

if authConfig.Spec.Response != nil {
for responseName, headerResponse := range authConfig.Spec.Response.Success.Headers {
if responseConfig := authConfig.Spec.Response; responseConfig != nil {
for responseName, headerResponse := range responseConfig.Success.Headers {
translatedResponse := evaluators.NewResponseConfig(
responseName,
headerResponse.Priority,
Expand All @@ -486,22 +486,11 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
headerResponse.Metrics,
)

if headerResponse.Cache != nil {
ttl := headerResponse.Cache.TTL
if ttl == 0 {
ttl = api.EvaluatorDefaultCacheTTL
}
translatedResponse.Cache = evaluators.NewEvaluatorCache(
*getJsonFromStaticDynamic(&headerResponse.Cache.Key),
ttl,
)
}
injectCache(headerResponse.Cache, translatedResponse)
interfacedResponseConfigs = append(interfacedResponseConfigs, translatedResponse)
}
}

if authConfig.Spec.Response != nil {
for responseName, response := range authConfig.Spec.Response.Success.DynamicMetadata {
for responseName, response := range responseConfig.Success.DynamicMetadata {
translatedResponse := evaluators.NewResponseConfig(
responseName,
response.Priority,
Expand All @@ -511,16 +500,7 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
response.Metrics,
)

if response.Cache != nil {
ttl := response.Cache.TTL
if ttl == 0 {
ttl = api.EvaluatorDefaultCacheTTL
}
translatedResponse.Cache = evaluators.NewEvaluatorCache(
*getJsonFromStaticDynamic(&response.Cache.Key),
ttl,
)
}
injectCache(response.Cache, translatedResponse)

switch response.GetMethod() {
// wristband
Expand Down Expand Up @@ -641,18 +621,31 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
}

// denyWith
if authConfig.Spec.Response != nil {
if denyWith := authConfig.Spec.Response.Unauthenticated; denyWith != nil {
if responseConfig := authConfig.Spec.Response; responseConfig != nil {
if denyWith := responseConfig.Unauthenticated; denyWith != nil {
translatedAuthConfig.Unauthenticated = buildAuthorinoDenyWithValues(denyWith)
}
if denyWith := authConfig.Spec.Response.Unauthorized; denyWith != nil {
if denyWith := responseConfig.Unauthorized; denyWith != nil {
translatedAuthConfig.Unauthorized = buildAuthorinoDenyWithValues(denyWith)
}
}

return translatedAuthConfig, nil
}

func injectCache(cache *api.EvaluatorCaching, translatedResponse *evaluators.ResponseConfig) {
if cache != nil {
ttl := cache.TTL
if ttl == 0 {
ttl = api.EvaluatorDefaultCacheTTL
}
translatedResponse.Cache = evaluators.NewEvaluatorCache(
*getJsonFromStaticDynamic(&cache.Key),
ttl,
)
}
}

func (r *AuthConfigReconciler) addToIndex(ctx context.Context, resourceNamespace, resourceId string, authConfig *evaluators.AuthConfig, hosts []string) (linkedHosts, looseHosts []string, err error) {
logger := log.FromContext(ctx)
linkedHosts = []string{}
Expand Down
5 changes: 5 additions & 0 deletions controllers/auth_config_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ func updateStatusSummary(authConfig *api.AuthConfig, newLinkedHosts []string) (c

func issuingWristbands(authConfig *api.AuthConfig) bool {
if authConfig.Spec.Response != nil {
for _, responseConfig := range authConfig.Spec.Response.Success.Headers {
if responseConfig.GetMethod() == api.WristbandAuthResponse {
return true
}
}
for _, responseConfig := range authConfig.Spec.Response.Success.DynamicMetadata {
if responseConfig.GetMethod() == api.WristbandAuthResponse {
return true
Expand Down

0 comments on commit 3d43aef

Please sign in to comment.