Skip to content

Commit 65271b0

Browse files
fix #11 - problem with special characters in dockerhub passwd
1 parent 4e6c0a8 commit 65271b0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

provider/dockerhub/dockerhub.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"net/http"
3030
"strings"
3131

32+
"github.com/christian-korneck/docker-pushrm/util"
3233
log "github.com/sirupsen/logrus"
3334
)
3435

@@ -67,7 +68,14 @@ func GetJwt(dockerUser string, dockerPasswd string) (jwt string, error error) {
6768
url := "https://hub.docker.com/v2/users/login/"
6869
method := "POST"
6970

70-
payload := strings.NewReader("{\n \"username\": \"" + dockerUser + "\",\n \"password\": \"" + dockerPasswd + "\"\n}")
71+
payloadJSON, err := json.Marshal(map[string]string{"username": dockerUser, "password": dockerPasswd})
72+
if err != nil {
73+
log.Debug(err)
74+
return "", fmt.Errorf("error retrieving Dockerhub jwt token, error marshal payload")
75+
}
76+
77+
payloadStr := util.BytesToString(payloadJSON)
78+
payload := strings.NewReader(payloadStr)
7179

7280
client := &http.Client{}
7381
req, err := http.NewRequest(method, url, payload)

util/util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ import (
3838
"github.com/spf13/viper"
3939
)
4040

41+
// BytesToString converts
42+
func BytesToString(b []byte) string {
43+
return string(b[:])
44+
}
45+
4146
// StringInSlice checks if a string exists in a slice
4247
func StringInSlice(checkval string, list []string) bool {
4348
for _, b := range list {

0 commit comments

Comments
 (0)