Skip to content

Commit

Permalink
api: simplify getLayer route and JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent 92b734d commit 6e20993
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
12 changes: 3 additions & 9 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
16 changes: 8 additions & 8 deletions database/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,7 +36,7 @@ type FeatureVersion struct {

Feature Feature
Version types.Version
AffectedBy []Vulnerability
AffectedBy []Vulnerability `json:",omitempty"`
}

type Vulnerability struct {
Expand All @@ -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"`
}

0 comments on commit 6e20993

Please sign in to comment.