Add push object

Split resolver to only return a name with separate methods
for getting a fetcher and pusher. Add implementation for
push.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-05-16 13:08:06 -07:00
parent 8f3b89c79d
commit 735b0e515e
12 changed files with 590 additions and 209 deletions

View File

@@ -79,20 +79,20 @@ func Parse(s string) (Spec, error) {
return Spec{}, ErrHostnameRequired
}
parts := splitRe.Split(u.Path, 2)
if len(parts) < 2 {
return Spec{}, ErrObjectRequired
}
var object string
// This allows us to retain the @ to signify digests or shortend digests in
// the object.
object := u.Path[len(parts[0]):]
if object[:1] == ":" {
object = object[1:]
if idx := splitRe.FindStringIndex(u.Path); idx != nil {
// This allows us to retain the @ to signify digests or shortend digests in
// the object.
object = u.Path[idx[0]:]
if object[:1] == ":" {
object = object[1:]
}
u.Path = u.Path[:idx[0]]
}
return Spec{
Locator: path.Join(u.Host, parts[0]),
Locator: path.Join(u.Host, u.Path),
Object: object,
}, nil
}
@@ -119,6 +119,9 @@ func (r Spec) Digest() digest.Digest {
// String returns the normalized string for the ref.
func (r Spec) String() string {
if r.Object == "" {
return r.Locator
}
if r.Object[:1] == "@" {
return fmt.Sprintf("%v%v", r.Locator, r.Object)
}

View File

@@ -78,9 +78,14 @@ func TestReferenceParser(t *testing.T) {
Err: ErrHostnameRequired,
},
{
Name: "ErrObjectRequired",
Input: "docker.io/library/redis?fooo=asdf",
Err: ErrObjectRequired,
Name: "ErrObjectRequired",
Input: "docker.io/library/redis?fooo=asdf",
Hostname: "docker.io",
Normalized: "docker.io/library/redis",
Expected: Spec{
Locator: "docker.io/library/redis",
Object: "",
},
},
{
Name: "Subdomain",