Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic mechanism to call Go func to calculate display ID #197

Merged
merged 4 commits into from
Jul 22, 2022

Conversation

rabbitfang
Copy link
Collaborator

@rabbitfang rabbitfang commented Jul 10, 2022

  • Adds a generic "transformer" concept, which is a mechanism to mutate resources after they are created with the ResourceConverter. Transformers are applied in order, can optionally also receive the original SDK resource, and receive a pointer to the model.Resource, which they are permitted to mutate as desired.
  • While the initial target use case for transformers is to support display IDs, the ultimate goal is for a generic mechanism that makes it easy to extend and customize behavior for building a complete model.Resource, with a future look towards console URLs, inter-resource links, and common ID formats.
  • Updates tag functions to flow through the transformer mechanism. This change was made to reduce the complexity in the resourceconverter.SendAllConverted* functions (which will later be reduced to a single function), and because the "get tags" functions are very close to the transformer paradigm.
  • The sqs.Queue (manual implementation) and lambda.Function (code generated) resources were updated to use the new transformer mechanism to demonstrate the utility. A later PR will update many other resources to improve their display IDs.
  • Previously, awsgen only needed to know the type returned by the AWS SDK's list API call if we were also making a call to a separate "get tags" API. With this change, however, we now need to know it anytime a transformer is used (including tag functions), which in the future, will probably be every time. In most cases the SDK type is the same as type name we use in cloudgrep, but occasionally it's not; therefore, we infer the SDK type automatically based on the resource type, but this can be overridden with the listApi.sdkType field in the awsgen config.

@rabbitfang rabbitfang requested review from a team and eljevakovic as code owners July 10, 2022 09:27
@codecov
Copy link

codecov bot commented Jul 10, 2022

Codecov Report

Merging #197 (c72c0b9) into main (c99041c) will increase coverage by 0.27%.
The diff coverage is 69.96%.

@@            Coverage Diff             @@
##             main     #197      +/-   ##
==========================================
+ Coverage   73.66%   73.94%   +0.27%     
==========================================
  Files         104      108       +4     
  Lines        5498     5722     +224     
==========================================
+ Hits         4050     4231     +181     
- Misses       1179     1219      +40     
- Partials      269      272       +3     
Impacted Files Coverage Δ
hack/awsgen/config/validate_tag_api.go 89.47% <ø> (-1.44%) ⬇️
pkg/resourceconverter/transformer.go 0.00% <0.00%> (ø)
pkg/resourceconverter/util.go 38.00% <0.00%> (+7.84%) ⬆️
pkg/provider/aws/zz_iam.go 64.40% <50.00%> (+0.50%) ⬆️
pkg/provider/aws/util.go 64.00% <64.00%> (ø)
pkg/provider/aws/zz_elasticache.go 80.43% <66.66%> (+0.88%) ⬆️
pkg/provider/aws/zz_elb.go 81.63% <66.66%> (+0.78%) ⬆️
pkg/provider/aws/zz_route53.go 77.35% <66.66%> (+0.88%) ⬆️
pkg/provider/aws/zz_sns.go 80.43% <66.66%> (+0.88%) ⬆️
pkg/provider/aws/cloudfront.go 79.06% <75.00%> (+1.56%) ⬆️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c99041c...c72c0b9. Read the comment docs.

@rabbitfang rabbitfang force-pushed the feature/display-id-transformers branch from 0efeab9 to c72c0b9 Compare July 22, 2022 17:45
@rabbitfang rabbitfang merged commit a5aec16 into main Jul 22, 2022
@rabbitfang rabbitfang deleted the feature/display-id-transformers branch July 22, 2022 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant