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

AWS/SNS create endpoint without custom user data (SQCORE-1267) #2910

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3-bug-fixes/aws-sns-without-CustomUserData
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Previously, AWS/SNS endpoint creation included `CustomUserData` which was the `UserId`. This doesn't make sense anymore; given that a user may be attached with the same device (Android or iOS) and several accounts (several `UserId`s!) to the same backend. So, `CustomUserData` isn't added to the request, anymore.
24 changes: 21 additions & 3 deletions services/gundeck/src/Gundeck/Aws.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,18 @@ lookupEndpoint arn = do
pure (SNSEndpoint (Push.Token t) (fromMaybe False e) d)
mkUsers = Set.fromList . mapMaybe (hush . fromText) . Text.split (== ':')

createEndpoint :: UserId -> Push.Transport -> ArnEnv -> AppName -> Push.Token -> Amazon (Either CreateEndpointError EndpointArn)
createEndpoint u tr arnEnv app token = do
createEndpoint :: Push.Transport -> ArnEnv -> AppName -> Push.Token -> Amazon (Either CreateEndpointError EndpointArn)
createEndpoint tr arnEnv app token = do
env <- ask
let top = mkAppTopic arnEnv tr app
let arn = mkSnsArn (env ^. region) (env ^. account) top
let tkn = Push.tokenText token
let req =
SNS.newCreatePlatformEndpoint (toText arn) tkn
& set SNS.createPlatformEndpoint_customUserData (Just (toText u))
& set SNS.createPlatformEndpoint_attributes (Just $ Map.insert "Enabled" "true" Map.empty)
logRequest req tkn arn
res <- retrying (limitRetries 2) (const isTimeout) (const (sendCatch (env ^. awsEnv) req))
logResponse res tkn arn
case res of
Right r ->
case view SNS.createPlatformEndpointResponse_endpointArn r of
Expand All @@ -313,6 +314,7 @@ createEndpoint u tr arnEnv app token = do
debug $
msg @Text "InvalidParameter: InvalidToken"
. field "response" (show x)
. logFields tkn arn
pure (Left (InvalidToken token))
| is "SNS" 404 x ->
pure (Left (AppNotFound app))
Expand Down Expand Up @@ -343,6 +345,22 @@ createEndpoint u tr arnEnv app token = do
string "must be at most 8192 bytes long in UTF-8 encoding"
<|> string "iOS device tokens must be no more than 400 hexadecimal characters"
pure ()
logRequest req tkn arn =
trace $
msg @Text "AWS/SNS endpoint creation request"
. field "request" (show req)
. logFields tkn arn
logResponse res tkn arn =
trace $
msg @Text "AWS/SNS endpoint creation response"
. field "response" (show res)
. logFields tkn arn
logFields tkn arn =
field "transport" (show tr)
. field "appName" (show app)
. field "arnEnv" (show arnEnv)
. field "token" tkn
. field "arn" (toText arn)

--------------------------------------------------------------------------------
-- Publish
Expand Down
2 changes: 1 addition & 1 deletion services/gundeck/src/Gundeck/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ addToken uid cid newtok = mpaRunWithBudget 1 (Left Public.AddTokenErrorNoBudget)
let tok = t ^. token
env <- view (options . optAws . awsArnEnv)
aws <- view awsEnv
ept <- Aws.execute aws (Aws.createEndpoint uid trp env app tok)
ept <- Aws.execute aws (Aws.createEndpoint trp env app tok)
case ept of
Left (Aws.EndpointInUse arn) -> do
Log.info $ "arn" .= toText arn ~~ msg (val "ARN in use")
Expand Down