mirror of
https://github.com/genuinetools/reg.git
synced 2024-06-30 19:14:16 -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
|
@ -35,8 +35,16 @@ func (c *Clair) GetAncestry(name string) (*clairpb.GetAncestryResponse_Ancestry,
|
||||||
func (c *Clair) PostAncestry(name string, layers []*clairpb.PostAncestryRequest_PostLayer) error {
|
func (c *Clair) PostAncestry(name string, layers []*clairpb.PostAncestryRequest_PostLayer) error {
|
||||||
c.Logf("clair.ancestry.post name=%s", name)
|
c.Logf("clair.ancestry.post name=%s", name)
|
||||||
|
|
||||||
|
if c.grpcConn == nil {
|
||||||
|
return errors.New("grpcConn cannot be nil")
|
||||||
|
}
|
||||||
|
|
||||||
client := clairpb.NewAncestryServiceClient(c.grpcConn)
|
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{
|
resp, err := client.PostAncestry(context.Background(), &clairpb.PostAncestryRequest{
|
||||||
AncestryName: name,
|
AncestryName: name,
|
||||||
Layers: layers,
|
Layers: layers,
|
||||||
|
|
20
handlers.go
20
handlers.go
|
@ -260,17 +260,33 @@ func (rc *registryController) vulnerabilitiesHandler(w http.ResponseWriter, r *h
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := rc.cl.Vulnerabilities(rc.reg, repo, tag)
|
image, err := registry.ParseImage(repo + ":" + tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"func": "vulnerabilities",
|
"func": "vulnerabilities",
|
||||||
"URL": r.URL,
|
"URL": r.URL,
|
||||||
"method": r.Method,
|
"method": r.Method,
|
||||||
}).Errorf("vulnerability scanning for %s:%s failed: %v", repo, tag, err)
|
}).Errorf("parsing image %s:%s failed: %v", repo, tag, err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
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",
|
||||||
|
"URL": r.URL,
|
||||||
|
"method": r.Method,
|
||||||
|
}).Errorf("vulnerability scanning for %s:%s failed: %v", repo, tag, err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue