From af243fe07c001a24a32dcad521f404ebd98a9ffb Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Tue, 17 Sep 2024 19:58:21 +0000 Subject: [PATCH] Post rebase fixups --- client/acquire_token.go | 18 +++--------------- client/main_test.go | 3 +-- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/client/acquire_token.go b/client/acquire_token.go index 3b2190212..4779cec03 100644 --- a/client/acquire_token.go +++ b/client/acquire_token.go @@ -24,6 +24,7 @@ import ( "fmt" "io/fs" "net/http" + "os" "path" "path/filepath" "strconv" @@ -117,19 +118,6 @@ func (tg *tokenGenerator) SetToken(contents string) { tg.Token.Store(&info) } -// Determine the token name if it is embedded in the scheme, Condor-style -func getTokenName(destination *url.URL) (scheme, tokenName string) { - schemePieces := strings.Split(destination.Scheme, "+") - tokenName = "" - // Scheme is always the last piece - scheme = schemePieces[len(schemePieces)-1] - // If there are 2 or more pieces, token name is everything but the last item, joined with a + - if len(schemePieces) > 1 { - tokenName = strings.Join(schemePieces[:len(schemePieces)-1], "+") - } - return -} - // Read a token from a file; ensure func getTokenFromFile(tokenLocation string) (string, error) { //Read in the JSON @@ -330,7 +318,7 @@ func (tg *tokenGenerator) getToken() (token interface{}, err error) { potentialTokens := make([]tokenInfo, 0) if tg.TokenName == "" { - _, tg.TokenName = getTokenName(tg.Destination) + tg.TokenName = tg.Destination.GetTokenName() } opts := config.TokenGenerationOpts{ @@ -376,7 +364,7 @@ func (tg *tokenGenerator) getToken() (token interface{}, err error) { opts.Operation = config.TokenSharedWrite } var contents string - contents, err = AcquireToken(tg.Destination, *tg.DirResp, opts) + contents, err = AcquireToken(tg.Destination.Path, *tg.DirResp, opts) if err == nil && contents != "" { valid, expiry := tokenIsValid(contents) info := tokenInfo{contents, expiry} diff --git a/client/main_test.go b/client/main_test.go index 8914b239c..9889f5c81 100644 --- a/client/main_test.go +++ b/client/main_test.go @@ -244,7 +244,6 @@ func TestGetToken(t *testing.T) { err = os.WriteFile(bearer_token_file, tmpFile, 0644) assert.NoError(t, err) os.Setenv("_CONDOR_CREDS", tmpDir) - // Use a valid URL, then replace the scheme pUrl, err = pelican_url.Parse("renamed.handle1+osdf:///user/ligo/frames", nil, nil) assert.NoError(t, err) token = newTokenGenerator(pUrl, &ligoDirResp, false, false) @@ -324,7 +323,7 @@ func TestGetToken(t *testing.T) { // Check that we haven't regressed on our error messages token = newTokenGenerator(pUrl, &dirResp, true, false) _, err = token.get() - assert.EqualError(t, err, "credential is required for osdf:///user/foo but was not discovered") + assert.EqualError(t, err, "credential is required for osdf:///user/ligo/frames but was not discovered") } // TestGetTokenName tests getTokenName