/
util.go
45 lines (40 loc) · 939 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package docker
import (
"encoding/base64"
"encoding/json"
"strings"
"github.com/docker/docker/api/types"
"github.com/wrfly/reglib"
)
func getAuth(image string) string {
domain := getDomain(image)
user, pass := reglib.GetAuthFromFile(domain)
auth := types.AuthConfig{
Username: user,
Password: pass,
}
authBytes, _ := json.Marshal(auth)
return base64.URLEncoding.EncodeToString(authBytes)
}
func getDomain(image string) string {
domain := strings.Split(image, "/")[0]
if !strings.Contains(domain, ".") {
domain = "docker.io"
}
return domain
}
func getMeta(image string) (domain, repo, tag string) {
domain = getDomain(image)
if domain == "docker.io" {
if !strings.Contains(image, "/") {
image = "library/" + image
}
}
image = strings.TrimPrefix(image, domain+"/")
tag = "latest"
if strings.Contains(image, ":") {
repo = strings.Split(image, ":")[0]
tag = strings.Split(image, ":")[1]
}
return
}