/
url.go
76 lines (68 loc) · 2.18 KB
/
url.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package registry
import (
contextpkg "context"
"fmt"
"io"
namepkg "github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
gzip "github.com/klauspost/pgzip"
"github.com/tliron/exturl"
resources "github.com/tliron/reposure/resources/reposure.puccini.cloud/v1alpha1"
)
func (self *Client) UpdateURLContext(registry *resources.Registry, urlContext *exturl.Context) error {
if host, roundTripper, err := self.GetHTTPRoundTripper(registry); err == nil {
if roundTripper != nil {
urlContext.SetHTTPRoundTripper(host, roundTripper)
}
} else {
return err
}
if host, username, password, token, err := self.GetAuthorization(registry); err == nil {
if (username != "") || (token != "") {
urlContext.SetCredentials(host, username, password, token)
}
} else {
return err
}
return nil
}
// TODO: what uses this?
func (self *Client) PushTarball(context contextpkg.Context, artifactName string, sourceUrl exturl.URL, registry *resources.Registry) (string, error) {
if registryHost, err := self.GetHost(registry); err == nil {
if options, err := self.GetRemoteOptions(registry); err == nil {
self.Log.Infof("publishing image %q at %q on %q", artifactName, sourceUrl.String(), registryHost)
opener := func() (io.ReadCloser, error) {
if reader, err := sourceUrl.Open(context); err == nil {
return gzip.NewReader(reader)
} else {
return nil, err
}
}
if contentTag, err := namepkg.NewTag("portable"); err == nil {
tag := fmt.Sprintf("%s/%s", registryHost, artifactName)
if tag_, err := namepkg.NewTag(tag); err == nil {
if image, err := tarball.Image(opener, &contentTag); err == nil {
options = append(options, remote.WithContext(context))
if err := remote.Write(tag_, image, options...); err == nil {
self.Log.Infof("published image %q at %q on %q", tag, sourceUrl.String(), registryHost)
return tag, nil
} else {
return "", err
}
} else {
return "", err
}
} else {
return "", err
}
} else {
return "", err
}
} else {
return "", err
}
} else {
return "", err
}
}