diff --git a/README.md b/README.md index 9db790dd..bf0f863e 100644 --- a/README.md +++ b/README.md @@ -74,49 +74,7 @@ Try(mapper.readValue[List[SavedArticle]](json)) match { *NB: I found that when a user record has 350+ articles the resultant string in too long for idea to handle. -## Running apps locally - -### Pre-requisites - -- Mobile credentials from [Janus](https://janus.gutools.co.uk/login) -- Install [AWS Sam](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) -- Install [Docker](https://docs.docker.com/engine/install/) -- Make sure you run the app with Java 11 - -### Mobile Save For Later - -Build a jar of the project by running: -- `sbt "project mobile-save-for-later" riffRaffPackageType` - Navigate to the project -- `cd mobile-save-for-later` - -Run the lambda service -- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local start-lambda --debug` - -Execute a function locally -- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local invoke` - -Execute a function using AWS cli -- `aws lambda invoke --function-name "mobilesaveforlaterFETCHcdkCODE" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt --profile mobile --region eu-west-1` - -### Mobile Save For Later User Deletion - -Build a jar of the project by running: -- `sbt "project mobile-save-for-later-user-deletion" riffRaffPackageType` - Navigate to the project -- `cd mobile-save-for-later-user-deletion` - -Run the lambda service -- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local start-lambda --debug` - -Execute a function locally -- `DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local invoke` - -Execute a function using AWS cli -- `aws lambda invoke --function-name "mobilesaveforlateruserdeletionCODE" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt --profile mobile --region eu-west-1` - - -## Testing the Apps on CODE +## Testing the Apps on CODE and running Locally [Save For Later App](docs/testing/save-for-later.md) diff --git a/docs/testing/save-for-later.md b/docs/testing/save-for-later.md index b4dbc386..deb31a0e 100644 --- a/docs/testing/save-for-later.md +++ b/docs/testing/save-for-later.md @@ -1,4 +1,4 @@ -### Pre-requisites +### Setting Up Oauth Flow 1) Download [Postman](https://www.postman.com/downloads/) 2) Set up acquiring an OKTA Auth token following these [instructions](https://github.com/guardian/identity/blob/a19ac17655fd715f15e8d0912b39173c199a8439/docs/postman/README.md) @@ -32,4 +32,17 @@ 2) Under the `Authorization` tab, on the type dropdown select `Bearer Token` and paste in the token generated from the Okta auth ![Authorization](../images/Authorization.png) 3) Under the `Headers` tab add `x-gu-is-oauth: true` - ![Headers](../images/GetHeaders.png) \ No newline at end of file + ![Headers](../images/GetHeaders.png) + + +## Testing locally +### Pre-requisites +1) Mobile credentials from [Janus](https://janus.gutools.co.uk/login) +2) Follow the authentication flow as outlined at the [top](#setting-up-oauth-flow) + +* Go to `src/main/scala/com/gu/sfl/local/LocalServer.scala` +* Select the drop down menu to the left of the run button and select `LocalServer` under run configurations +* Then choose `Edit Configurations` +* Add the following environment variables: + `App=mobile-save-for-later;IdentityApiHost=https://id.code.dev-guardianapis.com;IdentityOktaAudience=https://profile.code.dev-theguardian.com/;IdentityOktaIssuerUrl=https://profile.code.dev-theguardian.com/oauth2/aus3v9gla95Toj0EE0x7;Stage=CODE;SavedArticleLimit=100` +* Follow the same steps as above for testing the GET and POST endpoints by changing the host to `http://127.0.0.1:8080` \ No newline at end of file diff --git a/docs/testing/user-deletion.md b/docs/testing/user-deletion.md index 96375531..92d21893 100644 --- a/docs/testing/user-deletion.md +++ b/docs/testing/user-deletion.md @@ -15,7 +15,7 @@ { "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78", "receiptHandle": "MessageReceiptHandle", - "body": "{\"Message\": { \"userId\": \"1\"}}", + "body": "{\"Message\": \"{\\\"userId\\\":\\\"200126633\\\",\\\"eventType\\\":\\\"DELETE\\\"}\"}", "attributes": { "ApproximateReceiveCount": "1", "SentTimestamp": "1523232000000", @@ -30,4 +30,17 @@ } ] } -``` \ No newline at end of file +``` + +## Testing locally + +### Pre-requisites +1) Mobile credentials from [Janus](https://janus.gutools.co.uk/login) + +* Go to `src/main/scala/local/RunUserDeletionLambda.scala` +* Select the drop down menu to the left of the run button and select `RunUserDeletionLambda` under run configurations +* Then choose `Edit Configurations` +* Add the following environment variables: +* `SaveForLaterApp=mobile-save-for-later;Stage=CODE` +* Modify the event json at `src/main/resources/delete-event.json` to have the user id you want +* Hit the green run button \ No newline at end of file diff --git a/mobile-save-for-later-user-deletion/template.yml b/mobile-save-for-later-user-deletion/template.yml deleted file mode 100644 index f52d0601..00000000 --- a/mobile-save-for-later-user-deletion/template.yml +++ /dev/null @@ -1,84 +0,0 @@ -# This AWS SAM template has been generated from your function's configuration. If -# your function has one or more triggers, note that the AWS resources associated -# with these triggers aren't fully specified in this template and include -# placeholder values. Open this template in AWS Application Composer or your -# favorite IDE and modify it to specify a serverless application with other AWS -# resources. -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: An AWS Serverless Application Model template describing your function. -Resources: - mobilesaveforlateruserdeletionCODE: - Type: AWS::Serverless::Function - Properties: - CodeUri: 'target/scala-2.12/mobile-save-for-later-user-deletion.jar' - Description: Lamba that deletes saved for later data for deleted users - MemorySize: 384 - Timeout: 300 - Handler: com.gu.sfl.userdeletion.UserDeletionLambda::handler - Runtime: java11 - Architectures: - - x86_64 - EphemeralStorage: - Size: 512 - Environment: - Variables: - App: mobile-save-for-later-user-deletion - SaveForLaterApp: mobile-save-for-later - Stack: mobile - Stage: CODE - EventInvokeConfig: - MaximumEventAgeInSeconds: 21600 - MaximumRetryAttempts: 2 - PackageType: Zip - Policies: - - Statement: - - Action: - - dynamodb:* - Resource: - - >- - arn:aws:dynamodb:eu-west-1:201359054765:table/mobile-save-for-later-CODE-articles - Effect: Allow - - Action: - - lamda:InvokeFunction - Resource: - - >- - arn:aws:lambda:eu-west-1:201359054765:function:mobile-save-for-later-user-deletion-CODE - Effect: Allow - - Action: - - logs:CreateLogGroup - - logs:CreateLogStream - - logs:PutLogEvents - Resource: '*' - Effect: Allow - - Action: - - sqs:ReceiveMessage - - sqs:DeleteMessage - - sqs:GetQueueAttributes - Resource: - - arn:aws:sqs:eu-west-1:201359054765:UserIdDeleteQueue-CODE - Effect: Allow - SnapStart: - ApplyOn: None - Tags: - App: mobile-save-for-later-user-deletion - Stack: mobile - Stage: CODE - gu:build-tool: guardian/actions-riff-raff - gu:repo: guardian/mobile-save-for-later - Events: - SQS1: - Type: SQS - Properties: - Queue: - Fn::GetAtt: - - SQSQueue1 - - Arn - BatchSize: 5 - RuntimeManagementConfig: - UpdateRuntimeOn: Auto - SQSQueue1: - Type: AWS::SQS::Queue - Properties: - QueueName: SQSQueue1 - SqsManagedSseEnabled: true diff --git a/mobile-save-for-later/template.yml b/mobile-save-for-later/template.yml deleted file mode 100644 index 5e0f7c92..00000000 --- a/mobile-save-for-later/template.yml +++ /dev/null @@ -1,97 +0,0 @@ -# This AWS SAM template has been generated from your function's configuration. If -# your function has one or more triggers, note that the AWS resources associated -# with these triggers aren't fully specified in this template and include -# placeholder values. Open this template in AWS Application Composer or your -# favorite IDE and modify it to specify a serverless application with other AWS -# resources. -AWSTemplateFormatVersion: '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: An AWS Serverless Application Model template describing your function. -Resources: - mobilesaveforlaterFETCHcdkCODE: - Type: AWS::Serverless::Function - Properties: - CodeUri: 'target/scala-2.12/mobile-save-for-later.jar' - Description: '' - MemorySize: 1024 - Timeout: 20 - Handler: com.gu.sfl.lambda.FetchArticlesLambda::handleRequest - Runtime: java11 - Architectures: - - x86_64 - EphemeralStorage: - Size: 512 - Environment: - Variables: - App: mobile-save-for-later - APP: mobile-save-for-later - IdentityApiHost: https://id.code.dev-guardianapis.com - STACK: mobile - Stack: mobile - IdentityOktaAudience: https://profile.code.dev-theguardian.com/ - IdentityOktaIssuerUrl: https://profile.code.dev-theguardian.com/oauth2/aus3v9gla95Toj0EE0x7 - STAGE: CODE - Stage: CODE - EventInvokeConfig: - MaximumEventAgeInSeconds: 21600 - MaximumRetryAttempts: 2 - PackageType: Zip - Policies: - - Statement: - - Action: - - s3:GetObject* - - s3:GetBucket* - - s3:List* - Resource: - - arn:aws:s3:::mobile-dist - - arn:aws:s3:::mobile-dist/* - Effect: Allow - - Action: - - ssm:GetParametersByPath - Resource: >- - arn:aws:ssm:eu-west-1:201359054765:parameter/CODE/mobile/mobile-save-for-later - Effect: Allow - - Action: - - ssm:GetParameters - - ssm:GetParameter - Resource: >- - arn:aws:ssm:eu-west-1:201359054765:parameter/CODE/mobile/mobile-save-for-later/* - Effect: Allow - - Action: - - dynamodb:GetItem - - dynamodb:PutItem - - dynamodb:UpdateItem - - dynamodb:Query - Resource: >- - arn:aws:dynamodb:eu-west-1:201359054765:table/mobile-save-for-later-CODE-articles - Effect: Allow - - Effect: Allow - Action: - - logs:CreateLogGroup - - logs:CreateLogStream - - logs:PutLogEvents - Resource: '*' - Architecture: - x86_64 - ReservedConcurrentExecutions: 1 - SnapStart: - ApplyOn: None - Tags: - App: mobile-save-for-later - Stack: mobile - Stage: CODE - gu:build-tool: guardian/actions-riff-raff - gu:cdk:version: 45.1.0 - gu:repo: guardian/mobile-save-for-later - Events: - Api1: - Type: Api - Properties: - Path: /syncedPrefs/me - Method: GET - Api2: - Type: Api - Properties: - Path: /syncedPrefs/me - Method: GET -