diff --git a/api/handlers.go b/api/handlers.go index f467260b..bbba8bc8 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -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 // and vulnerabilities. func GETLayers(w http.ResponseWriter, r *http.Request, p httprouter.Params, e *Env) { - withFeatures := false - withVulnerabilities := false - if r.URL.Query().Get("withFeatures") == "true" { - withFeatures = true - } - if r.URL.Query().Get("withVulnerabilities") == "true" { - withFeatures = true - withVulnerabilities = true - } + _, withFeatures := r.URL.Query()["withFeatures"] + _, withVulnerabilities := r.URL.Query()["withVulnerabilities"] layer, err := e.Datastore.FindLayer(p.ByName("id"), withFeatures, withVulnerabilities) if err != nil { httputils.WriteHTTPError(w, 0, err) return } + httputils.WriteHTTP(w, http.StatusOK, struct{ Layer database.Layer }{Layer: layer}) } diff --git a/database/models.go b/database/models.go index a7bef10d..31c5904b 100644 --- a/database/models.go +++ b/database/models.go @@ -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. type Model struct { - ID int + ID int `json:"-"` } type Layer struct { Model Name string - EngineVersion int - Parent *Layer - Namespace *Namespace - Features []FeatureVersion + EngineVersion int `json:",omitempty"` + Parent *Layer `json:",omitempty"` + Namespace *Namespace `json:",omitempty"` + Features []FeatureVersion `json:",omitempty"` } type Namespace struct { @@ -36,7 +36,7 @@ type FeatureVersion struct { Feature Feature Version types.Version - AffectedBy []Vulnerability + AffectedBy []Vulnerability `json:",omitempty"` } type Vulnerability struct { @@ -48,10 +48,10 @@ type Vulnerability struct { Link string Severity types.Priority - FixedIn []FeatureVersion + FixedIn []FeatureVersion `json:",omitempty"` //Affects []FeatureVersion // For output purposes. Only make sense when the vulnerability // is already about a specific Feature/FeatureVersion. - FixedBy types.Version + FixedBy types.Version `json:",omitempty"` }