Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit f1cccbe

Browse files
committed
scout hint: tell user logging in is required
The `docker scout quickview` hint, displayed after a user pulls or builds an image, only works if the user is logged in to Hub. Check if user isn't logged in, and make hint more explicit in this case. Signed-off-by: Laura Brehm <[email protected]>
1 parent d22f3a8 commit f1cccbe

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

cli/mobycli/scout_suggest.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"strings"
2323

24+
"github.com/docker/cli/cli/config"
2425
"github.com/docker/compose/v2/pkg/utils"
2526

2627
"github.com/fatih/color"
@@ -53,10 +54,14 @@ func displayScoutQuickViewSuggestMsg(image string) {
5354
}
5455
out := os.Stderr
5556
b := color.New(color.Bold)
56-
_, _ = fmt.Fprintln(out)
57-
_, _ = b.Fprintln(out, "What's Next?")
58-
_, _ = fmt.Fprintf(out, " View summary of image vulnerabilities and recommendations → %s", color.CyanString("docker scout quickview%s", image))
59-
_, _ = fmt.Fprintln(out)
57+
58+
_, _ = b.Fprintln(out, "\nWhat's Next?")
59+
if !hubLoggedIn() {
60+
_, _ = fmt.Fprintf(out, " View summary of image vulnerabilities and recommendations (login required) → %s\n", color.CyanString("docker scout quickview%s", image))
61+
_, _ = fmt.Fprint(out, " To sign in, use the `docker login` command or sign in via Docker Desktop\n")
62+
} else {
63+
_, _ = fmt.Fprintf(out, " View summary of image vulnerabilities and recommendations → %s\n", color.CyanString("docker scout quickview%s", image))
64+
}
6065
}
6166

6267
func pulledImageFromArgs(args []string) string {
@@ -74,3 +79,17 @@ func pulledImageFromArgs(args []string) string {
7479
}
7580
return image
7681
}
82+
83+
// hubLoggedIn checks whether the user has credentials configured
84+
// for Docker Hub. This can be an expensive operation, so use it
85+
// mindfully.
86+
func hubLoggedIn() bool {
87+
// todo: run this with a timeout, this call can be slow (esp. on Windows)
88+
// and we don't want to hang execution here while we check
89+
hubAuth, err := config.LoadDefaultConfigFile(nil).GetAuthConfig("index.docker.io")
90+
if err != nil {
91+
// preserve original behaviour if we fail to fetch creds
92+
return true
93+
}
94+
return hubAuth.Username != ""
95+
}

0 commit comments

Comments
 (0)