Skip to content

Commit

Permalink
do not check token before the actual operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjiangshu committed Sep 3, 2024
1 parent f97d05d commit 7137645
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions sda-admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 7137645

Please sign in to comment.