diff --git a/providers/aws/resources/aws.lr b/providers/aws/resources/aws.lr index 23a76566ab..fe79db894e 100644 --- a/providers/aws/resources/aws.lr +++ b/providers/aws/resources/aws.lr @@ -1033,14 +1033,14 @@ private aws.s3.bucket.corsrule @defaults("name") { // Amazon S3 Bucket Policy private aws.s3.bucket.policy @defaults("name version") { + // Unique ID for the policy + id string // Name for the policy name string // Document for the policy document string // Version of the policy version() string - // Unique ID for the policy - id string // List of statements for the policy statements() []dict } diff --git a/providers/aws/resources/aws.lr.go b/providers/aws/resources/aws.lr.go index 920a96391b..9d537abca1 100644 --- a/providers/aws/resources/aws.lr.go +++ b/providers/aws/resources/aws.lr.go @@ -1663,6 +1663,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "aws.s3.bucket.corsrule.maxAgeSeconds": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsS3BucketCorsrule).GetMaxAgeSeconds()).ToDataRes(types.Int) }, + "aws.s3.bucket.policy.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAwsS3BucketPolicy).GetId()).ToDataRes(types.String) + }, "aws.s3.bucket.policy.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsS3BucketPolicy).GetName()).ToDataRes(types.String) }, @@ -1672,9 +1675,6 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "aws.s3.bucket.policy.version": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsS3BucketPolicy).GetVersion()).ToDataRes(types.String) }, - "aws.s3.bucket.policy.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAwsS3BucketPolicy).GetId()).ToDataRes(types.String) - }, "aws.s3.bucket.policy.statements": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAwsS3BucketPolicy).GetStatements()).ToDataRes(types.Array(types.Dict)) }, @@ -4369,6 +4369,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAwsS3BucketPolicy).__id, ok = v.Value.(string) return }, + "aws.s3.bucket.policy.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAwsS3BucketPolicy).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "aws.s3.bucket.policy.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAwsS3BucketPolicy).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return @@ -4381,10 +4385,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAwsS3BucketPolicy).Version, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "aws.s3.bucket.policy.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAwsS3BucketPolicy).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, "aws.s3.bucket.policy.statements": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAwsS3BucketPolicy).Statements, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -11626,10 +11626,10 @@ type mqlAwsS3BucketPolicy struct { MqlRuntime *plugin.Runtime __id string // optional: if you define mqlAwsS3BucketPolicyInternal it will be used here + Id plugin.TValue[string] Name plugin.TValue[string] Document plugin.TValue[string] Version plugin.TValue[string] - Id plugin.TValue[string] Statements plugin.TValue[[]interface{}] } @@ -11670,6 +11670,10 @@ func (c *mqlAwsS3BucketPolicy) MqlID() string { return c.__id } +func (c *mqlAwsS3BucketPolicy) GetId() *plugin.TValue[string] { + return &c.Id +} + func (c *mqlAwsS3BucketPolicy) GetName() *plugin.TValue[string] { return &c.Name } @@ -11684,10 +11688,6 @@ func (c *mqlAwsS3BucketPolicy) GetVersion() *plugin.TValue[string] { }) } -func (c *mqlAwsS3BucketPolicy) GetId() *plugin.TValue[string] { - return &c.Id -} - func (c *mqlAwsS3BucketPolicy) GetStatements() *plugin.TValue[[]interface{}] { return plugin.GetOrCompute[[]interface{}](&c.Statements, func() ([]interface{}, error) { return c.statements() diff --git a/providers/aws/resources/aws_s3.go b/providers/aws/resources/aws_s3.go index 517cecb04c..d79fb4ab70 100644 --- a/providers/aws/resources/aws_s3.go +++ b/providers/aws/resources/aws_s3.go @@ -164,13 +164,25 @@ func (a *mqlAwsS3Bucket) id() (string, error) { return a.Arn.Data, nil } -func (a *mqlAwsS3Bucket) policy() (*mqlAwsS3BucketPolicy, error) { - bucketname := a.Name.Data - - location := a.Location.Data +func emptyAwsS3BucketPolicy(runtime *plugin.Runtime) (*mqlAwsS3BucketPolicy, error) { + res, err := CreateResource(runtime, "aws.s3.bucket.policy", map[string]*llx.RawData{ + "name": llx.StringData(""), + "document": llx.StringData("{}"), + "version": llx.StringData(""), + "id": llx.StringData(""), + "statements": llx.ArrayData([]interface{}{}, types.Dict), + }) + if err != nil { + return nil, err + } + return res.(*mqlAwsS3BucketPolicy), nil +} +func (a *mqlAwsS3Bucket) policy() (*mqlAwsS3BucketPolicy, error) { conn := a.MqlRuntime.Connection.(*connection.AwsConnection) + bucketname := a.Name.Data + location := a.Location.Data svc := conn.S3(location) ctx := context.Background() @@ -179,9 +191,9 @@ func (a *mqlAwsS3Bucket) policy() (*mqlAwsS3BucketPolicy, error) { }) if err != nil { if isNotFoundForS3(err) { - return &mqlAwsS3BucketPolicy{}, nil + return emptyAwsS3BucketPolicy(a.MqlRuntime) } - return &mqlAwsS3BucketPolicy{}, err + return nil, err } if policy != nil && policy.Policy != nil { @@ -198,7 +210,7 @@ func (a *mqlAwsS3Bucket) policy() (*mqlAwsS3BucketPolicy, error) { } // no bucket policy found, return nil for the policy - return &mqlAwsS3BucketPolicy{}, nil + return emptyAwsS3BucketPolicy(a.MqlRuntime) } func (a *mqlAwsS3Bucket) tags() (map[string]interface{}, error) { @@ -605,6 +617,8 @@ func (a *mqlAwsS3BucketPolicy) id() (string, error) { if err != nil || policy == nil { return "none", err } + + a.Id = plugin.TValue[string]{Data: policy.Id, State: plugin.StateIsSet} return policy.Id, nil }