From 7137645d18162b2b03262159fa1dd60b23fa7d1a Mon Sep 17 00:00:00 2001 From: nanjiangshu Date: Tue, 3 Sep 2024 11:48:57 +0200 Subject: [PATCH] do not check token before the actual operation --- sda-admin/main.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sda-admin/main.go b/sda-admin/main.go index fd49d3e35..5da111543 100644 --- a/sda-admin/main.go +++ b/sda-admin/main.go @@ -45,8 +45,7 @@ Additional Commands: // Subcommand usage functions func listUsage() { - usageText := `List Operations: - + usageText := ` List Users: Usage: sda-admin list users List all users in the system. @@ -176,6 +175,13 @@ func printVersion() { fmt.Printf("sda-admin version %s\n", version) } +func checkToken(token string) { + if err := helpers.CheckTokenExpiration(token); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } +} + func main() { // Set up flags flag.StringVar(&api_uri, "uri", "", "Set the URI for the SDA server (optional if API_HOST is set)") @@ -206,12 +212,6 @@ func main() { } } - err := helpers.CheckTokenExpiration(token) - if err != nil { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) - os.Exit(1) - } - // Ensure there is a subcommand if flag.NArg() < 1 { fmt.Println("Error: a command is required.") @@ -276,6 +276,7 @@ func main() { } switch flag.Arg(1) { case "users": + checkToken(token) err := list.ListUsers(api_uri, token) if err != nil { fmt.Printf("Error: failed to get users, reason: %v\n", err) @@ -285,6 +286,7 @@ func main() { var username string listFilesCmd.StringVar(&username, "user", "", "Filter files by username") listFilesCmd.Parse(flag.Args()[2:]) + checkToken(token) err := list.ListFiles(api_uri, token, username) if err != nil { fmt.Printf("Error: failed to get files, reason: %v\n", err) @@ -314,6 +316,7 @@ func main() { os.Exit(1) } + checkToken(token) err := file.FileIngest(api_uri, token, username, filepath) if err != nil { fmt.Printf("Error: failed to ingest file, reason: %v\n", err) @@ -334,6 +337,7 @@ func main() { os.Exit(1) } + checkToken(token) err := file.FileAccession(api_uri, token, username, filepath, accessionID) if err != nil { fmt.Printf("Error: failed to assign accession ID to file, reason: %v\n", err) @@ -365,6 +369,7 @@ func main() { os.Exit(1) } + checkToken(token) err := dataset.DatasetCreate(api_uri, token, datasetID, accessionIDs) if err != nil { fmt.Printf("Error: failed to create dataset, reason: %v\n", err) @@ -383,6 +388,7 @@ func main() { os.Exit(1) } + checkToken(token) err := dataset.DatasetRelease(api_uri, token, datasetID) if err != nil { fmt.Printf("Error: failed to release dataset, reason: %v\n", err)