Skip to content

Commit 1ac4ce2

Browse files
committed
feat(query): expose severity on config insight search results
Add a Severity *string field to SelectedResource, populated only for config insights. Severity is orthogonal to Health (healthy/unhealthy/ warning/unknown) and Status, so it gets its own field rather than overloading either. Other resource kinds leave it nil, which is omitted from the JSON response.
1 parent a4d074d commit 1ac4ce2

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

query/resource_selector.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ type SelectedResource struct {
7878
// Status is the resource's free-form operational status (e.g. "Running",
7979
// "Pending"). Populated for configs and components.
8080
Status string `json:"status,omitempty"`
81+
// Severity is populated for resource kinds that carry a severity
82+
// (e.g. config insights). nil for other kinds.
83+
Severity *string `json:"severity,omitempty"`
8184
}
8285

8386
func SearchResources(ctx context.Context, req SearchResourcesRequest) (*SearchResourcesResponse, error) {
@@ -197,11 +200,16 @@ func SearchResources(ctx context.Context, req SearchResourcesRequest) (*SearchRe
197200
return err
198201
} else {
199202
for i := range items {
203+
var severity *string
204+
if s := string(items[i].Severity); s != "" {
205+
severity = &s
206+
}
200207
output.ConfigAnalysis = append(output.ConfigAnalysis, SelectedResource{
201-
ID: items[i].ID.String(),
202-
Name: items[i].Analyzer,
203-
Type: string(items[i].AnalysisType),
204-
Status: items[i].Status,
208+
ID: items[i].ID.String(),
209+
Name: items[i].Analyzer,
210+
Type: string(items[i].AnalysisType),
211+
Status: items[i].Status,
212+
Severity: severity,
205213
})
206214
}
207215
}

tests/query_resource_selector_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ var _ = ginkgo.Describe("Config Analysis Resource Selector", func() {
791791
Expect(response.ConfigAnalysis[0].ID).To(Equal(dummy.LogisticsDBRDSAnalysis.ID.String()))
792792
Expect(response.ConfigAnalysis[0].Name).To(Equal("rds-port-exposed"))
793793
Expect(response.ConfigAnalysis[0].Type).To(Equal(string(models.AnalysisTypeSecurity)))
794+
Expect(response.ConfigAnalysis[0].Severity).To(Equal(lo.ToPtr(string(models.SeverityCritical))))
794795
})
795796
})
796797

0 commit comments

Comments
 (0)