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

feat: switch to latest release a2 library #362

Merged
merged 9 commits into from
May 26, 2023
Merged

feat: switch to latest release a2 library #362

merged 9 commits into from
May 26, 2023

Conversation

jrconlin
Copy link
Member

@jrconlin jrconlin commented Apr 4, 2023

  • This switches from our semi-vendored a2, back to the official release.
    This should also clear the warning about the included nom library.

Breaking Change
This removes the unused .aps field from the router_data options. This
field was only used during testing. That test was also removed.

jrconlin added 2 commits April 4, 2023 09:03
* This switches from our semi-vendored a2, back to the official release.
This should also clear the warning about the included `nom` library.

*Breaking Change*
This removes the unused `.aps` field from the router_data options. This
field was only used during testing. That test was also removed.
@jrconlin jrconlin requested review from pjenvey and a team April 4, 2023 17:22
* note the reason we can't update tungstenite properly
@pjenvey
Copy link
Member

pjenvey commented Apr 18, 2023

We've identified some missing parts of Mark's original a2 branch that didn't get merged to a2 master likely due to merge conflicts. E.g. in this PR the Client::certificate_parts in here wasn't added. So we should double check that all of Mark's original branch made it into a2 before moving off of it.

@hackebrot
Copy link
Member

Hi @jrconlin! 👋🏻

I see you've added test eng as reviewers on this pull request, but neither @Trinaa or myself have any context about this project. Did you have any specific questions that we can help with?

@jrconlin jrconlin removed the request for review from a team May 2, 2023 15:07
@jrconlin
Copy link
Member Author

jrconlin commented May 2, 2023

Hi @jrconlin! 👋🏻

I see you've added test eng as reviewers on this pull request, but neither @Trinaa or myself have any context about this project. Did you have any specific questions that we can help with?

Sorry, that was probably a mis-click on my part. I've removed you from review.

@hackebrot
Copy link
Member

No worries, @jrconlin! Thanks. 👍🏻

@jrconlin
Copy link
Member Author

I compared the current version of mozilla-services/a2 against Mark's PR and looks like the only thing missing was the Client::certificate_parts method. I added it to this PR.

Once that PR lands, I'll redo this PR to include the new 0.8.0 version, and then submit a PR to wallet/a2 to include the change as well. That should let us be able to release the new server with the new library.

@jrconlin
Copy link
Member Author

Switched to using our mozilla-services/a2 git repo while we wait for reown-com/a2#72 to land.

Part of the delay was trying to debug the way that code wants to read in key/cert from the environment. I couldn't get the escape quite right. I would frequently get a Private Key error in the cert. Passing

"AUTOEND__APNS__CHANNELS": "{\"dev\":{\"cert\": \"keys/test.crt\", \"key\":\"keys/test.key\"}}",

worked, even with the same values, so guessing all the coding/recording might have changed a value.

@pjenvey
Copy link
Member

pjenvey commented May 25, 2023

Part of the delay was trying to debug the way that code wants to read in key/cert from the environment. I couldn't get the escape quite right. I would frequently get a Private Key error in the cert. Passing

"AUTOEND__APNS__CHANNELS": "{\"dev\":{\"cert\": \"keys/test.crt\", \"key\":\"keys/test.key\"}}",

Maybe that's more of a shell problem, assuming you're running with AUTOEND__APNS__CHANNELS="{\"dev\":{\"cert\": \"keys/test.crt\", \"key\":\"keys/test.key\"}}"? With the outer double quotes conflicting with the inner ones

I just tried running it surrounded in single quotes instead (preserving everything inside) and it worked as I'd expect (on master):

AUTOEND__APNS__CHANNELS='{"dev":{"cert": "keys/test.crt", "key":"keys/test.key"}}' AUTOEND__HUMAN_LOGS=true RUST_BACKTRACE=1 cargo run
...
May 25 23:48:08.863 DEBG Starting up...
settings.apns: ApnsSettings {
    channels: "{\"dev\":{\"cert\": \"keys/test.crt\", \"key\":\"keys/test.key\"}}",
    max_data: 4096,
}
May 25 23:48:08.864 DEBG initialized disabled sentry client due to disabled or invalid DSN
settings.apns.channels(): Ok(
    {
        "dev": ApnsChannel {
            cert: "keys/test.crt",
            key: "keys/test.key",
            topic: None,
            sandbox: false,
        },
    },
)

@jrconlin
Copy link
Member Author

jrconlin commented May 26, 2023

Oh, it's absolutely a vscode problem, and I was being stubborn.

< rant >
In VS Code, you specify your run args as a JSON structure. This includes a set of environment variables specified as key values, that you have to properly escape so that the JSON to env and then the env to JSON parser can handle, so you wind up with stuff like:

        {
            "type": "lldb",
            … ,
            "cwd": "${workspaceFolder}",
            "env": {
                "RUST_LOG": "autopush=DEBUG,autoconnect=DEBUG,autopush_common=DEBUG,autoendpoint=DEBUG,warn",
                "AUTOEND__PORT": "9160",
                //"AUTOEND__BIND_HOST": "0.0.0.0",
                "AUTOEND__HUMAN_LOGS": "1",
                "AUTOEND__CRYPTO_KEYS": "[…]",
                "AUTOEND__APNS__CHANNELS": "{\"dev\":{\"cert\":\"-----BEGIN CERTIFICATE-----\\n…=\\n-----END CERTIFICATE-----\", \"key\": \"-----BEGIN PRIVATE KEY-----\\n…----END PRIVATE KEY-----\"}}",
            }
        },

So yeah, LOTS of opportunities to screw things up, because control characters in JSON strings are big no-nos.
</ rant >

@jrconlin jrconlin requested a review from pjenvey May 26, 2023 17:29
Copy link
Member

@pjenvey pjenvey left a comment

Choose a reason for hiding this comment

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

Couple things:

  • I forgot what we concluded when we last discussed this, but is there a way to add a test that ensures we fixed the panic? Can we just shoot a message to Endpoint::Sandbox?
  • probably want to rename the branch to feat/ at this point

# The version of a2 at the time of the fork is v0.5.3.
a2 = { git = "https://github.com/mozilla-services/a2.git", branch = "autoendpoint" }
# several of these libraries are pinned due to https://github.com/mozilla-services/autopush-rs/issues/249
a2 = {version = "0.8", git = "https://github.com/mozilla-services/a2"}
Copy link
Member

Choose a reason for hiding this comment

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

We should probably pin this to a specific revision (even though we own this repo) -- actually, upstream quickly merged your pr 🎉 so let's pin to their repo instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

?? reown-com/a2#72 is still pending review.

I'll pin to a specific commit, but will still keep the version, since I ought to do a release.

Copy link
Member

Choose a reason for hiding this comment

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

My fault I must have been looking at the wrong repo

@@ -251,15 +302,13 @@ impl Router for ApnsRouter {
.get("rel_channel")
.and_then(Value::as_str)
.ok_or(ApnsError::NoReleaseChannel)?;
// XXX: We don't really use anything that is a numeric here, aside from
Copy link
Member

Choose a reason for hiding this comment

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

Not really an XXX: (broken/fixmeish) comment IMO

Suggested change
// XXX: We don't really use anything that is a numeric here, aside from
// NOTE: We don't really use anything that is a numeric here, aside from

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually... It is a FIXME, specifically the third line:

// Once we're off of DynamoDB, we might want to kill the map.

That's a note to future us that we probably want to recheck if we need to do this, right?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, could do FIXME but XXX works

.collect(),
device_token: token,
options: NotificationOptions {
let mut aps = Self::default_aps();
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I probably missed some this the last time I reviewed it (is James back from PTO yet, can we just kill all this? 😄 ) -- looking at it now, I think we can at least move this large chunk into its own method, I've taken a shot at that on this branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, sure? It's still a big ugly pile of code regardless of if we want to screw with the stack or not. Tossing it into a different function doesn't really help, and IDEs allow for block collapse if we just want to ignore it for now.

Copy link
Member

Choose a reason for hiding this comment

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

It's just too many lines for one method, this block is > 100 by itself (clippy's pedantic too_many_lines lint is that). I assumed it was in here due to lifetime trickyness, hence my branch to solve that w/ the new method. I wouldn't justify e.g. an even larger say 500 line method either with IDE collapsing help -- so I'll argue this does help readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, fair. I broke it out into it's own function like you suggested. (changed the name and gave it a better comment) I was debating how much of that I could reduce using macros, but I figured that was more work for what was (hopefully) a temporary thing.

@jrconlin jrconlin requested a review from pjenvey May 26, 2023 21:48
pjenvey
pjenvey previously approved these changes May 26, 2023
@@ -45,7 +45,7 @@ tokio.workspace = true
url.workspace = true
uuid.workspace = true

a2 = {version = "0.8", git = "https://github.com/mozilla-services/a2"}
a2 = {version = "0.8", git = "https://github.com/mozilla-services/a2", branch="master"}
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking more of a specific sha (thinking of reproducable builds) but then again we weren't doing this before by pointing to the autoendpoint branch, so never mind I guess.

@jrconlin jrconlin merged commit 728fe16 into master May 26, 2023
@jrconlin jrconlin deleted the chore/main-a2 branch May 26, 2023 23:09
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