-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
adapt.go
45 lines (39 loc) · 1.56 KB
/
adapt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package monitor
import (
"github.com/aquasecurity/trivy/pkg/iac/providers/azure/monitor"
"github.com/aquasecurity/trivy/pkg/iac/scanners/azure"
"github.com/aquasecurity/trivy/pkg/iac/types"
)
func Adapt(deployment azure.Deployment) monitor.Monitor {
return monitor.Monitor{
LogProfiles: adaptLogProfiles(deployment),
}
}
func adaptLogProfiles(deployment azure.Deployment) (logProfiles []monitor.LogProfile) {
for _, resource := range deployment.GetResourcesByType("Microsoft.Insights/logProfiles") {
logProfiles = append(logProfiles, adaptLogProfile(resource))
}
return logProfiles
}
func adaptLogProfile(resource azure.Resource) monitor.LogProfile {
categories := resource.Properties.GetMapValue("categories").AsList()
var categoriesList []types.StringValue
for _, category := range categories {
categoriesList = append(categoriesList, category.AsStringValue("", category.Metadata))
}
locations := resource.Properties.GetMapValue("locations").AsList()
var locationsList []types.StringValue
for _, location := range locations {
locationsList = append(locationsList, location.AsStringValue("", location.Metadata))
}
return monitor.LogProfile{
Metadata: resource.Metadata,
RetentionPolicy: monitor.RetentionPolicy{
Metadata: resource.Metadata,
Enabled: resource.Properties.GetMapValue("retentionPolicy").GetMapValue("enabled").AsBoolValue(false, resource.Metadata),
Days: resource.Properties.GetMapValue("retentionPolicy").GetMapValue("days").AsIntValue(0, resource.Metadata),
},
Categories: categoriesList,
Locations: locationsList,
}
}