Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
Jess Frazelle 2016-12-19 21:13:34 -08:00
parent 0a5af85b8e
commit e33d3e5526
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
4 changed files with 23 additions and 26 deletions

30
main.go
View file

@ -4,11 +4,13 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"text/tabwriter"
"github.com/Sirupsen/logrus"
"github.com/docker/distribution/digest"
"github.com/docker/docker/cliconfig"
"github.com/docker/engine-api/types"
"github.com/jessfraz/reg/registry"
@ -149,7 +151,6 @@ func main() {
return err
}
// print the tags
fmt.Println(string(b))
return nil
@ -175,26 +176,37 @@ func main() {
},
},
{
Name: "timestamp",
Usage: "get the notary timestamp for the specific reference of a repository",
Name: "download",
Aliases: []string{"layer"},
Usage: "download a layer for the specific reference of a repository",
Flags: []cli.Flag{
cli.StringFlag{
Name: "output, o",
Usage: "output file, default to stdout",
},
},
Action: func(c *cli.Context) error {
repo, ref, err := getRepoAndRef(c)
if err != nil {
return err
}
timestamp, err := r.NotaryTimestamp(repo, ref)
layer, err := r.DownloadLayer(repo, digest.Digest(ref))
if err != nil {
return err
}
defer layer.Close()
b, err := ioutil.ReadAll(layer)
if err != nil {
return err
}
b, err := json.MarshalIndent(timestamp, " ", " ")
if err != nil {
return err
if c.String("output") != "" {
return ioutil.WriteFile(c.String("output"), b, 0644)
}
// print the tags
fmt.Println(string(b))
fmt.Fprint(os.Stdout, string(b))
return nil
},

View file

@ -1,7 +1,6 @@
package registry
import (
"log"
"strings"
"github.com/docker/distribution/manifest/schema1"
@ -21,7 +20,7 @@ func (r *Registry) Manifest(repository, ref string) (interface{}, error) {
if !strings.Contains(ref, ":") {
// we got a tag, get the manifest for the ref
log.Printf("ref: %s", h.Get("Docker-Content-Digest"))
r.Logf("ref: %s", h.Get("Docker-Content-Digest"))
}
if m.Versioned.SchemaVersion == 1 {

View file

@ -1,15 +0,0 @@
package registry
// NotaryTimestamp returns a notary timestamp for a specific repository:tag.
func (r *Registry) NotaryTimestamp(repository, ref string) (interface{}, error) {
url := r.url("/v2/%s/%s/_trust/tuf/timestamp.json", r.Domain, repository)
r.Logf("registry.manifests url=%s repository=%s ref=%s", url, repository, ref)
var ts interface{}
_, err := r.getJSON(url, &ts)
if err != nil {
return ts, err
}
return ts, nil
}

View file

@ -91,6 +91,7 @@ func (a *authService) Request(username, password string) (*http.Request, error)
for _, s := range a.Scope {
q.Set("scope", s)
}
// q.Set("scope", "repository:r.j3ss.co/htop:push,pull")
a.Realm.RawQuery = q.Encode()
req, err := http.NewRequest("GET", a.Realm.String(), nil)