Skip to content

Commit

Permalink
Merge branch 'main' of github.com:PelicanPlatform/pelican into cache-…
Browse files Browse the repository at this point in the history
…watermarks
  • Loading branch information
haoming29 committed Apr 4, 2024
2 parents c8101dd + dd9cbae commit 2d01938
Show file tree
Hide file tree
Showing 75 changed files with 4,342 additions and 851 deletions.
3 changes: 2 additions & 1 deletion .github/scripts/validate-parameters/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"OIDCAuthenticationRequirements",
"AuthorizationTemplates",
"IPMapping",
"Exports"
"Exports",
"Lots"
]


Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ builds:
tags:
- forceposix
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser -X github.com/pelicanplatform/pelican/config.version={{.Version}}
- -s -w -X github.com/pelicanplatform/pelican/config.commit={{.Commit}} -X github.com/pelicanplatform/pelican/config.date={{.Date}} -X github.com/pelicanplatform/pelican/config.builtBy=goreleaser -X github.com/pelicanplatform/pelican/config.version={{.Version}}
ignore:
- goos: windows
goarch: arm64
Expand Down
36 changes: 7 additions & 29 deletions client/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,18 @@ import (
"strconv"
"strings"

"github.com/pelicanplatform/pelican/config"
namespaces "github.com/pelicanplatform/pelican/namespaces"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/pelicanplatform/pelican/config"
namespaces "github.com/pelicanplatform/pelican/namespaces"
"github.com/pelicanplatform/pelican/utils"
)

type directorResponse struct {
Error string `json:"error"`
}

// Simple parser to that takes a "values" string from a header and turns it
// into a map of key/value pairs
func HeaderParser(values string) (retMap map[string]string) {
retMap = map[string]string{}

// Some headers might not have values, such as the
// X-OSDF-Authorization header when the resource is public
if values == "" {
return
}

mapPairs := strings.Split(values, ",")
for _, pair := range mapPairs {
// Remove any unwanted spaces
pair = strings.ReplaceAll(pair, " ", "")

// Break out key/value pairs and put in the map
split := strings.Split(pair, "=")
retMap[split[0]] = split[1]
}

return retMap
}

// Given the Director response, create the ordered list of caches
// and store it as namespace.SortedDirectorCaches
func CreateNsFromDirectorResp(dirResp *http.Response) (namespace namespaces.Namespace, err error) {
Expand All @@ -70,7 +48,7 @@ func CreateNsFromDirectorResp(dirResp *http.Response) (namespace namespaces.Name
err = errors.New("Pelican director did not include mandatory X-Pelican-Namespace header in response")
return
}
xPelicanNamespace := HeaderParser(pelicanNamespaceHdr[0])
xPelicanNamespace := utils.HeaderParser(pelicanNamespaceHdr[0])
namespace.Path = xPelicanNamespace["namespace"]
namespace.UseTokenOnRead, _ = strconv.ParseBool(xPelicanNamespace["require-token"])
namespace.ReadHTTPS, _ = strconv.ParseBool(xPelicanNamespace["readhttps"])
Expand All @@ -82,15 +60,15 @@ func CreateNsFromDirectorResp(dirResp *http.Response) (namespace namespaces.Name
//So it's a map entry - HeaderParser returns a max entry
//We want to appen the value
for _, authEntry := range dirResp.Header.Values("X-Pelican-Authorization") {
parsedEntry := HeaderParser(authEntry)
parsedEntry := utils.HeaderParser(authEntry)
xPelicanAuthorization = append(xPelicanAuthorization, parsedEntry["issuer"])
}
namespace.Issuer = xPelicanAuthorization
}

var xPelicanTokenGeneration map[string]string
if len(dirResp.Header.Values("X-Pelican-Token-Generation")) > 0 {
xPelicanTokenGeneration = HeaderParser(dirResp.Header.Values("X-Pelican-Token-Generation")[0])
xPelicanTokenGeneration = utils.HeaderParser(dirResp.Header.Values("X-Pelican-Token-Generation")[0])

// Instantiate the cred gen struct
namespace.CredentialGen = &namespaces.CredentialGeneration{}
Expand Down
16 changes: 2 additions & 14 deletions client/director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,9 @@ import (
"github.com/stretchr/testify/assert"

namespaces "github.com/pelicanplatform/pelican/namespaces"
"github.com/pelicanplatform/pelican/utils"
)

func TestHeaderParser(t *testing.T) {
header1 := "namespace=/foo/bar, issuer = https://get-your-tokens.org, readhttps=False"
newMap1 := HeaderParser(header1)

assert.Equal(t, "/foo/bar", newMap1["namespace"])
assert.Equal(t, "https://get-your-tokens.org", newMap1["issuer"])
assert.Equal(t, "False", newMap1["readhttps"])

header2 := ""
newMap2 := HeaderParser(header2)
assert.Equal(t, map[string]string{}, newMap2)
}

func TestGetCachesFromDirectorResponse(t *testing.T) {
// Construct the Director's Response, comprising headers and a body
directorHeaders := make(map[string][]string)
Expand Down Expand Up @@ -125,7 +113,7 @@ func TestCreateNsFromDirectorResp(t *testing.T) {
var xPelicanAuthorization map[string]string
var issuer string
if len(directorResponse.Header.Values("X-Pelican-Authorization")) > 0 {
xPelicanAuthorization = HeaderParser(directorResponse.Header.Values("X-Pelican-Authorization")[0])
xPelicanAuthorization = utils.HeaderParser(directorResponse.Header.Values("X-Pelican-Authorization")[0])
issuer = xPelicanAuthorization["issuer"]
}

Expand Down
Loading

0 comments on commit 2d01938

Please sign in to comment.