From 505d14d9dc943cbc98004ad70a9fad2fcf26a79b Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Fri, 9 Aug 2024 20:41:41 +0000 Subject: [PATCH] Clean up X-Pelican-Token-Generation header creation Two changes here -- move the addition of base path into the hdrKey iteration, and don't include the max scope depth if 0, which is a) invalid and b) the default value of variable we get it from when nothing is set. --- director/director.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/director/director.go b/director/director.go index dc96131e3..b3915d55c 100644 --- a/director/director.go +++ b/director/director.go @@ -225,10 +225,13 @@ func generateXTokenGenHeader(ginCtx *gin.Context, namespaceAd server_structs.Nam hdrVals := []string{namespaceAd.Generation[0].CredentialIssuer.String(), fmt.Sprint(namespaceAd.Generation[0].MaxScopeDepth), string(namespaceAd.Generation[0].Strategy), basePath} - for idx, hdrKey := range []string{"issuer", "max-scope-depth", "strategy"} { + for idx, hdrKey := range []string{"issuer", "max-scope-depth", "strategy", "base-path"} { hdrVal := hdrVals[idx] if hdrVal == "" { continue + } else if hdrKey == "max-scope-depth" && hdrVal == "0" { + // don't send a 0 max-scope-depth because it's malformed and probably means there should be no token generation header + continue } if !first { tokenGen += ", " @@ -237,10 +240,6 @@ func generateXTokenGenHeader(ginCtx *gin.Context, namespaceAd server_structs.Nam tokenGen += hdrKey + "=" + hdrVal } - if basePath != "" { - tokenGen += ", base-path=" + basePath - } - if tokenGen != "" { ginCtx.Writer.Header()["X-Pelican-Token-Generation"] = []string{tokenGen} }