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

Read data from notifications #171

Merged
merged 7 commits into from Oct 20, 2017
Merged

Read data from notifications #171

merged 7 commits into from Oct 20, 2017

Conversation

@SergeyZhukovsky
Copy link
Member

SergeyZhukovsky commented Oct 12, 2017

Implemented a logic for SNS->SQS notifications.

@SergeyZhukovsky SergeyZhukovsky requested a review from ayumi Oct 12, 2017
Copy link
Contributor

ayumi left a comment

I think this generally looks good.

I noticed there aren't any new tests; do existing tests cover the new code?

I've left style consistency comments inline; these aren't critical but very desirable.

Question for verification testing: What's your preferred testing workflow so I can try it out? Did you run the sync server locally, and with what AWS permissions.

@@ -15,6 +15,9 @@ const EXPIRED_CREDENTIAL_ERRORS = [
/The provided token has expired\./,
/Invalid according to Policy: Policy expired\./
]
const SQS_MAX_LIST_MESSAGES_COUNT = 10

This comment has been minimized.

Copy link
@ayumi

ayumi Oct 16, 2017

Contributor

can you move this into ./config for cleanliness

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky Oct 17, 2017

Author Member

yep sure, but do you think that I should move the upper block there as well?
const PUT_CONCURRENCY = 100
const S3_MAX_RETRIES = 1
const EXPIRED_CREDENTIAL_ERRORS = [
/The provided token has expired./,
/Invalid according to Policy: Policy expired./
]

This comment has been minimized.

Copy link
@ayumi

ayumi Oct 17, 2017

Contributor

I think that is also a good idea

sslEnabled: true
})

return {s3, postData, expiration, bucket, region, SQS, SNS}

This comment has been minimized.

Copy link
@ayumi

ayumi Oct 16, 2017

Contributor

minor: capitalization on SQS vs sqs, in this repo we're using lowercase for instances and SQS for class names / constructors. can you adjust for consistency with s3?

TopicConfigurations: [
{
Events: [
's3:ObjectCreated:Post'

This comment has been minimized.

Copy link
@ayumi

ayumi Oct 16, 2017

Contributor

minor: maybe it's not important now, but in the future maybe we need to subscribe to ObjectDeleted as well (happens when user hits Reset Sync which deletes everything from S3)

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky Oct 17, 2017

Author Member

That subscription is: our s3 bucket is allowed to post notification to SNS topic. Probably it is a good idea to delete the corresponding SNS and SQS in that case. Thanks, I'll do it.

callback(error, null)
} else if (data) {
for (let message of data.Messages) {
var key = ''

This comment has been minimized.

Copy link
@ayumi

ayumi Oct 16, 2017

Contributor

can you use let instead of var?

@@ -95,6 +95,20 @@ class UserAwsCredentialGenerator {
"Effect": "Allow",
"Action": "s3:DeleteObject",
"Resource": "${this.arnS3Prefix()}/*"
},
{

This comment has been minimized.

Copy link
@ayumi

ayumi Oct 16, 2017

Contributor

does this work? i'm curious if the sync server AWS IAM profile needs to be updated to have to permission to do this as well. iirc the child credentials can only authorize a subset of the parent permissions.

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky Oct 17, 2017

Author Member

I haven't checked the Rest Sync, but I see that I haven't implemented the delete of SNS and SQS. I'll fix that tomorrow.

@SergeyZhukovsky
Copy link
Member Author

SergeyZhukovsky commented Oct 17, 2017

Thank you for the review. I see some critical things in my implementation that need to be fixed, especially with a Reset Sync functionality. I'm going to work on that tomorrow.
Everything was ran locally with the default AWS permissions.

@@ -169,11 +199,216 @@ RequestUtil.prototype.list = function (category, startAt, maxRecords) {
}
if (startAt) { options.StartAfter = `${prefix}/${startAt}` }
return this.withRetry(() => {
return s3Helper.listObjects(this.s3, options, !!maxRecords)
if (!startAt || startAt === 0 || ((new Date()).getTime() - startAt) >

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas Oct 17, 2017

Member

minor: startAt === 0 is unnecessary since !0 is true

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky Oct 17, 2017

Author Member

thanks, you are right

@@ -96,13 +96,13 @@ const startSync = (requester) => {
return jsRecords
}

ipc.on(messages.FETCH_SYNC_RECORDS, (e, categoryNames, startAt, limitResponse) => {
ipc.on(messages.FETCH_SYNC_RECORDS, (e, categoryNames, startAt, limitResponse, platform) => {

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas Oct 17, 2017

Member

please document the platform parameter in client/constants/messages.js

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas Oct 17, 2017

Member

on second thought, is this necessary at all? at least on laptop, the background page should be able to get the platform via window.navigator.userAgent

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky Oct 17, 2017

Author Member

it could be ignored on laptop. I added it to manage notifications like history or preferences records on mobile. We don't sync them for now there, but if I don't poll and delete them Amazon could keep returning me them again and again. It is just a temporary till we have those records sync on mobile as well.

@ayumi
Copy link
Contributor

ayumi commented Oct 17, 2017

I think this would be okay to test on staging. I'm 90% sure old clients who don't support SQS+SNS will continue to work.
However I'm only 50% sure that new clients with SQS+SNS will work. We may need to update the server's IAM AWS policy to support SQS+SNS permission grants – let me know and I can help with this.

@SergeyZhukovsky
Copy link
Member Author

SergeyZhukovsky commented Oct 17, 2017

I think I configured everything on staging, I'll ping you when I finish fixes after the review.

@ayumi
Copy link
Contributor

ayumi commented Oct 18, 2017

@SergeyZhukovsky this looks good for testing on staging.

before merging to master i think we should make sure tests cover SNS/SQS functionality (set up a queue, upload record, read from queue)

also if there were server IAM permission changes needed, we should write them down in our terraform AWS config

@ayumi ayumi force-pushed the SNS_SQS_notifications branch from 3986830 to a65254b Oct 19, 2017
ayumi added 2 commits Oct 19, 2017
To prevent users from mucking with each others' data
Use namespaced SNS and SQS
@SergeyZhukovsky SergeyZhukovsky merged commit 56a0c37 into staging Oct 20, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.