Skip to content

Commit

Permalink
refactor GlobusLogin function for simpler return signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Consolethinks committed Sep 2, 2024
1 parent 61b6117 commit 128f69f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
15 changes: 7 additions & 8 deletions cmd/cliutils/globusLogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gopkg.in/yaml.v2"
)

type globusConfig struct {
type GlobusConfig struct {
ClientID string `yaml:"client-id"`
ClientSecret string `yaml:"client-secret,omitempty"`
RedirectURL string `yaml:"redirect-url"`
Expand All @@ -21,16 +21,15 @@ type globusConfig struct {
DestinationPrefixPath string `yaml:"destination-prefix-path,omitempty"`
}

func GlobusLogin(confPath string) (gClient globus.GlobusClient, srcCollection string, srcPrefixPath string, destCollection string, destPrefixPath string, err error) {
func GlobusLogin(confPath string) (gClient globus.GlobusClient, gConfig GlobusConfig, err error) {
// read in config
data, err := os.ReadFile(confPath)
if err != nil {
return globus.GlobusClient{}, "", "", "", "", fmt.Errorf("can't read globus config: %v", err)
return globus.GlobusClient{}, GlobusConfig{}, fmt.Errorf("can't read globus config: %v", err)
}
var gConfig globusConfig
err = yaml.Unmarshal(data, &gConfig)
if err != nil {
return globus.GlobusClient{}, "", "", "", "", fmt.Errorf("can't unmarshal globus config: %v", err)
return globus.GlobusClient{}, GlobusConfig{}, fmt.Errorf("can't unmarshal globus config: %v", err)
}

// config setup
Expand All @@ -46,13 +45,13 @@ func GlobusLogin(confPath string) (gClient globus.GlobusClient, srcCollection st
// negotiate token and create client
var code string
if _, err := fmt.Scan(&code); err != nil {
return globus.GlobusClient{}, "", "", "", "", err
return globus.GlobusClient{}, GlobusConfig{}, err
}
tok, err := clientConfig.Exchange(ctx, code, oauth2.VerifierOption(verifier))
if err != nil {
return globus.GlobusClient{}, "", "", "", "", fmt.Errorf("oauth2 exchange failed: %v", err)
return globus.GlobusClient{}, GlobusConfig{}, fmt.Errorf("oauth2 exchange failed: %v", err)
}

// return globus client
return globus.HttpClientToGlobusClient(clientConfig.Client(ctx, tok)), gConfig.SourceCollection, gConfig.SourcePrefixPath, gConfig.DestinationCollection, gConfig.DestinationPrefixPath, nil
return globus.HttpClientToGlobusClient(clientConfig.Client(ctx, tok)), gConfig, nil
}
12 changes: 6 additions & 6 deletions cmd/commands/datasetIngestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ For Windows you need instead to specify -user username:password on the command l

// globus specific vars (if needed)
var globusClient globus.GlobusClient
var srcCollection, srcPrefixPath, destCollection, destPrefixPath string
var gConfig cliutils.GlobusConfig

switch transferType {
case Ssh:
Expand All @@ -109,7 +109,7 @@ For Windows you need instead to specify -user username:password on the command l
globusConfigPath = filepath.Join(filepath.Dir(execPath), "globus.yaml")
}

globusClient, srcCollection, srcPrefixPath, destCollection, destPrefixPath, err = cliutils.GlobusLogin(globusConfigPath)
globusClient, gConfig, err = cliutils.GlobusLogin(globusConfigPath)
if err != nil {
log.Fatalln("couldn't create globus client:", err)
}
Expand Down Expand Up @@ -449,10 +449,10 @@ For Windows you need instead to specify -user username:password on the command l
},
GlobusParams: cliutils.GlobusParams{
GlobusClient: globusClient,
SrcCollection: srcCollection,
SrcPrefixPath: srcPrefixPath,
DestCollection: destCollection,
DestPrefixPath: destPrefixPath,
SrcCollection: gConfig.SourceCollection,
SrcPrefixPath: gConfig.SourcePrefixPath,
DestCollection: gConfig.DestinationCollection,
DestPrefixPath: gConfig.DestinationPrefixPath,
Filelist: filePathList,
IsSymlinkList: isSymlinkList,
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/commands/globusCheckTransfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ For further help see "` + MANUAL + `"`,
user, _ = authenticate(RealAuthenticator{}, client, APIServer, userpass, token)
}

globusClient, _, srcPrefixPath, _, _, err := cliutils.GlobusLogin(globusConfigPath)
globusClient, gConfig, err := cliutils.GlobusLogin(globusConfigPath)
if err != nil {
log.Fatalf("Couldn't create globus client: %v\n", err)
}
Expand All @@ -160,7 +160,7 @@ For further help see "` + MANUAL + `"`,

// get source and dest folders
sourceFolder := *task.SourceBasePath
sourceFolder = strings.TrimPrefix(sourceFolder, srcPrefixPath)
sourceFolder = strings.TrimPrefix(sourceFolder, gConfig.SourcePrefixPath)
sourceFolder = strings.TrimSuffix(sourceFolder, "/")
var destFolder string
if !skipDestPathCheck {
Expand Down

0 comments on commit 128f69f

Please sign in to comment.