From 4a8d8107ef775251538c036c7536286b145a636f Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 19 Dec 2016 19:34:37 -0800 Subject: [PATCH] domain fixes --- main.go | 25 +++++++++++++++++++++++++ registry/notary.go | 15 +++++++++++++++ registry/registry.go | 4 +++- server/server.go | 6 +++--- server/templates/layout.html | 2 +- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 registry/notary.go diff --git a/main.go b/main.go index 3452c263..c9d2427c 100644 --- a/main.go +++ b/main.go @@ -171,6 +171,31 @@ func main() { // print the tags fmt.Println(strings.Join(tags, "\n")) + return nil + }, + }, + { + Name: "timestamp", + Usage: "get the notary timestamp for the specific reference of a repository", + Action: func(c *cli.Context) error { + repo, ref, err := getRepoAndRef(c) + if err != nil { + return err + } + + timestamp, err := r.NotaryTimestamp(repo, ref) + if err != nil { + return err + } + + b, err := json.MarshalIndent(timestamp, " ", " ") + if err != nil { + return err + } + + // print the tags + fmt.Println(string(b)) + return nil }, }, diff --git a/registry/notary.go b/registry/notary.go new file mode 100644 index 00000000..b21c25db --- /dev/null +++ b/registry/notary.go @@ -0,0 +1,15 @@ +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 +} diff --git a/registry/registry.go b/registry/registry.go index 1c744303..659a3cd4 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -14,6 +14,7 @@ import ( // Registry defines the client for retriving information from the registry API. type Registry struct { URL string + Domain string Client *http.Client Logf LogfCallback } @@ -72,7 +73,8 @@ func newFromTransport(auth types.AuthConfig, transport http.RoundTripper, debug } registry := &Registry{ - URL: url, + URL: url, + Domain: strings.TrimPrefix(url, "https://"), Client: &http.Client{ Transport: errorTransport, }, diff --git a/server/server.go b/server/server.go index 213151af..c3109ccc 100644 --- a/server/server.go +++ b/server/server.go @@ -247,7 +247,7 @@ func createStaticIndex(r *registry.Registry, staticDir string) error { repos = append(repos, repository{ Name: repo, Tags: strings.Join(tags, "
"), - RegistryURL: r.URL, + RegistryURL: r.Domain, }) } @@ -266,9 +266,9 @@ func createStaticIndex(r *registry.Registry, staticDir string) error { lp := filepath.Join(templateDir, "layout.html") d := data{ - RegistryURL: r.URL, + RegistryURL: r.Domain, Repos: repos, - LastUpdated: time.Now().String(), + LastUpdated: time.Now().Format(time.RFC1123), } tmpl := template.Must(template.New("").ParseFiles(lp)) if err := tmpl.ExecuteTemplate(f, "layout", d); err != nil { diff --git a/server/templates/layout.html b/server/templates/layout.html index 1d75667b..873538c3 100644 --- a/server/templates/layout.html +++ b/server/templates/layout.html @@ -13,7 +13,7 @@ -

{{ .RegistryURL }}<

+

{{ .RegistryURL }}

clear