Skip to content

Commit

Permalink
api/v3: Add feature type to API feature
Browse files Browse the repository at this point in the history
API now returns every feature found by the detectors and also indicates
the type of feature.
  • Loading branch information
KeyboardNerd committed Feb 19, 2019
1 parent 870e812 commit 32b11e5
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 82 deletions.
175 changes: 93 additions & 82 deletions api/v3/clairpb/clair.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/v3/clairpb/clair.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ message Feature {
Detector detector = 5;
// The list of vulnerabilities that affect the feature.
repeated Vulnerability vulnerabilities = 6;
// The feature type indicates if the feature represents a source package or
// binary package.
string feature_type = 7;
}

message Layer {
Expand Down
4 changes: 4 additions & 0 deletions api/v3/clairpb/clair.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@
"$ref": "#/definitions/clairVulnerability"
},
"description": "The list of vulnerabilities that affect the feature."
},
"feature_type": {
"type": "string",
"description": "The feature type indicates if the feature represents a source package or\nbinary package."
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions api/v3/clairpb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func NotificationFromDatabaseModel(dbNotification database.VulnerabilityNotifica
return &noti, nil
}

// VulnerabilityFromDatabaseModel converts database Vulnerability to api Vulnerability.
func VulnerabilityFromDatabaseModel(dbVuln database.Vulnerability) (*Vulnerability, error) {
metaString := ""
if dbVuln.Metadata != nil {
Expand All @@ -119,6 +120,7 @@ func VulnerabilityFromDatabaseModel(dbVuln database.Vulnerability) (*Vulnerabili
}, nil
}

// VulnerabilityWithFixedInFromDatabaseModel converts database VulnerabilityWithFixedIn to api Vulnerability.
func VulnerabilityWithFixedInFromDatabaseModel(dbVuln database.VulnerabilityWithFixedIn) (*Vulnerability, error) {
vuln, err := VulnerabilityFromDatabaseModel(dbVuln.Vulnerability)
if err != nil {
Expand All @@ -145,9 +147,11 @@ func NamespacedFeatureFromDatabaseModel(feature database.AncestryFeature) *Featu
VersionFormat: feature.Namespace.VersionFormat,
Version: version,
Detector: DetectorFromDatabaseModel(feature.FeatureBy),
FeatureType: string(feature.Type),
}
}

// DetectorFromDatabaseModel converts database detector to api detector.
func DetectorFromDatabaseModel(detector database.Detector) *Detector {
return &Detector{
Name: detector.Name,
Expand All @@ -156,6 +160,7 @@ func DetectorFromDatabaseModel(detector database.Detector) *Detector {
}
}

// DetectorsFromDatabaseModel converts database detectors to api detectors.
func DetectorsFromDatabaseModel(dbDetectors []database.Detector) []*Detector {
detectors := make([]*Detector, 0, len(dbDetectors))
for _, d := range dbDetectors {
Expand Down

0 comments on commit 32b11e5

Please sign in to comment.