mirror of
https://github.com/genuinetools/reg.git
synced 2024-06-28 02:14:16 -04:00
cleanup
Signed-off-by: Jess Frazelle <acidburn@google.com>
This commit is contained in:
parent
0a5af85b8e
commit
e33d3e5526
30
main.go
30
main.go
|
@ -4,11 +4,13 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/distribution/digest"
|
||||||
"github.com/docker/docker/cliconfig"
|
"github.com/docker/docker/cliconfig"
|
||||||
"github.com/docker/engine-api/types"
|
"github.com/docker/engine-api/types"
|
||||||
"github.com/jessfraz/reg/registry"
|
"github.com/jessfraz/reg/registry"
|
||||||
|
@ -149,7 +151,6 @@ func main() {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the tags
|
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -175,26 +176,37 @@ func main() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "timestamp",
|
Name: "download",
|
||||||
Usage: "get the notary timestamp for the specific reference of a repository",
|
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 {
|
Action: func(c *cli.Context) error {
|
||||||
repo, ref, err := getRepoAndRef(c)
|
repo, ref, err := getRepoAndRef(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := json.MarshalIndent(timestamp, " ", " ")
|
if c.String("output") != "" {
|
||||||
if err != nil {
|
return ioutil.WriteFile(c.String("output"), b, 0644)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print the tags
|
fmt.Fprint(os.Stdout, string(b))
|
||||||
fmt.Println(string(b))
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/distribution/manifest/schema1"
|
"github.com/docker/distribution/manifest/schema1"
|
||||||
|
@ -21,7 +20,7 @@ func (r *Registry) Manifest(repository, ref string) (interface{}, error) {
|
||||||
|
|
||||||
if !strings.Contains(ref, ":") {
|
if !strings.Contains(ref, ":") {
|
||||||
// we got a tag, get the manifest for the 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 {
|
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 {
|
for _, s := range a.Scope {
|
||||||
q.Set("scope", s)
|
q.Set("scope", s)
|
||||||
}
|
}
|
||||||
|
// q.Set("scope", "repository:r.j3ss.co/htop:push,pull")
|
||||||
a.Realm.RawQuery = q.Encode()
|
a.Realm.RawQuery = q.Encode()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", a.Realm.String(), nil)
|
req, err := http.NewRequest("GET", a.Realm.String(), nil)
|
||||||
|
|
Loading…
Reference in a new issue