Skip to content

Commit

Permalink
Support ohaws role
Browse files Browse the repository at this point in the history
  • Loading branch information
taahamahdi committed Jul 12, 2024
1 parent e8cc1d0 commit 1a1aa69
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
10 changes: 2 additions & 8 deletions docs/tables/aws_iam_roles.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,5 @@ The following tables depend on aws_iam_roles:
|tags|`json`|
|arn|`utf8`|
|oh_resource_type|`utf8`|
|create_date|`timestamp[us, tz=UTC]`|
|path|`utf8`|
|role_id|`utf8`|
|role_name|`utf8`|
|description|`utf8`|
|max_session_duration|`int64`|
|permissions_boundary|`json`|
|role_last_used|`json`|
|role|`json`|
|policies|`json`|
3 changes: 2 additions & 1 deletion resources/services/iam/role_attached_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/OpsHelmInc/cloudquery/client"
"github.com/OpsHelmInc/ohaws"
"github.com/apache/arrow/go/v16/arrow"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/iam/types"
Expand Down Expand Up @@ -31,7 +32,7 @@ func roleAttachedPolicies() *schema.Table {
}

func fetchIamRoleAttachedPolicies(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
p := parent.Item.(*types.Role)
p := parent.Item.(*ohaws.Role)
cl := meta.(*client.Client)
svc := cl.Services(client.AWSServiceIam).Iam
config := iam.ListAttachedRolePoliciesInput{
Expand Down
6 changes: 3 additions & 3 deletions resources/services/iam/role_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/url"

"github.com/OpsHelmInc/cloudquery/client"
"github.com/OpsHelmInc/ohaws"
"github.com/apache/arrow/go/v16/arrow"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/iam/types"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
sdkTypes "github.com/cloudquery/plugin-sdk/v4/types"
Expand Down Expand Up @@ -42,7 +42,7 @@ func rolePolicies() *schema.Table {
func fetchIamRolePolicies(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
cl := meta.(*client.Client)
svc := cl.Services(client.AWSServiceIam).Iam
role := parent.Item.(*types.Role)
role := parent.Item.(*ohaws.Role)
paginator := iam.NewListRolePoliciesPaginator(svc, &iam.ListRolePoliciesInput{
RoleName: role.RoleName,
})
Expand All @@ -65,7 +65,7 @@ func getRolePolicy(ctx context.Context, meta schema.ClientMeta, resource *schema
cl := meta.(*client.Client)
svc := cl.Services(client.AWSServiceIam).Iam
p := resource.Item.(string)
role := resource.Parent.Item.(*types.Role)
role := resource.Parent.Item.(*ohaws.Role)

policyResult, err := svc.GetRolePolicy(ctx, &iam.GetRolePolicyInput{PolicyName: &p, RoleName: role.RoleName}, func(options *iam.Options) {
options.Region = cl.Region
Expand Down
8 changes: 4 additions & 4 deletions resources/services/iam/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/url"

"github.com/OpsHelmInc/cloudquery/client"
"github.com/OpsHelmInc/ohaws"
"github.com/apache/arrow/go/v16/arrow"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/iam/types"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
sdkTypes "github.com/cloudquery/plugin-sdk/v4/types"
Expand All @@ -21,7 +21,7 @@ func Roles() *schema.Table {
Description: `https://docs.aws.amazon.com/IAM/latest/APIReference/API_Role.html`,
Resolver: fetchIamRoles,
PreResourceResolver: getRole,
Transform: transformers.TransformWithStruct(&types.Role{}),
Transform: transformers.TransformWithStruct(&ohaws.Role{}),
Multiplex: client.ServiceAccountRegionMultiplexer(tableName, "iam"),
Columns: []schema.Column{
client.DefaultAccountIDColumn(true),
Expand Down Expand Up @@ -69,7 +69,7 @@ func fetchIamRoles(ctx context.Context, meta schema.ClientMeta, parent *schema.R
}

func getRole(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource) error {
role := resource.Item.(types.Role)
role := resource.Item.(ohaws.Role)
cl := meta.(*client.Client)
svc := cl.Services(client.AWSServiceIam).Iam
roleDetails, err := svc.GetRole(ctx, &iam.GetRoleInput{
Expand All @@ -85,7 +85,7 @@ func getRole(ctx context.Context, meta schema.ClientMeta, resource *schema.Resou
}

func resolveRolesAssumeRolePolicyDocument(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
r := resource.Item.(*types.Role)
r := resource.Item.(*ohaws.Role)
if r.AssumeRolePolicyDocument == nil {
return nil
}
Expand Down

0 comments on commit 1a1aa69

Please sign in to comment.