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

update file upload api #132

Merged
merged 20 commits into from
Jan 27, 2021
Merged

update file upload api #132

merged 20 commits into from
Jan 27, 2021

Conversation

dcmcand
Copy link

@dcmcand dcmcand commented Jan 26, 2021

Description of change
Update file upload api in response to comments on HHS#267

Issue(s)

@dcmcand dcmcand requested a review from rahearn January 26, 2021 21:32
Copy link

@rahearn rahearn left a comment

Choose a reason for hiding this comment

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

Cleanup is all awesome, but I think the VCAP_SERVICES part needs a little more work.

let s3Config;

if (process.env.VCAP_SERVICES) {
const bucket = process.env.VCAP_SERVICES.s3[0];
Copy link

Choose a reason for hiding this comment

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

VCAP_SERVICES is a json string in the environment. I know in ruby you need to call JSON.parse(ENV["VCAP_SERVICES"]) to get the values out. Does node handle that transparently?

s3Config = {
accessKeyId: bucket.access_key_id,
endpoint: bucket.uri,
secretAccessKey: bucket.secret_access_key,
Copy link

Choose a reason for hiding this comment

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

I think these paths won't quite be correct. See the example data I DM'd you in slack. There's a credentials object that they're held in inside of what you've assigned to bucket

s3ForcePathStyle: true,
};
}
export const s3 = new S3(s3Config);

export const verifyVersioning = async (bucket = process.env.bucket, s3Client = s3) => {
Copy link

Choose a reason for hiding this comment

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

Setting bucket name should also come from VCAP_SERVICES in deployed environments. Looks like there's two points the bucket name is set, and right now they're being set to different env vars. process.env.bucket here and process.env.S3_BUCKET on line 47

@dcmcand dcmcand requested a review from rahearn January 27, 2021 16:03
let bucketName = process.env.S3_BUCKET;
if (process.env.VCAP_SERVICES) {
const { credentials, name } = process.env.VCAP_SERVICES.s3[0];
bucketName = name;
Copy link

Choose a reason for hiding this comment

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

name here is the cloud.gov service name. We want to set bucketName = credentials.bucket

secretAccessKey: credentials.secret_access_key,
signatureVersion: 'v4',
s3ForcePathStyle: true,
};
Copy link
Author

Choose a reason for hiding this comment

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

I tested all these paths with the sample data you sent and they all work now.

@dcmcand dcmcand requested a review from rahearn January 27, 2021 16:05
dcmcand and others added 3 commits January 27, 2021 16:10
Copy link

@rahearn rahearn left a comment

Choose a reason for hiding this comment

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

🎉

@dcmcand dcmcand merged commit 3cff2f4 into main Jan 27, 2021
@dcmcand dcmcand deleted the cm-pr-267-add-file-upload-api branch January 27, 2021 16:39
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.

3 participants