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

custom-resources: can't flatten response containing null property value #5061

Closed
pahud opened this issue Nov 16, 2019 · 0 comments · Fixed by #5073
Closed

custom-resources: can't flatten response containing null property value #5061

pahud opened this issue Nov 16, 2019 · 0 comments · Fixed by #5073
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@pahud
Copy link
Contributor

pahud commented Nov 16, 2019

This function will fail if the response property contains the null value.

function flatten(object: object): { [key: string]: string } {
return Object.assign(
{},
...function _flatten(child: any, path: string[] = []): any {
return [].concat(...Object.keys(child)
.map(key =>
typeof child[key] === 'object'
? _flatten(child[key], path.concat([key]))
: ({ [path.concat([key]).join('.')]: child[key] })
));
}(object)
);
}

Reproduction Steps

const clusterInfo = new cr.AwsCustomResource(stack, 'clusterInfo', {
  onUpdate: {
    service: 'EKS',
    action: 'describeCluster',
    region,
    parameters: {
      name: cluster.clusterName,
    },
    physicalResourceId: cluster.clusterName,
  },
})

Will get response like this

 { name: 'cluster-a5bc1663-3159-4112-9c28-e8c84e730606',
     arn:
      'arn:aws:eks:ap-northeast-1:903779448426:cluster/cluster-a5bc1663-3159-4112-9c28-e8c84e730606',
     createdAt: 2019-11-15T01:28:24.825Z,
     version: '1.14',
     endpoint: '...',
     roleArn: '...',
     resourcesVpcConfig:
      { subnetIds: [Array],
        securityGroupIds: [Array],
        vpcId: 'vpc-497a492d',
        endpointPublicAccess: true,
        endpointPrivateAccess: false },
     logging: { clusterLogging: [Array] },
     status: 'ACTIVE',
     certificateAuthority:
      { data: '...' },
     clientRequestToken: null,
     platformVersion: 'eks.2' } }

And the clientRequestToken would be null, which breaks the flatten() function.

A simple additional check like this can fix this issue but I'm not sure if it's a good way to fix it.

function flatten(object) {
    return Object.assign({}, ...function _flatten(child, path = []) {
        return [].concat(...Object.keys(child)
            .map(key => typeof child[key] === 'object' && child[key] != null
            ? _flatten(child[key], path.concat([key]))
            : ({ [path.concat([key]).join('.')]: child[key] })));
    }(object));
}

Error Log

Environment

  • CLI Version :
  • Framework Version:
  • OS :
  • Language :

Other


This is 🐛 Bug Report

@pahud pahud added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 16, 2019
jogold added a commit to jogold/aws-cdk that referenced this issue Nov 18, 2019
jogold added a commit to jogold/aws-cdk that referenced this issue Nov 18, 2019
@mergify mergify bot closed this as completed in #5073 Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant