From 8b28357284a2fea6b7cee7aadd6ee56bf9014c0a Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 30 Nov 2024 16:25:58 -0800 Subject: [PATCH] Add additional fields to ECR resource - lastRecordedPullTime - pushedAt - sizeInBytes ``` ... lastRecordedPullTime: 2024-11-14 15:23:42.949 -0800 PST pushedAt: 2024-03-19 11:50:13 -0700 PDT sizeInBytes: 83520228 ... ``` Signed-off-by: Tim Smith --- providers/aws/resources/aws.lr | 6 ++++ providers/aws/resources/aws.lr.go | 36 ++++++++++++++++++++ providers/aws/resources/aws.lr.manifest.yaml | 6 ++++ providers/aws/resources/aws_ecr.go | 19 ++++++----- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/providers/aws/resources/aws.lr b/providers/aws/resources/aws.lr index e78c1c2bbc..bbc38888c1 100644 --- a/providers/aws/resources/aws.lr +++ b/providers/aws/resources/aws.lr @@ -2497,6 +2497,12 @@ private aws.ecr.image @defaults("uri region") { arn string // uri for the image repository uri string + // The time the image was pushed + pushedAt time + // The size of the image in bytes + sizeInBytes int + // The last time Amazon recorded an image pull. Note: Amazon only refreshes this data once every 24 hours so it is not fully granular. + lastRecordedPullTime time } // AWS Database Migration Service (DMS) diff --git a/providers/aws/resources/aws.lr.go b/providers/aws/resources/aws.lr.go index c2cda90fc4..a4aa3937d0 100644 --- a/providers/aws/resources/aws.lr.go +++ b/providers/aws/resources/aws.lr.go @@ -3728,6 +3728,15 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "aws.ecr.image.uri": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsEcrImage).GetUri()).ToDataRes(types.String) }, + "aws.ecr.image.pushedAt": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAwsEcrImage).GetPushedAt()).ToDataRes(types.Time) + }, + "aws.ecr.image.sizeInBytes": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAwsEcrImage).GetSizeInBytes()).ToDataRes(types.Int) + }, + "aws.ecr.image.lastRecordedPullTime": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAwsEcrImage).GetLastRecordedPullTime()).ToDataRes(types.Time) + }, "aws.dms.replicationInstances": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsDms).GetReplicationInstances()).ToDataRes(types.Array(types.Dict)) }, @@ -9391,6 +9400,18 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAwsEcrImage).Uri, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "aws.ecr.image.pushedAt": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAwsEcrImage).PushedAt, ok = plugin.RawToTValue[*time.Time](v.Value, v.Error) + return + }, + "aws.ecr.image.sizeInBytes": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAwsEcrImage).SizeInBytes, ok = plugin.RawToTValue[int64](v.Value, v.Error) + return + }, + "aws.ecr.image.lastRecordedPullTime": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAwsEcrImage).LastRecordedPullTime, ok = plugin.RawToTValue[*time.Time](v.Value, v.Error) + return + }, "aws.dms.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAwsDms).__id, ok = v.Value.(string) return @@ -23718,6 +23739,9 @@ type mqlAwsEcrImage struct { Region plugin.TValue[string] Arn plugin.TValue[string] Uri plugin.TValue[string] + PushedAt plugin.TValue[*time.Time] + SizeInBytes plugin.TValue[int64] + LastRecordedPullTime plugin.TValue[*time.Time] } // createAwsEcrImage creates a new instance of this resource @@ -23789,6 +23813,18 @@ func (c *mqlAwsEcrImage) GetUri() *plugin.TValue[string] { return &c.Uri } +func (c *mqlAwsEcrImage) GetPushedAt() *plugin.TValue[*time.Time] { + return &c.PushedAt +} + +func (c *mqlAwsEcrImage) GetSizeInBytes() *plugin.TValue[int64] { + return &c.SizeInBytes +} + +func (c *mqlAwsEcrImage) GetLastRecordedPullTime() *plugin.TValue[*time.Time] { + return &c.LastRecordedPullTime +} + // mqlAwsDms for the aws.dms resource type mqlAwsDms struct { MqlRuntime *plugin.Runtime diff --git a/providers/aws/resources/aws.lr.manifest.yaml b/providers/aws/resources/aws.lr.manifest.yaml index 653f20e920..3df758a4b5 100755 --- a/providers/aws/resources/aws.lr.manifest.yaml +++ b/providers/aws/resources/aws.lr.manifest.yaml @@ -1294,10 +1294,16 @@ resources: fields: arn: {} digest: {} + lastRecordedPullTime: + min_mondoo_version: 9.0.0 mediaType: {} + pushedAt: + min_mondoo_version: 9.0.0 region: {} registryId: {} repoName: {} + sizeInBytes: + min_mondoo_version: 9.0.0 tags: {} uri: {} is_private: true diff --git a/providers/aws/resources/aws_ecr.go b/providers/aws/resources/aws_ecr.go index 48b3721fab..b862a876d7 100644 --- a/providers/aws/resources/aws_ecr.go +++ b/providers/aws/resources/aws_ecr.go @@ -198,14 +198,17 @@ func (a *mqlAwsEcrRepository) images() ([]interface{}, error) { } mqlImage, err := CreateResource(a.MqlRuntime, "aws.ecr.image", map[string]*llx.RawData{ - "digest": llx.StringDataPtr(image.ImageDigest), - "mediaType": llx.StringDataPtr(image.ImageManifestMediaType), - "tags": llx.ArrayData(tags, types.String), - "registryId": llx.StringDataPtr(image.RegistryId), - "repoName": llx.StringData(name), - "region": llx.StringData(region), - "arn": llx.StringData(ecrImageArn(ImageInfo{Region: region, RegistryId: convert.ToString(image.RegistryId), RepoName: name, Digest: convert.ToString(image.ImageDigest)})), - "uri": llx.StringData(uri), + "arn": llx.StringData(ecrImageArn(ImageInfo{Region: region, RegistryId: convert.ToString(image.RegistryId), RepoName: name, Digest: convert.ToString(image.ImageDigest)})), + "digest": llx.StringDataPtr(image.ImageDigest), + "lastRecordedPullTime": llx.TimeDataPtr(image.LastRecordedPullTime), + "mediaType": llx.StringDataPtr(image.ImageManifestMediaType), + "pushedAt": llx.TimeDataPtr(image.ImagePushedAt), + "region": llx.StringData(region), + "registryId": llx.StringDataPtr(image.RegistryId), + "repoName": llx.StringData(name), + "sizeInBytes": llx.IntDataPtr(image.ImageSizeInBytes), + "tags": llx.ArrayData(tags, types.String), + "uri": llx.StringData(uri), }) if err != nil { return nil, err