Skip to content

Commit

Permalink
feat: expose raw machine tags for external automation (#1618)
Browse files Browse the repository at this point in the history
Fixes #1615

Enable accessing the raw machine tags for external automation
  • Loading branch information
ipcrm committed Apr 29, 2024
1 parent 7ddbd38 commit 5e2e2c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/v2_vulnerabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,21 @@ func (v *VulnerabilityHost) GetMachineTags() (machineTags VulnerabilityHostMachi
return
}

func (v *VulnerabilityHost) GetMachineTagsRaw() (map[string]interface{}, error) {
jsonTags, err := json.Marshal(v.MachineTags)
if err != nil {
return nil, err
}

var rawTags map[string]interface{}

if err := json.Unmarshal(jsonTags, &rawTags); err != nil {
return nil, err
}

return rawTags, nil
}

type VulnerabilityHostMachineTags struct {
Account string `json:"Account"`
AmiID string `json:"AmiId"`
Expand Down
13 changes: 13 additions & 0 deletions api/v2_vulnerabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,19 @@ func TestV2Vulnerabilities_Hosts_AllPages(t *testing.T) {
}
}

func TestV2Vulnerabilities_HostGetAwsMachineTagsRaw(t *testing.T) {
var mockHostResponse api.VulnerabilitiesHostResponse
err := json.Unmarshal([]byte(mockVulnerabilitiesHostsResponseSetTags(vulnerabilityHostAwsMachineTags)), &mockHostResponse)
assert.NoError(t, err)

tags, err := mockHostResponse.Data[0].GetMachineTagsRaw()
assert.NoError(t, err)
assert.Equal(t, tags["Account"], "123456789038")
assert.Equal(t, tags["AmiId"], "ami-1234567890540c038")
assert.Equal(t, tags["ExternalIp"], "1.5.8.9")
assert.Equal(t, tags["Hostname"], "ip-192-168-28-69.us-east-2.compute.internal")
}

func TestV2Vulnerabilities_HostGetAwsMachineTags(t *testing.T) {
var mockHostResponse api.VulnerabilitiesHostResponse
err := json.Unmarshal([]byte(mockVulnerabilitiesHostsResponseSetTags(vulnerabilityHostAwsMachineTags)), &mockHostResponse)
Expand Down

0 comments on commit 5e2e2c3

Please sign in to comment.