Skip to content

Commit

Permalink
Clean up X-Pelican-Token-Generation header creation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhiemstrawisc committed Aug 9, 2024
1 parent 194bccc commit 505d14d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ", "
Expand All @@ -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}
}
Expand Down

0 comments on commit 505d14d

Please sign in to comment.