Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
candiduslynx committed Nov 10, 2022
1 parent 291829f commit 6d26d32
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
20 changes: 20 additions & 0 deletions plugins/source/aws/codegen/recipes/base.go
Expand Up @@ -36,6 +36,9 @@ type Resource struct {
Relations []string
UnwrapEmbeddedStructs bool

// NameTransformer custom name transformer for resource
NameTransformer func(field reflect.StructField) (string, error)

// Used for generating the resolver and mock tests.
// --------------------------------
ShouldGenerateResolverAndMockTest bool
Expand Down Expand Up @@ -136,6 +139,9 @@ func (r *Resource) Generate() error {
if r.UnwrapEmbeddedStructs {
opts = append(opts, codegen.WithUnwrapAllEmbeddedStructs())
}
if r.NameTransformer != nil {
opts = append(opts, codegen.WithNameTransformer(r.NameTransformer))
}
name := fmt.Sprintf("aws_%s_%s", r.Service, r.SubService)
if r.Name != "" {
name = r.Name
Expand Down Expand Up @@ -288,3 +294,17 @@ func (r Resource) CloudQueryServiceName() string {
csr := caser.New()
return csr.ToPascal(r.Service)
}

// CreateReplaceTransformer allows overriding column names
func CreateReplaceTransformer(replace map[string]string) func(field reflect.StructField) (string, error) {
return func(field reflect.StructField) (string, error) {
name, err := codegen.DefaultNameTransformer(field)
if err != nil {
return "", err
}
for k, v := range replace {
name = strings.ReplaceAll(name, k, v)
}
return name, nil
}
}
6 changes: 4 additions & 2 deletions plugins/source/aws/codegen/recipes/ram.go
Expand Up @@ -29,12 +29,13 @@ func RAMResources() []*Resource {
SubService: "resource_shares",
Struct: new(types.ResourceShare),
Multiplex: mx,
PKColumns: []string{"resource_share_arn"},
PKColumns: []string{"arn"},
ExtraColumns: defaultRegionalColumns,
Relations: []string{
"ResourceShareAssociatedPrincipals()",
"ResourceShareAssociatedResources()",
},
NameTransformer: CreateReplaceTransformer(map[string]string{"resource_share_arn": "arn"}),
},
{
SubService: "resource_share_associated_principals",
Expand All @@ -54,9 +55,10 @@ func RAMResources() []*Resource {
SubService: "resource_share_invitations",
Struct: new(types.ResourceShareInvitation),
Multiplex: mx,
PKColumns: []string{"resource_share_invitation_arn"},
PKColumns: []string{"arn"},
ExtraColumns: defaultRegionalColumns,
ResolverAndMockTestTemplate: "get_resources_paginated_1",
NameTransformer: CreateReplaceTransformer(map[string]string{"resource_share_invitation_arn": "arn"}),
},
{
SubService: "resource_share_permissions",
Expand Down
Expand Up @@ -2,7 +2,7 @@

https://docs.aws.amazon.com/ram/latest/APIReference/API_ResourceShareInvitation.html

The primary key for this table is **resource_share_invitation_arn**.
The primary key for this table is **arn**.


## Columns
Expand All @@ -19,7 +19,7 @@ The primary key for this table is **resource_share_invitation_arn**.
|receiver_arn|String|
|resource_share_arn|String|
|resource_share_associations|JSON|
|resource_share_invitation_arn (PK)|String|
|arn (PK)|String|
|resource_share_name|String|
|sender_account_id|String|
|status|String|
4 changes: 2 additions & 2 deletions plugins/source/aws/docs/tables/aws_ram_resource_shares.md
Expand Up @@ -2,7 +2,7 @@

https://docs.aws.amazon.com/ram/latest/APIReference/API_ResourceShare.html

The primary key for this table is **resource_share_arn**.
The primary key for this table is **arn**.

## Relations
The following tables depend on aws_ram_resource_shares:
Expand All @@ -24,7 +24,7 @@ The following tables depend on aws_ram_resource_shares:
|last_updated_time|Timestamp|
|name|String|
|owning_account_id|String|
|resource_share_arn (PK)|String|
|arn (PK)|String|
|status|String|
|status_message|String|
|tags|JSON|

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

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

0 comments on commit 6d26d32

Please sign in to comment.