domain fixes

This commit is contained in:
Jess Frazelle 2016-12-19 19:34:37 -08:00
parent 1d42ff4384
commit 4a8d8107ef
No known key found for this signature in database
GPG key ID: 18F3685C0022BFF3
5 changed files with 47 additions and 5 deletions

25
main.go
View file

@ -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
},
},

15
registry/notary.go Normal file
View file

@ -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
}

View file

@ -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,
},

View file

@ -247,7 +247,7 @@ func createStaticIndex(r *registry.Registry, staticDir string) error {
repos = append(repos, repository{
Name: repo,
Tags: strings.Join(tags, "<br/>"),
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 {

View file

@ -13,7 +13,7 @@
<link rel="stylesheet" href="/css/styles.css" />
</head>
<body>
<h1>{{ .RegistryURL }}<</h1>
<h1>{{ .RegistryURL }}</h1>
<form>
<input name="filter" type="search"><a class="clear">clear</a>
</form>