From a690e91c42ded4fcf3c9b59b8e0adf91ce222ea8 Mon Sep 17 00:00:00 2001 From: Josh Komoroske Date: Mon, 26 Feb 2024 22:11:42 -0500 Subject: [PATCH] feat: remove username input Logging into ghcr.io does not require that the username match the owner of the token. --- docker/exec.go | 9 ++++----- main.go | 8 +------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/docker/exec.go b/docker/exec.go index ec9cfff..36cfb1c 100644 --- a/docker/exec.go +++ b/docker/exec.go @@ -13,11 +13,10 @@ import ( "syscall" ) -// Login executes a docker login to ghcr.io with the given username and -// password. -func Login(username, password string) error { - cmd := exec.Command("/usr/bin/docker", "login", "ghcr.io", "--username", username, "--password-stdin") - cmd.Stdin = strings.NewReader(password + "\n") +// Login executes a docker login to ghcr.io with the given GitHub token. +func Login(token string) error { + cmd := exec.Command("/usr/bin/docker", "login", "ghcr.io", "--username", "-", "--password-stdin") + cmd.Stdin = strings.NewReader(token + "\n") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/main.go b/main.go index 49e8370..f1a8fdf 100644 --- a/main.go +++ b/main.go @@ -28,8 +28,6 @@ func mainCmd() error { flag.StringVar(&image, "image", "", "ghcr.io image to run") var tokenEnv string flag.StringVar(&tokenEnv, "token-env", "", "env var to use for github token") - var username string - flag.StringVar(&username, "username", "", "username for github token") flag.Parse() if image == "" { @@ -53,12 +51,8 @@ func mainCmd() error { token = value } - if username == "" { - username = os.Getenv("GITHUB_ACTOR") - } - fmt.Printf("::group::%s\n", "Docker login") - err := docker.Login(username, token) + err := docker.Login(token) fmt.Println("::endgroup::") if err != nil { return err