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

Fixes fs.js s3 read/write issues introduced by switching clients #282

Merged
merged 5 commits into from
Feb 23, 2023

Conversation

DavidSeptimus-Klotho
Copy link
Contributor

Resolves #280

  • Stripped leading slashes in object paths supplied to fs functions to be more consistent with expected fs behavior (as well as the older s3fs-based implementation).
  • Changed s3_readFile() to return a Promise by default and only returns a string if the user specifies an encoding. Additionally, an empty body results in a Promise rather than an empty string.

Standard checks

  • Unit tests: Any special considerations? No
  • Docs: Do we need to update any docs, internal or public? No
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working? Slim chance. Potentially breaks apps built with v0.6.1 that using Cloud FS for JavaScript that intend to use / as an actual s3 object prefix or that expect fs.readFile() to always return a string.

- Stripped leading slashes in object paths supplied to fs functions to be more consistent with expected fs behavior (as well as the older s3fs-based implementation)
- Changed s3_readFile() to return a Promise<Buffer> by default and only returns a string if the user specifies an encoding. Additionally, an empty body results in a Promise<Void> rather than an empty string.
Comment on lines 100 to 106
return new Promise((resolve, reject) => {
const stream = data.Body;
const chunks = [];
stream.on('data', chunk => chunks.push(chunk))
stream.once('end', () => resolve(Buffer.concat(chunks)))
stream.once('error', reject)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: make this reusable? Looks similar to steamToString as well but maybe nothing to pull out between the 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simple enough. I hadn't even looked at the content of streamToString.

@DavidSeptimus-Klotho DavidSeptimus-Klotho temporarily deployed to integ_test February 23, 2023 01:21 — with GitHub Actions Inactive
@DavidSeptimus-Klotho DavidSeptimus-Klotho temporarily deployed to integ_test February 23, 2023 01:21 — with GitHub Actions Inactive
Copy link
Contributor

@gordon-klotho gordon-klotho left a comment

Choose a reason for hiding this comment

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

All good except the backwards compat question

@@ -123,7 +127,7 @@ async function s3_readFile(...args) {
async function s3_readdir(path) {
const bucketParams: ListObjectsCommandInput = {
Bucket: bucketName,
Prefix: `${path}`,
Prefix: stripLeadingSlashes(`${path}`),
Copy link
Contributor

Choose a reason for hiding this comment

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

Did this really used to be the behaviour? If so, we broke backwards compat, then we'll be breaking backwards compat again to return it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual behavior was actually quite a bit more complex as seen here:
https://github.com/hasnat/s3fs/blob/master/lib/utils.js

The key bit is that all the keys were normalized across host operating systems to match a specific format. Removing that from our FS breaks the expectation that you can use the Cloud FS the same as your local FS.

@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 3%
github.com/klothoplatform/klotho/pkg/annotation 23%
github.com/klothoplatform/klotho/pkg/cli 4%
github.com/klothoplatform/klotho/pkg/core 21%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 54%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 59%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 39%
github.com/klothoplatform/klotho/pkg/input 72%
github.com/klothoplatform/klotho/pkg/lang 38%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 36%
github.com/klothoplatform/klotho/pkg/lang/javascript 48%
github.com/klothoplatform/klotho/pkg/lang/python 63%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 23%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 49%
github.com/klothoplatform/klotho/pkg/provider/aws/resources 70%
github.com/klothoplatform/klotho/pkg/runtime 78%
github.com/klothoplatform/klotho/pkg/static_unit 33%
github.com/klothoplatform/klotho/pkg/updater 30%
github.com/klothoplatform/klotho/pkg/validation 74%
github.com/klothoplatform/klotho/pkg/yaml_util 79%
Summary 43% (4252 / 9945)

@DavidSeptimus-Klotho DavidSeptimus-Klotho merged commit 5861153 into main Feb 23, 2023
@DavidSeptimus-Klotho DavidSeptimus-Klotho deleted the bugfix/js-cloud-fs branch February 23, 2023 18:42
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.

Regression: CloudFS Reads File Contents as a String
3 participants