Skip to content

Commit 574d828

Browse files
committed
Wire up start/end querystrings for tag history
Signed-off-by: Jon Johnson <[email protected]>
1 parent 1ca4f2b commit 574d828

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

internal/explore/explore.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -620,16 +620,11 @@ func (h *handler) tagHistory(w http.ResponseWriter, r *http.Request, ref name.Re
620620
return b, link, nil
621621
}
622622

623-
func (h *handler) renderLinks(w http.ResponseWriter, r *http.Request, links, u string) error {
623+
func (h *handler) renderLinks(w http.ResponseWriter, r *http.Request, links string, u url.URL) error {
624624
if links == "" {
625625
return nil
626626
}
627627

628-
uri, err := url.Parse(u)
629-
if err != nil {
630-
return err
631-
}
632-
633628
fmt.Fprintf(w, "<p>Link: ")
634629
for i, link := range strings.Split(links, ",") {
635630
clean := strings.TrimSpace(link)
@@ -646,7 +641,7 @@ func (h *handler) renderLinks(w http.ResponseWriter, r *http.Request, links, u s
646641

647642
log.Printf("clean: %q", clean)
648643

649-
relative, err := uri.Parse(clean)
644+
relative, err := u.Parse(clean)
650645
if err != nil {
651646
return err
652647
}
@@ -688,19 +683,36 @@ func (h *handler) renderHistory(w http.ResponseWriter, r *http.Request, image st
688683
return fmt.Errorf("not a cgr.dev image: %s", image)
689684
}
690685

691-
// Make sure we are descending until I've been dead for a while.
692-
u := fmt.Sprintf("https://%s/v2/%s/_chainguard/history/%s?end=3000-01-01T00:00:00.000Z", ref.Context().Registry, ref.Context().RepositoryStr(), ref.Identifier())
686+
raw := url.Values{
687+
"end": []string{"3000-01-01T00:00:00.000Z"}, // Make sure we are descending until I've been dead for a while.
688+
}
689+
690+
u := url.URL{
691+
Scheme: "https",
692+
Host: ref.Context().Registry.String(),
693+
Path: fmt.Sprintf("/v2/%s/_chainguard/history/%s", ref.Context().RepositoryStr(), ref.Identifier()),
694+
}
695+
696+
if start := r.URL.Query().Get("start"); start != "" {
697+
raw.Set("start", start)
698+
}
699+
700+
if end := r.URL.Query().Get("end"); end != "" {
701+
raw.Set("end", end)
702+
}
703+
704+
u.RawQuery = raw.Encode()
693705

694706
// TODO: Do we need to cache this?
695-
th, link, err := h.tagHistory(w, r, ref, u)
707+
th, link, err := h.tagHistory(w, r, ref, u.String())
696708
if err != nil {
697709
return err
698710
}
699711

700712
header := HeaderData{
701713
Repo: ref.Context().String(),
702714
Reference: ref.String(),
703-
JQ: `curl -H "$(crane auth token -H ` + ref.Context().String() + `)" ` + u,
715+
JQ: `curl -H "$(crane auth token -H ` + ref.Context().String() + `)" ` + u.String(),
704716
}
705717

706718
if err := headerTmpl.Execute(w, TitleData{image}); err != nil {

0 commit comments

Comments
 (0)