api: implement get namespaces route

This commit is contained in:
Jimmy Zelinskie 2016-01-29 16:43:17 -05:00
parent b916fba4c6
commit 38aeed4f2c
2 changed files with 34 additions and 18 deletions

View File

@ -18,14 +18,9 @@ type Error struct {
Message string `json:"Layer`
}
type LayerEnvelope struct {
Layer *Layer `json:"Layer,omitempty"`
Error *Error `json:"Error,omitempty"`
}
type Layer struct {
Name string `json:"Name,omitempty"`
NamespaceName string `json:"NamespaceName,omitempty"`
Namespace string `json:"Namespace,omitempty"`
Path string `json:"Path,omitempty"`
ParentName string `json:"ParentName,omitempty"`
Format string `json:"Format,omitempty"`
@ -34,12 +29,12 @@ type Layer struct {
}
type Vulnerability struct {
Name string `json:"Name,omitempty"`
NamespaceName string `json:"NamespaceName,omitempty"`
Description string `json:"Description,omitempty"`
Severity string `json:"Severity,omitempty"`
FixedBy string `json:"FixedBy,omitempty"`
FixedIn []Feature `json:"FixedIn,omitempty"`
Name string `json:"Name,omitempty"`
Namespace string `json:"Namespace,omitempty"`
Description string `json:"Description,omitempty"`
Severity string `json:"Severity,omitempty"`
FixedBy string `json:"FixedBy,omitempty"`
FixedIn []Feature `json:"FixedIn,omitempty"`
}
type Feature struct {
@ -66,3 +61,13 @@ type VulnerabilityWithLayers struct {
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"`
LayersIntroducingVulnerability []string `json:"LayersIntroducingVulnerability,omitempty"`
}
type LayerEnvelope struct {
Layer *Layer `json:"Layer,omitempty"`
Error *Error `json:"Error,omitempty"`
}
type NamespaceEnvelope struct {
Namespaces *[]string `json:"Namespaces,omitempty"`
Error *Error `json:"Error,omitempty"`
}

View File

@ -92,7 +92,7 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
}
if dbLayer.Namespace != nil {
layer.NamespaceName = dbLayer.Namespace.Name
layer.Namespace = dbLayer.Namespace.Name
}
if withFeatures || withVulnerabilities && dbLayer.Features != nil {
@ -105,10 +105,10 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
for _, dbVuln := range dbFeatureVersion.AffectedBy {
vuln := Vulnerability{
Name: dbVuln.Name,
NamespaceName: dbVuln.Namespace.Name,
Description: dbVuln.Description,
Severity: string(dbVuln.Severity),
Name: dbVuln.Name,
Namespace: dbVuln.Namespace.Name,
Description: dbVuln.Description,
Severity: string(dbVuln.Severity),
}
if dbVuln.FixedBy != types.MaxVersion {
@ -138,7 +138,18 @@ func deleteLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ct
}
func getNamespaces(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) int {
return 0
dbNamespaces, err := ctx.Store.ListNamespaces()
if err != nil {
writeResponse(w, NamespaceEnvelope{Error: &Error{err.Error()}})
return writeHeader(w, http.StatusInternalServerError)
}
var namespaces []string
for _, dbNamespace := range dbNamespaces {
namespaces = append(namespaces, dbNamespace.Name)
}
writeResponse(w, NamespaceEnvelope{Namespaces: &namespaces})
return writeHeader(w, http.StatusOK)
}
func postVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) int {