working commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Reference struct {
|
||||
urlobj *url.URL
|
||||
user, pass string
|
||||
repo, tag string
|
||||
}
|
||||
|
||||
func NewReference(rawref string) (*Reference, error) {
|
||||
ref := &Reference{}
|
||||
if !strings.Contains(rawref, "://") {
|
||||
rawref = "https://" + rawref
|
||||
}
|
||||
urlobj, err := url.Parse(rawref)
|
||||
if err != nil {
|
||||
return ref, err
|
||||
}
|
||||
if urlobj.User != nil {
|
||||
ref.user = urlobj.User.Username()
|
||||
ref.pass, _ = urlobj.User.Password()
|
||||
urlobj.User = nil
|
||||
}
|
||||
repotag := strings.SplitN(urlobj.Path, ":", 2)
|
||||
if len(repotag) != 2 {
|
||||
err = errors.New("Incorrect repo")
|
||||
return ref, err
|
||||
}
|
||||
ref.urlobj = urlobj
|
||||
ref.urlobj.Path = ""
|
||||
ref.repo = repotag[0]
|
||||
ref.tag = repotag[1]
|
||||
ref.urlobj = urlobj
|
||||
|
||||
return ref, err
|
||||
}
|
||||
|
||||
func (ref *Reference) Manifest() string {
|
||||
curl := ref.urlobj.JoinPath("/v2", ref.repo, "/manifests", ref.tag)
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
func (ref *Reference) Blob(digest string) string {
|
||||
curl := ref.urlobj.JoinPath("/v2", ref.repo, "/blobs", digest)
|
||||
return curl.String()
|
||||
}
|
||||
|
||||
func (ref *Reference) Userinfo() (string, string) {
|
||||
return ref.user, ref.pass
|
||||
}
|
||||
Reference in New Issue
Block a user