Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose raw machine tags for external automation #1618

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading