Skip to content

Commit

Permalink
🐛 fix empty aws.s3.bucket.policy + 🐛 fix its ID (#2077)
Browse files Browse the repository at this point in the history
The ID needs to be assigned after parsing at the moment. This is
probably better stored in the generate file, but for now the manual
assignment fixes things.

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Oct 4, 2023
1 parent ccbf91c commit 7a657c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 12 additions & 12 deletions providers/aws/resources/aws.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions providers/aws/resources/aws_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 7a657c7

Please sign in to comment.