Skip to content

Commit

Permalink
🧹 add back in ecr-api and ecs-api discovery (#2860)
Browse files Browse the repository at this point in the history
* 🧹 add instance type to ec2 instance labels

* 🧹 add back in ecr-api and ecs-api discovery
  • Loading branch information
vjeffrey authored Dec 20, 2023
1 parent 7e9832b commit c9708e5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
62 changes: 60 additions & 2 deletions providers/aws/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,66 @@ func discover(runtime *plugin.Runtime, awsAccount *mqlAwsAccount, target string,
}
}
}
// case DiscoveryECSContainersAPI:
// case DiscoveryECRImageAPI:
case DiscoveryECSContainersAPI:
res, err := NewResource(runtime, "aws.ecs", map[string]*llx.RawData{})
if err != nil {
return nil, err
}

ecs := res.(*mqlAwsEcs)

containers := ecs.GetContainers()
if containers == nil {
return assetList, nil
}

for i := range containers.Data {
c := containers.Data[i].(*mqlAwsEcsContainer)
if !containerMatchesFilters(c, filters) {
continue
}
assetList = append(assetList, MqlObjectToAsset(accountId,
mqlObject{
name: c.ContainerName.Data, labels: map[string]string{},
awsObject: awsObject{
account: accountId, region: c.Region.Data, arn: c.Arn.Data,
id: c.Arn.Data, service: "ecs", objectType: "container",
},
}, conn))
}

case DiscoveryECRImageAPI:
res, err := NewResource(runtime, "aws.ecr", map[string]*llx.RawData{})
if err != nil {
return nil, err
}

ecr := res.(*mqlAwsEcr)

images := ecr.GetImages()
if images == nil {
return assetList, nil
}

for i := range images.Data {
a := images.Data[i].(*mqlAwsEcrImage)
if !imageMatchesFilters(a, filters) {
continue
}
l := make(map[string]string)
for i := range a.Tags.Data {
l[a.Tags.Data[i].(string)] = ""
}

assetList = append(assetList, MqlObjectToAsset(accountId,
mqlObject{
name: l["Name"], labels: l,
awsObject: awsObject{
account: accountId, region: a.Region.Data, arn: a.Arn.Data,
id: a.Uri.Data, service: "ecr", objectType: "image",
},
}, conn))
}
case DiscoveryEC2InstanceAPI:
res, err := NewResource(runtime, "aws.ec2", map[string]*llx.RawData{})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions providers/aws/resources/discovery_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func addConnectionInfoToEc2Asset(instance *mqlAwsEc2Instance, accountId string,
asset.Options = conn.ConnectionOptions()
asset.Labels["mondoo.com/region"] = instance.Region.Data
asset.Labels["mondoo.com/platform"] = instance.PlatformDetails.Data
asset.Labels["mondoo.com/instance-type"] = instance.InstanceType.Data

if instance.GetImage().Data != nil {
asset.Labels["mondoo.com/image"] = instance.GetImage().Data.Id.Data
}
Expand Down

0 comments on commit c9708e5

Please sign in to comment.