refactor: remove all calls to common.NewShellCmd
At this point, the only usage of go-sh should be by plugin trigger calls.
This commit is contained in:
@@ -3,6 +3,7 @@ package registry
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -35,25 +36,23 @@ func CommandLogin(server string, username string, password string, passwordStdin
|
||||
server = "docker.io"
|
||||
}
|
||||
|
||||
command := []string{
|
||||
common.DockerBin(),
|
||||
"login",
|
||||
"--username",
|
||||
username,
|
||||
"--password-stdin",
|
||||
server,
|
||||
}
|
||||
|
||||
buffer := bytes.Buffer{}
|
||||
buffer.Write([]byte(password + "\n"))
|
||||
|
||||
loginCmd := common.NewShellCmd(strings.Join(command, " "))
|
||||
loginCmd.Command.Stdin = &buffer
|
||||
if !loginCmd.Execute() {
|
||||
return errors.New("Failed to log into registry")
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: common.DockerBin(),
|
||||
Args: []string{"login", "--username", username, "--password-stdin", server},
|
||||
Stdin: &buffer,
|
||||
StreamStderr: true,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to run docker login: %w", err)
|
||||
}
|
||||
if result.ExitCode != 0 {
|
||||
return fmt.Errorf("Unable to run docker login: %s", result.StderrContents())
|
||||
}
|
||||
|
||||
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
_, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "post-registry-login",
|
||||
Args: []string{server, username},
|
||||
StreamStdio: true,
|
||||
|
||||
Reference in New Issue
Block a user