mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-28 11:46:20 -04:00
cleanup
Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
parent
0a5af85b8e
commit
e33d3e5526
4 changed files with 23 additions and 26 deletions
30
main.go
30
main.go
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue