Skip to content

Commit 5fa4abd

Browse files
committed
changes as per review
1 parent fa1181e commit 5fa4abd

File tree

7 files changed

+28
-27
lines changed

7 files changed

+28
-27
lines changed

pkg/filler/filler.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package filler
1717
import (
1818
"context"
1919
"errors"
20-
"html/template"
2120
"log/slog"
2221
"sort"
2322
"strings"
@@ -61,18 +60,13 @@ func (f *Filler) TagData(ctx context.Context, repo string, tag string) (*templat
6160
architecturesStr = cfg.Architecture
6261
}
6362

64-
scanUrlStr := ""
65-
if imageInfo.ScanUrls != nil {
66-
scanUrlStr = strings.Join(imageInfo.ScanUrls, "")
67-
}
68-
6963
return &templates.TagData{
7064
Name: repo,
7165
Tag: tag,
7266
PullReference: imageInfo.Reference,
7367
CreatedAt: cfg.Created.Format(time.RFC3339),
7468
Architectures: architecturesStr,
75-
ScanUrls: template.HTML(scanUrlStr),
69+
ScanUrl: imageInfo.ScanUrl,
7670
InspectUrl: imageInfo.InspectUrl,
7771
}, nil
7872
}

pkg/registry/client.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package registry
1717
import (
1818
"context"
1919
v1 "github.com/google/go-containerregistry/pkg/v1"
20+
"html/template"
2021
"time"
2122
)
2223

@@ -30,8 +31,8 @@ type ImageInfo struct {
3031
Image v1.Image
3132
Reference string
3233
Architectures []string
33-
ScanUrls []string
34-
InspectUrl string
34+
ScanUrl template.HTML
35+
InspectUrl template.HTML
3536
}
3637

3738
// Client interface defines methods for interacting with a container registry
Loading
+4
Loading

pkg/registry/registry/registry.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ package registry
1616

1717
import (
1818
"context"
19+
"embed"
1920
"fmt"
2021
"github.com/google/go-containerregistry/pkg/name"
2122
"github.com/google/go-containerregistry/pkg/v1/remote"
2223
"github.com/seqeralabs/staticreg/pkg/cfg"
2324
"github.com/seqeralabs/staticreg/pkg/registry"
25+
"html/template"
2426
"strings"
2527
)
2628

29+
//go:embed img/*
30+
var icons embed.FS
31+
2732
const defaultUserAgent = "seqera/staticreg"
2833

2934
var (
@@ -108,27 +113,25 @@ func (c *Registry) ImageInfo(ctx context.Context, image string, tag string) (reg
108113
scanUrls = append(scanUrls, c.getScanUrl(ref.String(), "", cf.Architecture))
109114
}
110115
}
111-
inspectUrl := fmt.Sprintf("%s/view/inspect?image=%s", waveServerUrl, ref)
116+
inspectIcon, _ := icons.ReadFile("img/inspect-icon.svg")
117+
inspectUrl := template.HTML(fmt.Sprintf("<a href=%s/view/inspect?image=%s>%s</a>", waveServerUrl, ref, inspectIcon))
118+
119+
scanUrl := template.HTML(strings.Join(scanUrls, ""))
112120

113-
return registry.ImageInfo{Image: i, Reference: ref.String(), Architectures: architectures, ScanUrls: scanUrls, InspectUrl: inspectUrl}, nil
121+
return registry.ImageInfo{Image: i, Reference: ref.String(), Architectures: architectures, ScanUrl: scanUrl, InspectUrl: inspectUrl}, nil
114122
}
115123

116124
func (c *Registry) getScanUrl(ref string, digest string, platform string) string {
117125

118126
waveServerUrl := c.cfg.WaveServerUrl
119-
127+
scanIcon, _ := icons.ReadFile("img/scan-icon.svg")
120128
if !strings.Contains(waveServerUrl, "https://") && !strings.Contains(waveServerUrl, "http://") {
121129
waveServerUrl = "https://" + waveServerUrl
122130
}
123131

124-
const scanSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shield-check" viewBox="0 0 16 16">
125-
<path d="M5.338 1.59a61 61 0 0 0-2.837.856.48.48 0 0 0-.328.39c-.554 4.157.726 7.19 2.253 9.188a10.7 10.7 0 0 0 2.287 2.233c.346.244.652.42.893.533q.18.085.293.118a1 1 0 0 0 .101.025 1 1 0 0 0 .1-.025q.114-.034.294-.118c.24-.113.547-.29.893-.533a10.7 10.7 0 0 0 2.287-2.233c1.527-1.997 2.807-5.031 2.253-9.188a.48.48 0 0 0-.328-.39c-.651-.213-1.75-.56-2.837-.855C9.552 1.29 8.531 1.067 8 1.067c-.53 0-1.552.223-2.662.524zM5.072.56C6.157.265 7.31 0 8 0s1.843.265 2.928.56c1.11.3 2.229.655 2.887.87a1.54 1.54 0 0 1 1.044 1.262c.596 4.477-.787 7.795-2.465 9.99a11.8 11.8 0 0 1-2.517 2.453 7 7 0 0 1-1.048.625c-.28.132-.581.24-.829.24s-.548-.108-.829-.24a7 7 0 0 1-1.048-.625 11.8 11.8 0 0 1-2.517-2.453C1.928 10.487.545 7.169 1.141 2.692A1.54 1.54 0 0 1 2.185 1.43 63 63 0 0 1 5.072.56"/>
126-
<path d="M10.854 5.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7.5 7.793l2.646-2.647a.5.5 0 0 1 .708 0"/>
127-
</svg>`
128-
129-
url := fmt.Sprintf("<a href=%s/view/scans?image=%s title=%s>%s</a>", waveServerUrl, ref, platform, scanSvg)
132+
url := fmt.Sprintf("<a href=%s/view/scans?image=%s title=%s>%s</a>", waveServerUrl, ref, platform, scanIcon)
130133
if digest != "" {
131-
url = fmt.Sprintf("<a href=%s/view/scans?image=%s@%s title=%s>%s</a>", waveServerUrl, ref, digest, platform, scanSvg)
134+
url = fmt.Sprintf("<a href=%s/view/scans?image=%s@%s title=%s>%s</a>", waveServerUrl, ref, digest, platform, scanIcon)
132135
}
133136
return url
134137
}

pkg/templates/templates.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ type TagData struct {
6666
PullReference string
6767
CreatedAt string
6868
Architectures string
69-
ScanUrls template.HTML
70-
InspectUrl string
69+
ScanUrl template.HTML
70+
InspectUrl template.HTML
7171
}
7272

7373
type RepositoryData struct {

pkg/templates/tmpl/repository.html

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ <h1 class="lg:text-3xl xs:text-sm font-bold tracking-tight text-gray-900"><a
4444
pull {{.PullReference}}
4545
</span>
4646
</td>
47-
<td class="p-2 font-mono text-left"><div class="inline-flex items-center space-x-2">{{.ScanUrls}}</div></td>
48-
<td class="p-2 font-mono text-left"><a href={{.InspectUrl}}>
49-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-search" viewBox="0 0 16 16">
50-
<path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0"/>
51-
</svg>
52-
</a></td>
47+
<td class="p-2 font-mono text-left"><div class="inline-flex items-center space-x-2">{{.ScanUrl}}</div></td>
48+
<td class="p-2 font-mono text-left">{{.InspectUrl}}</td>
5349
</tr>
5450
{{end}}
5551
</tbody>

0 commit comments

Comments
 (0)