Skip to content

Commit

Permalink
Post rebase fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
jhiemstrawisc committed Sep 17, 2024
1 parent c8d012d commit af243fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
18 changes: 3 additions & 15 deletions client/acquire_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"io/fs"
"net/http"
"os"
"path"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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}
Expand Down
3 changes: 1 addition & 2 deletions client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af243fe

Please sign in to comment.