address review comments

This commit is contained in:
Aishwarya Lad
2024-06-25 15:04:24 -07:00
parent ced9875ed0
commit 9a4e1ba483
3 changed files with 13 additions and 15 deletions
+3 -3
View File
@@ -225,17 +225,17 @@ func main() {
cli.StringFlag{
Name: "docker.baseimageusername",
Usage: "Docker username for base image registry",
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME",
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME,DOCKER_BASE_IMAGE_USERNAME",
},
cli.StringFlag{
Name: "docker.baseimagepassword",
Usage: "Docker password for base image registry",
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD",
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD,DOCKER_BASE_IMAGE_PASSWORD",
},
cli.StringFlag{
Name: "docker.baseimageregistry",
Usage: "Docker registry for base image registry",
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY",
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY,DOCKER_BASE_IMAGE_REGISTRY",
},
cli.StringFlag{
Name: "docker.email",
+5 -5
View File
@@ -1,6 +1,7 @@
package docker
import (
"errors"
"fmt"
"os"
"os/exec"
@@ -11,7 +12,6 @@ import (
"github.com/drone-plugins/drone-docker/internal/docker"
"github.com/drone-plugins/drone-plugin-lib/drone"
"github.com/pkg/errors"
)
type (
@@ -163,7 +163,7 @@ func (p Plugin) Exec() error {
return fmt.Errorf("Error writing config.json: %s", err)
}
_, err = file.Write([]byte(p.Login.Config))
fmt.Println("Writing p.Login.Config: %s", p.Login.Config)
fmt.Println("Writing p.Login.Config")
if err != nil {
return fmt.Errorf("Error writing config.json: %s", err)
@@ -175,7 +175,7 @@ func (p Plugin) Exec() error {
json, err := setDockerAuth(p.Login.Username, p.Login.Password, p.Login.Registry,
p.BaseImageUsername, p.BaseImagePassword, p.BaseImageRegistry)
if err != nil {
return errors.Wrap(err, "Failed to set authentication in docker config")
return fmt.Errorf("Failed to set authentication in docker config %s", err)
}
if json != nil {
path := filepath.Join(dockerHome, "config.json")
@@ -306,15 +306,15 @@ func setDockerAuth(username, password, registry, baseImageUsername,
baseImagePassword, baseImageRegistry string) ([]byte, error) {
var credentials []docker.RegistryCredentials
// add only docker registry to the config
dockerConfig := docker.NewConfig()
if password != "" && strings.Contains(registry, "docker") {
dockerConfig := docker.NewConfig()
pushToRegistryCreds := docker.RegistryCredentials{
Registry: registry,
Username: username,
Password: password,
}
// push registry auth
credentials := append(credentials, pushToRegistryCreds)
credentials = append(credentials, pushToRegistryCreds)
}
if baseImageRegistry != "" {
+5 -7
View File
@@ -3,11 +3,11 @@ package docker
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/pkg/errors"
"strings"
)
const (
@@ -43,7 +43,6 @@ func NewConfig() *Config {
func (c *Config) SetAuth(registry, username, password string) {
authBytes := []byte(username + ":" + password)
encodedString := base64.StdEncoding.EncodeToString(authBytes)
log.Printf("auth : %s", encodedString)
c.Auths[registry] = Auth{Auth: encodedString}
}
@@ -67,7 +66,7 @@ func (c *Config) CreateDockerConfigJson(credentials []RegistryCredentials) ([]by
jsonBytes, err := json.Marshal(c)
if err != nil {
return nil, errors.Wrap(err, "failed to serialize docker config json")
return nil, errors.New("failed to serialize docker config json")
}
return jsonBytes, nil
@@ -77,15 +76,14 @@ func WriteDockerConfig(data []byte, path string) (string error) {
err := os.MkdirAll(path, 0600)
if err != nil {
if !os.IsExist(err) {
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory", path))
return errors.New("failed to create %s directory")
}
}
filePath := path + "/config.json"
log.Printf("Config data is %s", data)
err = ioutil.WriteFile(filePath, data, 0644)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to create docker config file at %s", path))
return errors.New("failed to create docker config file at %s")
}
return nil
}