Skip to content
This repository was archived by the owner on Jun 7, 2025. It is now read-only.

Commit 68c0cb0

Browse files
committed
patching auth system
1 parent e357c41 commit 68c0cb0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/docker.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bufio"
55
"context"
6+
"encoding/base64"
67
"encoding/json"
78
"errors"
89
"log"
@@ -85,7 +86,7 @@ func (docker *DockerClient) UpdateContainer(containerId string) (err error) {
8586
docker.panic(name, "Error while fetching container", err)
8687
}
8788
//Pulling Image
88-
authToken := getContainerCredsToken(&containerInfos)
89+
authToken := docker.getContainerCredsToken(&containerInfos)
8990
reader, err := docker.cli.ImagePull(ctx, containerInfos.Config.Image, types.ImagePullOptions{All: false, RegistryAuth: authToken})
9091
if err != nil {
9192
docker.panic(name, "Error while pulling image:", err)
@@ -170,13 +171,16 @@ func (docker *DockerClient) print(name string, args ...interface{}) {
170171
}
171172

172173
//Read auth config from container labels and return a base64 encoded string for docker.
173-
func getContainerCredsToken(container *types.ContainerJSON) string {
174+
func (docker *DockerClient) getContainerCredsToken(container *types.ContainerJSON) string {
174175
serveraddress := container.Config.Labels["docker-ci.auth-server"]
175176
password := container.Config.Labels["docker-ci.password"]
176177
username := container.Config.Labels["docker-ci.username"]
177-
var auth []byte
178178
if serveraddress != "" && username != "" && password != "" {
179-
auth, _ = json.Marshal(DockerAuth{Username: username, Password: password, Serveraddress: serveraddress})
179+
data, err := json.Marshal(DockerAuth{Username: username, Password: password, Serveraddress: serveraddress})
180+
if err != nil {
181+
docker.panic(container.Name[1:], "Error while marshalling auth config:", err)
182+
}
183+
auth := base64.StdEncoding.EncodeToString(data)
180184
return string(auth)
181185
} else {
182186
return ""

0 commit comments

Comments
 (0)