Skip to content

Commit 5e2e2c3

Browse files
author
Matt Cadorette
authored
feat: expose raw machine tags for external automation (#1618)
Fixes #1615 Enable accessing the raw machine tags for external automation
1 parent 7ddbd38 commit 5e2e2c3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

api/v2_vulnerabilities.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,21 @@ func (v *VulnerabilityHost) GetMachineTags() (machineTags VulnerabilityHostMachi
517517
return
518518
}
519519

520+
func (v *VulnerabilityHost) GetMachineTagsRaw() (map[string]interface{}, error) {
521+
jsonTags, err := json.Marshal(v.MachineTags)
522+
if err != nil {
523+
return nil, err
524+
}
525+
526+
var rawTags map[string]interface{}
527+
528+
if err := json.Unmarshal(jsonTags, &rawTags); err != nil {
529+
return nil, err
530+
}
531+
532+
return rawTags, nil
533+
}
534+
520535
type VulnerabilityHostMachineTags struct {
521536
Account string `json:"Account"`
522537
AmiID string `json:"AmiId"`

api/v2_vulnerabilities_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,19 @@ func TestV2Vulnerabilities_Hosts_AllPages(t *testing.T) {
437437
}
438438
}
439439

440+
func TestV2Vulnerabilities_HostGetAwsMachineTagsRaw(t *testing.T) {
441+
var mockHostResponse api.VulnerabilitiesHostResponse
442+
err := json.Unmarshal([]byte(mockVulnerabilitiesHostsResponseSetTags(vulnerabilityHostAwsMachineTags)), &mockHostResponse)
443+
assert.NoError(t, err)
444+
445+
tags, err := mockHostResponse.Data[0].GetMachineTagsRaw()
446+
assert.NoError(t, err)
447+
assert.Equal(t, tags["Account"], "123456789038")
448+
assert.Equal(t, tags["AmiId"], "ami-1234567890540c038")
449+
assert.Equal(t, tags["ExternalIp"], "1.5.8.9")
450+
assert.Equal(t, tags["Hostname"], "ip-192-168-28-69.us-east-2.compute.internal")
451+
}
452+
440453
func TestV2Vulnerabilities_HostGetAwsMachineTags(t *testing.T) {
441454
var mockHostResponse api.VulnerabilitiesHostResponse
442455
err := json.Unmarshal([]byte(mockVulnerabilitiesHostsResponseSetTags(vulnerabilityHostAwsMachineTags)), &mockHostResponse)

0 commit comments

Comments
 (0)