From cfb0a752e9d3d77e489c0c09512204fa62b8bcb9 Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Mon, 29 Jan 2024 02:17:41 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20aws.efs.filesystem=20resou?= =?UTF-8?q?rce=20(add=20init)=20(#3147)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Christoph Hartmann Co-authored-by: Tim Smith --- providers/aws/resources/aws_efs.go | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/providers/aws/resources/aws_efs.go b/providers/aws/resources/aws_efs.go index 2e1c426304..f6b3ac7667 100644 --- a/providers/aws/resources/aws_efs.go +++ b/providers/aws/resources/aws_efs.go @@ -13,6 +13,7 @@ import ( "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v10/llx" + "go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v10/providers-sdk/v1/util/convert" "go.mondoo.com/cnquery/v10/providers-sdk/v1/util/jobpool" "go.mondoo.com/cnquery/v10/providers/aws/connection" @@ -115,6 +116,44 @@ func (a *mqlAwsEfsFilesystem) kmsKey() (*mqlAwsKmsKey, error) { return a.GetKmsKey().Data, nil } +func initAwsEfsFilesystem(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { + if len(args) > 2 { + return args, nil, nil + } + + if len(args) == 0 { + if ids := getAssetIdentifier(runtime); ids != nil { + args["name"] = llx.StringData(ids.name) + args["arn"] = llx.StringData(ids.arn) + } + } + + if args["arn"] == nil { + return nil, nil, errors.New("arn required to fetch efs filesystem") + } + + // load all efs filesystems + obj, err := CreateResource(runtime, "aws.efs", map[string]*llx.RawData{}) + if err != nil { + return nil, nil, err + } + efs := obj.(*mqlAwsEfs) + + rawResources := efs.GetFilesystems() + if err != nil { + return nil, nil, err + } + + arnVal := args["arn"].Value.(string) + for i := range rawResources.Data { + fs := rawResources.Data[i].(*mqlAwsEfsFilesystem) + if fs.Arn.Data == arnVal { + return args, fs, nil + } + } + return nil, nil, errors.New("efs filesystem does not exist") +} + func (a *mqlAwsEfsFilesystem) backupPolicy() (interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AwsConnection) id := a.Id.Data