Skip to content

Commit

Permalink
Report token expiry duration to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Burgey committed Dec 1, 2021
1 parent 7514c2c commit d670a56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 10 additions & 3 deletions internal/internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ func getSite(args *Args, conf *config) (s *site, err error) {
return
}
} else {
fmt.Printf("Found %d sites providing swift\n", siteCount)
fmt.Printf(" Found %d sites providing swift\n", siteCount)
siteName, err = utils.SelectString("Site", sites)
if err != nil {
return
Expand Down Expand Up @@ -793,7 +793,7 @@ func Run(args *Args) (err error) {
return
}

fmt.Printf("Searching sites providing swift for this VO\n")
fmt.Printf(" Searching sites providing swift for this VO\n")

site, err := getSite(args, config)
if err != nil {
Expand All @@ -817,7 +817,14 @@ func Run(args *Args) (err error) {
return
}

fmt.Printf("\nYou can now use the rclone remote %s like so:\n\t'rclone lsd %s:'\n", rcloneRemote, rcloneRemote)
expiresAt := *site.Auth.TokenInfo.ExpiresAt
if !expiresAt.IsZero() {
timeToTokenExpiry := time.Until(expiresAt).Truncate(time.Second)
utils.PrintWarn(fmt.Sprintf("Token expires in: %s", timeToTokenExpiry))
fmt.Print("\tYou have to rerun this tool after the token expired.")
}

fmt.Printf("\n%s You can now use the rclone remote %s using e.g.:\n\t'rclone lsd %s:'\n", utils.IconGood, rcloneRemote, rcloneRemote)

return err
}
12 changes: 9 additions & 3 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ import (
"github.com/manifoldco/promptui"
)

var (
IconGood = promptui.IconGood
IconWarn = promptui.IconWarn
IconBad = promptui.IconBad
)

func templateForSelected(kind string) string {
return fmt.Sprintf(`{{ "%s" | green }} %s: {{ . | bold }}`, promptui.IconGood, kind)
return fmt.Sprintf(`%s %s: {{ . | bold }}`, IconGood, kind)
}

func PrintWarn(errString string) {
fmt.Printf("%s %s\n", promptui.IconWarn, errString)
fmt.Printf("%s %s\n", IconWarn, errString)
}

func PrintError(errString string) {
fmt.Printf("%s %s\n", promptui.IconBad, errString)
fmt.Printf("%s %s\n", IconBad, errString)
}

// printSelected prints in the same style as if we made a choice using selectString
Expand Down

0 comments on commit d670a56

Please sign in to comment.