Skip to content

Commit

Permalink
feat: Add policy column to aws_efs_filesystems table (#14672)
Browse files Browse the repository at this point in the history

#### Summary

resolves #14632

I'm looking for a way to reduce the duplicate implementations, for example, the following part is a way to get a service to resolve data for the table. It works well when a table relays on a single resolver. But if a table needs multiple resolver then might be a good way to do it. 

```go
	p := resource.Item.(types.FileSystemDescription)
	config := efs.DescribeFileSystemPolicyInput{
		FileSystemId: p.FileSystemId,
	}
	cl := meta.(*client.Client)
	svc := cl.Services(client.AWSServiceEfs).Efs
```

<!--
Explain what problem this PR addresses
-->
  • Loading branch information
cychiang committed Oct 20, 2023
1 parent f136331 commit 833b9c2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
32 changes: 30 additions & 2 deletions plugins/source/aws/resources/services/efs/filesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ func Filesystems() *schema.Table {
{
Name: "backup_policy_status",
Type: arrow.BinaryTypes.String,
Resolver: ResolveEfsFilesystemBackupPolicyStatus,
Resolver: resolveEfsFilesystemBackupPolicyStatus,
},
{
Name: "file_system_policy",
Type: arrow.BinaryTypes.String,
Resolver: resolveEfsFilesystemPolicy,
},
{
Name: "tags",
Expand Down Expand Up @@ -60,7 +65,7 @@ func fetchEfsFilesystems(ctx context.Context, meta schema.ClientMeta, parent *sc
return nil
}

func ResolveEfsFilesystemBackupPolicyStatus(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
func resolveEfsFilesystemBackupPolicyStatus(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
p := resource.Item.(types.FileSystemDescription)
config := efs.DescribeBackupPolicyInput{
FileSystemId: p.FileSystemId,
Expand All @@ -82,3 +87,26 @@ func ResolveEfsFilesystemBackupPolicyStatus(ctx context.Context, meta schema.Cli

return resource.Set(c.Name, response.BackupPolicy.Status)
}

func resolveEfsFilesystemPolicy(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
p := resource.Item.(types.FileSystemDescription)
config := efs.DescribeFileSystemPolicyInput{
FileSystemId: p.FileSystemId,
}
cl := meta.(*client.Client)
svc := cl.Services(client.AWSServiceEfs).Efs
response, err := svc.DescribeFileSystemPolicy(ctx, &config, func(options *efs.Options) {
options.Region = cl.Region
})
if err != nil {
if cl.IsNotFoundError(err) {
return nil
}
return err
}
if response.Policy == nil {
return nil
}

return resource.Set(c.Name, response.Policy)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func buildEfsFilesystemsMock(t *testing.T, ctrl *gomock.Controller) client.Servi
m.EXPECT().DescribeBackupPolicy(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&b, nil)

p := efs.DescribeFileSystemPolicyOutput{}
require.NoError(t, faker.FakeObject(&p))
m.EXPECT().DescribeFileSystemPolicy(gomock.Any(), gomock.Any(), gomock.Any()).Return(
&p, nil)

return client.Services{
Efs: m,
}
Expand Down
1 change: 1 addition & 0 deletions website/tables/aws/aws_efs_filesystems.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The primary key for this table is **arn**.
|region|`utf8`|
|arn (PK)|`utf8`|
|backup_policy_status|`utf8`|
|file_system_policy|`utf8`|
|tags|`json`|
|creation_time|`timestamp[us, tz=UTC]`|
|creation_token|`utf8`|
Expand Down

0 comments on commit 833b9c2

Please sign in to comment.