mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-28 11:46:20 -04:00
do not show vulns on tags page if there is no clair registry
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
f9d8dca27d
commit
3e014d1732
3 changed files with 38 additions and 23 deletions
29
handlers.go
29
handlers.go
|
@ -47,6 +47,7 @@ type AnalysisResult struct {
|
||||||
RegistryDomain string `json:"registryDomain"`
|
RegistryDomain string `json:"registryDomain"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
LastUpdated string `json:"lastUpdated"`
|
LastUpdated string `json:"lastUpdated"`
|
||||||
|
HasVulns bool `json:"hasVulns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *registryController) repositories(staticDir string, generateTagsFiles bool) error {
|
func (rc *registryController) repositories(staticDir string, generateTagsFiles bool) error {
|
||||||
|
@ -65,6 +66,7 @@ func (rc *registryController) repositories(staticDir string, generateTagsFiles b
|
||||||
return fmt.Errorf("getting catalog for %s failed: %v", rc.reg.Domain, err)
|
return fmt.Errorf("getting catalog for %s failed: %v", rc.reg.Domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
for _, repo := range repoList {
|
for _, repo := range repoList {
|
||||||
repoURI := fmt.Sprintf("%s/%s", rc.reg.Domain, repo)
|
repoURI := fmt.Sprintf("%s/%s", rc.reg.Domain, repo)
|
||||||
r := Repository{
|
r := Repository{
|
||||||
|
@ -74,28 +76,36 @@ func (rc *registryController) repositories(staticDir string, generateTagsFiles b
|
||||||
|
|
||||||
result.Repositories = append(result.Repositories, r)
|
result.Repositories = append(result.Repositories, r)
|
||||||
|
|
||||||
if generateTagsFiles {
|
if !generateTagsFiles {
|
||||||
// TODO(jessfraz): make this a go routine with a wait group.
|
// Continue early because we don't need to generate the tags pages.
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate the tags pages in a go routine.
|
||||||
|
wg.Add(1)
|
||||||
|
go func(repo string) {
|
||||||
|
defer wg.Done()
|
||||||
logrus.Infof("generating static tags page for repo %s", repo)
|
logrus.Infof("generating static tags page for repo %s", repo)
|
||||||
|
|
||||||
// Parse and execute the tags templates.
|
// Parse and execute the tags templates.
|
||||||
b, err := rc.generateTagsTemplate(repo)
|
b, err := rc.generateTagsTemplate(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Warnf("generating tags tamplate for repo %q failed: %v", repo, err)
|
logrus.Warnf("generating tags template for repo %q failed: %v", repo, err)
|
||||||
}
|
}
|
||||||
// Create the directory for the static tags files.
|
// Create the directory for the static tags files.
|
||||||
tagsDir := filepath.Join(staticDir, "repo", repo, "tags")
|
tagsDir := filepath.Join(staticDir, "repo", repo, "tags")
|
||||||
if err := os.MkdirAll(tagsDir, 0755); err != nil {
|
if err := os.MkdirAll(tagsDir, 0755); err != nil {
|
||||||
return err
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the tags file.
|
// Write the tags file.
|
||||||
tagsFile := filepath.Join(tagsDir, "index.html")
|
tagsFile := filepath.Join(tagsDir, "index.html")
|
||||||
if err := ioutil.WriteFile(tagsFile, b, 0755); err != nil {
|
if err := ioutil.WriteFile(tagsFile, b, 0755); err != nil {
|
||||||
logrus.Warnf("writing tags tamplate for repo %s to %sfailed: %v", repo, tagsFile, err)
|
logrus.Warnf("writing tags template for repo %s to %sfailed: %v", repo, tagsFile, err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}(repo)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
// Parse & execute the template.
|
// Parse & execute the template.
|
||||||
logrus.Info("executing the template repositories")
|
logrus.Info("executing the template repositories")
|
||||||
|
@ -174,6 +184,7 @@ func (rc *registryController) generateTagsTemplate(repo string) ([]byte, error)
|
||||||
RegistryDomain: rc.reg.Domain,
|
RegistryDomain: rc.reg.Domain,
|
||||||
LastUpdated: time.Now().Local().Format(time.RFC1123),
|
LastUpdated: time.Now().Local().Format(time.RFC1123),
|
||||||
Name: repo,
|
Name: repo,
|
||||||
|
HasVulns: rc.cl != nil, // if we have a clair client we can return vulns
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
|
@ -242,10 +253,7 @@ func (rc *registryController) vulnerabilitiesHandler(w http.ResponseWriter, r *h
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result := clair.VulnerabilityReport{}
|
result, err := rc.cl.Vulnerabilities(rc.reg, repo, tag)
|
||||||
|
|
||||||
if rc.cl != nil {
|
|
||||||
result, err = rc.cl.Vulnerabilities(rc.reg, repo, tag)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"func": "vulnerabilities",
|
"func": "vulnerabilities",
|
||||||
|
@ -255,7 +263,6 @@ func (rc *registryController) vulnerabilitiesHandler(w http.ResponseWriter, r *h
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasSuffix(r.URL.String(), ".json") {
|
if strings.HasSuffix(r.URL.String(), ".json") {
|
||||||
js, err := json.Marshal(result)
|
js, err := json.Marshal(result)
|
||||||
|
|
|
@ -156,9 +156,13 @@ func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
|
||||||
mux.HandleFunc("/repo/{repo}/tags/", rc.tagsHandler)
|
mux.HandleFunc("/repo/{repo}/tags/", rc.tagsHandler)
|
||||||
mux.HandleFunc("/repo/{repo}/tag/{tag}", rc.vulnerabilitiesHandler)
|
mux.HandleFunc("/repo/{repo}/tag/{tag}", rc.vulnerabilitiesHandler)
|
||||||
mux.HandleFunc("/repo/{repo}/tag/{tag}/", rc.vulnerabilitiesHandler)
|
mux.HandleFunc("/repo/{repo}/tag/{tag}/", rc.vulnerabilitiesHandler)
|
||||||
|
|
||||||
|
// Add the vulns endpoints if we have a client for a clair server.
|
||||||
|
if rc.cl != nil {
|
||||||
mux.HandleFunc("/repo/{repo}/tag/{tag}/vulns", rc.vulnerabilitiesHandler)
|
mux.HandleFunc("/repo/{repo}/tag/{tag}/vulns", rc.vulnerabilitiesHandler)
|
||||||
mux.HandleFunc("/repo/{repo}/tag/{tag}/vulns/", rc.vulnerabilitiesHandler)
|
mux.HandleFunc("/repo/{repo}/tag/{tag}/vulns/", rc.vulnerabilitiesHandler)
|
||||||
mux.HandleFunc("/repo/{repo}/tag/{tag}/vulns.json", rc.vulnerabilitiesHandler)
|
mux.HandleFunc("/repo/{repo}/tag/{tag}/vulns.json", rc.vulnerabilitiesHandler)
|
||||||
|
}
|
||||||
|
|
||||||
// Serve the static assets.
|
// Serve the static assets.
|
||||||
staticHandler := http.FileServer(http.Dir(staticDir))
|
staticHandler := http.FileServer(http.Dir(staticDir))
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Tag</th>
|
<th>Tag</th>
|
||||||
<th>Created</th>
|
<th>Created</th>
|
||||||
<th>Vulnerabilities</th>
|
{{if .HasVulns}}<th>Vulnerabilities</th>{{end}}
|
||||||
</tr>
|
</tr>
|
||||||
{{ range $key, $value := .Repositories }}
|
{{ range $key, $value := .Repositories }}
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -37,11 +37,13 @@
|
||||||
<td align="right" nowrap>
|
<td align="right" nowrap>
|
||||||
{{ $value.Created.Format "02 Jan, 2006 15:04:05 UTC" }}
|
{{ $value.Created.Format "02 Jan, 2006 15:04:05 UTC" }}
|
||||||
</td>
|
</td>
|
||||||
|
{{if .HasVulns}}
|
||||||
<td align="right" nowrap>
|
<td align="right" nowrap>
|
||||||
<a href="/repo/{{ $value.Name | urlquery }}/tag/{{ $value.Tag }}/vulns" id="{{ $value.Name }}:{{ $value.Tag }}">
|
<a href="/repo/{{ $value.Name | urlquery }}/tag/{{ $value.Tag }}/vulns" id="{{ $value.Name }}:{{ $value.Tag }}">
|
||||||
<div class="signal"></div>
|
<div class="signal"></div>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
{{end}}
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</table>
|
</table>
|
||||||
|
@ -52,6 +54,7 @@
|
||||||
<p>Last Updated: {{ .LastUpdated }}</p>
|
<p>Last Updated: {{ .LastUpdated }}</p>
|
||||||
</div><!--/.footer-->
|
</div><!--/.footer-->
|
||||||
<script src="/static/js/scripts.js"></script>
|
<script src="/static/js/scripts.js"></script>
|
||||||
|
{{if .HasVulns}}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var ajaxCalls = [
|
var ajaxCalls = [
|
||||||
{{ range $key, $value := .Repositories }}
|
{{ range $key, $value := .Repositories }}
|
||||||
|
@ -64,6 +67,7 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
{{end}}
|
||||||
<script>
|
<script>
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||||
|
|
Loading…
Reference in a new issue