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

fix(aws-s3-assets): support asset url with two extension name like tar.gz #20874

Merged
merged 18 commits into from
Jul 14, 2022

Conversation

ntachukwu
Copy link
Contributor

@ntachukwu ntachukwu commented Jun 25, 2022

using aws-s3-assets to upload data artifacts of extension tar.gz returns an uploaded asset renamed to <random Id>.gz.

This PR proposes that the AssetStaging Object should be able to check if the uploaded artifact is a tar.gz or any other archive tar file with a compression extension and return the appropriate extension name as stagedPath.

closes #12699

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Jun 25, 2022

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Jun 25, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team June 25, 2022 10:00
} else {
let extensionName: string = path.extname(this.sourcePath);
const sourceName: string = path.basename(this.sourcePath).replace(extensionName, '');
const doubleArchive = ARCHIVE_EXTENSIONS.includes(path.extname(sourceName)) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Array.prototype.includes() already returns true or false. This ternary construction is unnecessary.

const stagedPath = this.stagingDisabled
? this.sourcePath
: path.resolve(this.assetOutdir, renderAssetFilename(assetHash, path.extname(this.sourcePath)));
let stagedPath: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to refactor the implementation without using let and without the code becoming too difficult to read? You want to use const if at all possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could create a method that checks for double extensions and returns an extension string? This will replace path.extname(this.sourcePath)

Copy link
Contributor

@kellertk kellertk left a comment

Choose a reason for hiding this comment

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

Instead of overloading ARCHIVE_EXTENSIONS, would it be possible to genericize the implementation? So you can use any arbitrary number of extensions on a file an they'd all be preserved.

@mergify mergify bot dismissed kellertk’s stale review June 27, 2022 16:14

Pull request has been modified.

@ntachukwu ntachukwu requested a review from kellertk June 27, 2022 16:15
@ntachukwu
Copy link
Contributor Author

Instead of overloading ARCHIVE_EXTENSIONS, would it be possible to genericize the implementation? So you can use any arbitrary number of extensions on a file an they'd all be preserved.

The idea behind overloading ARCHIVE_EXTENSIONS was to prevent invalid extension names as the basename might contain multiple dots e.g /path/to/artifact/artifact.da.vinci.monalisa.tar.gz which could be mistaken for extension names. Is this not something to be concerned about?

@indrora
Copy link
Contributor

indrora commented Jul 8, 2022

Looks great! I would love to see a unit test or two for the new function just to make sure that it handles some common cases. path/to/artifact/artifact.da.vinci.monalisa.tar.gz absolutely deserves a spot in those tests because it's a wonderfully ambiguous one. A file with no extension (for instance Dockerfile and bob) should return something useful... Verify that.

A nitpick: one common extension for compressed tar archives is .tgz and the typical .tar should be in there too for uncompressed tarballs.

@pahud
Copy link
Contributor

pahud commented Jul 13, 2022

LGTM

@ntachukwu ntachukwu changed the title feat(aws-s3-assets): support asset url with two extension name like tar.gz fix(aws-s3-assets): support asset url with two extension name like tar.gz Jul 13, 2022
indrora
indrora previously approved these changes Jul 14, 2022
Copy link
Contributor

@indrora indrora left a comment

Choose a reason for hiding this comment

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

Looks fantastic.

@mergify mergify bot dismissed indrora’s stale review July 14, 2022 17:38

Pull request has been modified.

@indrora indrora removed request for a team and kellertk July 14, 2022 17:39
@mergify
Copy link
Contributor

mergify bot commented Jul 14, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 1ad4e08
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 673b0d1 into aws:main Jul 14, 2022
@mergify
Copy link
Contributor

mergify bot commented Jul 14, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

guessi pushed a commit to guessi/aws-cdk that referenced this pull request Jul 17, 2022
…r.gz (aws#20874)

using aws-s3-assets to upload data artifacts of extension `tar.gz` returns an uploaded asset renamed to `<random Id>.gz`. 

This PR proposes that the AssetStaging Object should be able to check if the uploaded artifact is a `tar.gz` or any other archive tar file with a compression extension and return the appropriate extension name as stagedPath.

closes aws#12699

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-s3-assets): Object keys don't preserve the full extension name
5 participants