Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Issue #134 - FN::GetAtt can return an array #139

Merged
merged 7 commits into from
Apr 25, 2018
Merged

Issue #134 - FN::GetAtt can return an array #139

merged 7 commits into from
Apr 25, 2018

Conversation

tomdionysus
Copy link
Contributor

First off, my TypeScript isn't that good, corrections welcome. This works but as always I invite discussion/critique.

  • Implemented getResourceTypeAttribute in resourcesSpec.ts that gets the named attribute on the specified resource type, or throws NoSuchResourceTypeAttribute if not found.
  • Renamed ItemType on PrimitiveAttribute to PrimitiveType
  • Modified fnGetAtt to get the Attribute using getResourceTypeAttribute and return a List of mocks if specified.
  • Wrote tests for getResourceTypeAttribute
  • Added extra JSON/YAML fixtures and tests for fnGetAtt

Copy link
Owner

@martysweet martysweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thanks! Just a few bits

expect(result['errors']['warn']).to.have.lengthOf(0);
});

it("should not pass validation where Fn::GetAtt returns a list", () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the JSON versions, they look like they are testing the same stuff as the YAML?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - I had assumed that the processing for Fn::GetAtt and !GetAtt might be different, and included tests for both. Happy to strip them out.

src/validator.ts Outdated
return `mockAttr_${reference}_${attributeName}`;
} else {
// Lookup attribute
const attribute = resourcesSpec.getResourceTypeAttribute(resource['Type'], attributeName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to catch the exception and throw it back to the user as a Critical error...

Also need a test case for this type of behaviour, for example requesting "!GetAtt DNSVPCDomain.VeryLostNameServers"

should result in:
Resource: Resources > .....
Message: Required property ...
Documentation: ...
Template invalid!

Such examples are

addError('crit', `Fn::If does not allow ${keys[0]} as a nested function within an array`, placeInTemplate, 'Fn::If');

Probably: Fn::GetAtt cannot find property AAAA on resource AAAA of type AAAA, placeInTemplate, DestinationType?? (if possible), otherwise fn::getatt

The last parameter decides which documentation to serve to the user.

There might be some better ones within the validator

@tomdionysus
Copy link
Contributor Author

tomdionysus commented Apr 20, 2018

Ok - give that a go. I'm unsure if you really want exception processing in that function, but it does work.

For the returned documentation, I'd thought what would be most useful - the type on which the attribute cannot be found.

@martysweet
Copy link
Owner

Agreed about the exception processing, it doesn't really go with the style of the rest of the program. However, the end result is what we expect.

Maybe having a doesResourceTypeAttributeExist() would be more appropriate/same style until a considerable refactor? Then if false run the addError().

Happy with resource type, looks good!

@martysweet martysweet added this to the v1.6.1 milestone Apr 22, 2018
@tomdionysus
Copy link
Contributor Author

Is it enough of a wart to fix right now? I'd be happy to help with the refactor as and when - my own CoffeeCloud (https://github.com/blackravenltd/CoffeeCloud) project is hitched to the cfn-lint wagon, I've customers using both who are very happy apart from the 'just ignore this error, the cfn-lint team are on it'.

Copy link
Owner

@martysweet martysweet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, ignore me, I seem to have forgotten that during the transition to TypeScript some things were managed by Exception handling.

I'm happy with this, just one comment about !! 😀

Thanks!

// Lookup attribute
const attribute = resourcesSpec.getResourceTypeAttribute(resource['Type'], attributeName)
const primitiveAttribute = attribute as PrimitiveAttribute
if(!!primitiveAttribute['PrimitiveType']) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the !! intentional?

Copy link
Contributor Author

@tomdionysus tomdionysus Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's my oldskool JS showing itself... 'double-not' coerces to boolean (i.e. true if not falsy). The intent here is to test for the existence of the property and make sure it has a value - I could have used hasOwnProperty (or instanceof) come to think of it, unless there is an idiomatic TypeScript way to do it...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@martysweet
Copy link
Owner

Looks like the build is failing due to a new npm version, will merge this and push a new release when resolved 😀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants