api: implement get namespaces route
This commit is contained in:
parent
b916fba4c6
commit
38aeed4f2c
@ -18,14 +18,9 @@ type Error struct {
|
|||||||
Message string `json:"Layer`
|
Message string `json:"Layer`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LayerEnvelope struct {
|
|
||||||
Layer *Layer `json:"Layer,omitempty"`
|
|
||||||
Error *Error `json:"Error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Layer struct {
|
type Layer struct {
|
||||||
Name string `json:"Name,omitempty"`
|
Name string `json:"Name,omitempty"`
|
||||||
NamespaceName string `json:"NamespaceName,omitempty"`
|
Namespace string `json:"Namespace,omitempty"`
|
||||||
Path string `json:"Path,omitempty"`
|
Path string `json:"Path,omitempty"`
|
||||||
ParentName string `json:"ParentName,omitempty"`
|
ParentName string `json:"ParentName,omitempty"`
|
||||||
Format string `json:"Format,omitempty"`
|
Format string `json:"Format,omitempty"`
|
||||||
@ -35,7 +30,7 @@ type Layer struct {
|
|||||||
|
|
||||||
type Vulnerability struct {
|
type Vulnerability struct {
|
||||||
Name string `json:"Name,omitempty"`
|
Name string `json:"Name,omitempty"`
|
||||||
NamespaceName string `json:"NamespaceName,omitempty"`
|
Namespace string `json:"Namespace,omitempty"`
|
||||||
Description string `json:"Description,omitempty"`
|
Description string `json:"Description,omitempty"`
|
||||||
Severity string `json:"Severity,omitempty"`
|
Severity string `json:"Severity,omitempty"`
|
||||||
FixedBy string `json:"FixedBy,omitempty"`
|
FixedBy string `json:"FixedBy,omitempty"`
|
||||||
@ -66,3 +61,13 @@ type VulnerabilityWithLayers struct {
|
|||||||
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"`
|
Vulnerability *Vulnerability `json:"Vulnerability,omitempty"`
|
||||||
LayersIntroducingVulnerability []string `json:"LayersIntroducingVulnerability,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"`
|
||||||
|
}
|
||||||
|
@ -92,7 +92,7 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dbLayer.Namespace != nil {
|
if dbLayer.Namespace != nil {
|
||||||
layer.NamespaceName = dbLayer.Namespace.Name
|
layer.Namespace = dbLayer.Namespace.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
if withFeatures || withVulnerabilities && dbLayer.Features != nil {
|
if withFeatures || withVulnerabilities && dbLayer.Features != nil {
|
||||||
@ -106,7 +106,7 @@ func getLayer(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *
|
|||||||
for _, dbVuln := range dbFeatureVersion.AffectedBy {
|
for _, dbVuln := range dbFeatureVersion.AffectedBy {
|
||||||
vuln := Vulnerability{
|
vuln := Vulnerability{
|
||||||
Name: dbVuln.Name,
|
Name: dbVuln.Name,
|
||||||
NamespaceName: dbVuln.Namespace.Name,
|
Namespace: dbVuln.Namespace.Name,
|
||||||
Description: dbVuln.Description,
|
Description: dbVuln.Description,
|
||||||
Severity: string(dbVuln.Severity),
|
Severity: string(dbVuln.Severity),
|
||||||
}
|
}
|
||||||
@ -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 {
|
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 {
|
func postVulnerability(w http.ResponseWriter, r *http.Request, p httprouter.Params, ctx *context.RouteContext) int {
|
||||||
|
Loading…
Reference in New Issue
Block a user