api: simplify getLayer route and JSON output
This commit is contained in:
parent
92b734d0a4
commit
6e20993bac
@ -90,20 +90,14 @@ func DELETELayers(w http.ResponseWriter, r *http.Request, p httprouter.Params, e
|
|||||||
// GETLayers returns informations about an existing layer, optionally with its features
|
// GETLayers returns informations about an existing layer, optionally with its features
|
||||||
// and vulnerabilities.
|
// and vulnerabilities.
|
||||||
func GETLayers(w http.ResponseWriter, r *http.Request, p httprouter.Params, e *Env) {
|
func GETLayers(w http.ResponseWriter, r *http.Request, p httprouter.Params, e *Env) {
|
||||||
withFeatures := false
|
_, withFeatures := r.URL.Query()["withFeatures"]
|
||||||
withVulnerabilities := false
|
_, withVulnerabilities := r.URL.Query()["withVulnerabilities"]
|
||||||
if r.URL.Query().Get("withFeatures") == "true" {
|
|
||||||
withFeatures = true
|
|
||||||
}
|
|
||||||
if r.URL.Query().Get("withVulnerabilities") == "true" {
|
|
||||||
withFeatures = true
|
|
||||||
withVulnerabilities = true
|
|
||||||
}
|
|
||||||
|
|
||||||
layer, err := e.Datastore.FindLayer(p.ByName("id"), withFeatures, withVulnerabilities)
|
layer, err := e.Datastore.FindLayer(p.ByName("id"), withFeatures, withVulnerabilities)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httputils.WriteHTTPError(w, 0, err)
|
httputils.WriteHTTPError(w, 0, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
httputils.WriteHTTP(w, http.StatusOK, struct{ Layer database.Layer }{Layer: layer})
|
httputils.WriteHTTP(w, http.StatusOK, struct{ Layer database.Layer }{Layer: layer})
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,17 @@ import "github.com/coreos/clair/utils/types"
|
|||||||
|
|
||||||
// ID is only meant to be used by database implementations and should never be used for anything else.
|
// ID is only meant to be used by database implementations and should never be used for anything else.
|
||||||
type Model struct {
|
type Model struct {
|
||||||
ID int
|
ID int `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Layer struct {
|
type Layer struct {
|
||||||
Model
|
Model
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
EngineVersion int
|
EngineVersion int `json:",omitempty"`
|
||||||
Parent *Layer
|
Parent *Layer `json:",omitempty"`
|
||||||
Namespace *Namespace
|
Namespace *Namespace `json:",omitempty"`
|
||||||
Features []FeatureVersion
|
Features []FeatureVersion `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Namespace struct {
|
type Namespace struct {
|
||||||
@ -36,7 +36,7 @@ type FeatureVersion struct {
|
|||||||
|
|
||||||
Feature Feature
|
Feature Feature
|
||||||
Version types.Version
|
Version types.Version
|
||||||
AffectedBy []Vulnerability
|
AffectedBy []Vulnerability `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vulnerability struct {
|
type Vulnerability struct {
|
||||||
@ -48,10 +48,10 @@ type Vulnerability struct {
|
|||||||
Link string
|
Link string
|
||||||
Severity types.Priority
|
Severity types.Priority
|
||||||
|
|
||||||
FixedIn []FeatureVersion
|
FixedIn []FeatureVersion `json:",omitempty"`
|
||||||
//Affects []FeatureVersion
|
//Affects []FeatureVersion
|
||||||
|
|
||||||
// For output purposes. Only make sense when the vulnerability
|
// For output purposes. Only make sense when the vulnerability
|
||||||
// is already about a specific Feature/FeatureVersion.
|
// is already about a specific Feature/FeatureVersion.
|
||||||
FixedBy types.Version
|
FixedBy types.Version `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user