mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-28 11:46:20 -04:00
fix v3 when grpcConn is nil
fixes #138 Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
e13ca36072
commit
6b207b0cf9
2 changed files with 26 additions and 2 deletions
|
@ -35,8 +35,16 @@ func (c *Clair) GetAncestry(name string) (*clairpb.GetAncestryResponse_Ancestry,
|
|||
func (c *Clair) PostAncestry(name string, layers []*clairpb.PostAncestryRequest_PostLayer) error {
|
||||
c.Logf("clair.ancestry.post name=%s", name)
|
||||
|
||||
if c.grpcConn == nil {
|
||||
return errors.New("grpcConn cannot be nil")
|
||||
}
|
||||
|
||||
client := clairpb.NewAncestryServiceClient(c.grpcConn)
|
||||
|
||||
if client == nil {
|
||||
return errors.New("could not establish connection to grpc clair api")
|
||||
}
|
||||
|
||||
resp, err := client.PostAncestry(context.Background(), &clairpb.PostAncestryRequest{
|
||||
AncestryName: name,
|
||||
Layers: layers,
|
||||
|
|
18
handlers.go
18
handlers.go
|
@ -260,7 +260,22 @@ func (rc *registryController) vulnerabilitiesHandler(w http.ResponseWriter, r *h
|
|||
return
|
||||
}
|
||||
|
||||
result, err := rc.cl.Vulnerabilities(rc.reg, repo, tag)
|
||||
image, err := registry.ParseImage(repo + ":" + tag)
|
||||
if err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"func": "vulnerabilities",
|
||||
"URL": r.URL,
|
||||
"method": r.Method,
|
||||
}).Errorf("parsing image %s:%s failed: %v", repo, tag, err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Get the vulnerability report.
|
||||
result, err := rc.cl.VulnerabilitiesV3(rc.reg, image.Path, image.Reference())
|
||||
if err != nil {
|
||||
// Fallback to Clair v2 API.
|
||||
result, err = rc.cl.Vulnerabilities(rc.reg, image.Path, image.Reference())
|
||||
if err != nil {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"func": "vulnerabilities",
|
||||
|
@ -270,6 +285,7 @@ func (rc *registryController) vulnerabilitiesHandler(w http.ResponseWriter, r *h
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasSuffix(r.URL.String(), ".json") {
|
||||
js, err := json.Marshal(result)
|
||||
|
|
Loading…
Reference in a new issue