parent
86d87253c5
commit
b0834925a3
@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -35,25 +36,30 @@ func GetRegistryTags(image string) (RawTags, error) {
|
|||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func basicAuth(username, password string) string {
|
||||||
|
auth := username + ":" + password
|
||||||
|
return base64.StdEncoding.EncodeToString([]byte(auth))
|
||||||
|
}
|
||||||
|
|
||||||
// getRegv2Token retrieves a registry v2 authentication token.
|
// getRegv2Token retrieves a registry v2 authentication token.
|
||||||
func getRegv2Token(cl *client.Client, image reference.Named) (string, error) {
|
func getRegv2Token(cl *client.Client, image reference.Named) (string, error) {
|
||||||
img := reference.Path(image)
|
img := reference.Path(image)
|
||||||
tokenURL := "https://auth.docker.io/token"
|
tokenURL := "https://auth.docker.io/token"
|
||||||
values := fmt.Sprintf("service=registry.docker.io&scope=repository:%s:pull", img)
|
values := fmt.Sprintf("service=registry.docker.io&scope=repository:%s:pull", img)
|
||||||
|
|
||||||
username, userOk := os.LookupEnv("DOCKER_USERNAME")
|
|
||||||
password, passOk := os.LookupEnv("DOCKER_PASSWORD")
|
|
||||||
if userOk && passOk {
|
|
||||||
logrus.Debugf("using docker log in credentials for registry token request")
|
|
||||||
values = fmt.Sprintf("%s&grant_type=password&client_id=coopcloud.tech&username=%s&password=%s", values, username, password)
|
|
||||||
}
|
|
||||||
|
|
||||||
fullURL := fmt.Sprintf("%s?%s", tokenURL, values)
|
fullURL := fmt.Sprintf("%s?%s", tokenURL, values)
|
||||||
req, err := retryablehttp.NewRequest("GET", fullURL, nil)
|
req, err := retryablehttp.NewRequest("GET", fullURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
username, userOk := os.LookupEnv("DOCKER_USERNAME")
|
||||||
|
password, passOk := os.LookupEnv("DOCKER_PASSWORD")
|
||||||
|
if userOk && passOk {
|
||||||
|
logrus.Debugf("using docker log in credentials for registry token request")
|
||||||
|
req.Header.Add("Authorization", fmt.Sprintf("Basic %s", basicAuth(username, password)))
|
||||||
|
}
|
||||||
|
|
||||||
client := web.NewHTTPRetryClient()
|
client := web.NewHTTPRetryClient()
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user