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: implement the /configuration endpoint #39

Merged
merged 1 commit into from
Sep 28, 2018
Merged

feat: implement the /configuration endpoint #39

merged 1 commit into from
Sep 28, 2018

Conversation

philbooth
Copy link
Contributor

Fixes #25.

Adds a ServerLimits type to src/settings.rs, containing the static values returned by the /info/configuration endpoint. The default values are the same as the ones in the Python code.

@bbangert @pjenvey r?

Cargo.toml Outdated
@@ -29,7 +29,7 @@ mozsvc-common = "0.1.0"
num_cpus = "1.8.0"
rand = "0.5.2"
ring = "0.13.2"
serde = "1.0.67"
serde = { version = "1.0.67", features = ["rc"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feature added so that Arc<ServerLimits> can be serialized to a JSON response payload. The alternative is to derive Clone and Copy on ServerLimits and don't keep it in an Arc. I wasn't sure which would be preferable, happy to make the switch if this way is wrong.

Copy link
Member

Choose a reason for hiding this comment

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

You should be able to get away w/out it. The inner ServerLimits can be deref'd out of the arc via *server.limits -- and we need to borrow it for the json call, so: json(&*server.limits)

Feel free to change this later if it makes it easier on these 2 outstanding PRs

test_endpoint(
http::Method::GET,
"/42/info/configuration",
&serde_json::to_string(&ServerLimits::default()).unwrap(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did wonder whether this test is too tautological to be useful, but I think it's okay. Asserting that the response payload equals the JSON serialization of the default ServerLimits is fine, yeah?

static DEFAULT_MAX_RECORD_PAYLOAD_BYTES: u32 = 2 * MEGABYTE;
static DEFAULT_MAX_REQUEST_BYTES: u32 = DEFAULT_MAX_POST_BYTES + 4 * KILOBYTE;
static DEFAULT_MAX_TOTAL_BYTES: u32 = 100 * DEFAULT_MAX_POST_BYTES;
static DEFAULT_MAX_TOTAL_RECORDS: u32 = 100 * DEFAULT_MAX_POST_RECORDS;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 retain the doc strings as well.

#[derive(Debug)]
pub struct Secrets {
pub master_secret: Vec<u8>,
pub signing_secret: [u8; 32],
}

impl Secrets {
pub fn new(master_secret: &str) -> Secrets {
pub fn new(master_secret: &str) -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only learned this for the first time when I reviewed one of those pull requests yesterday. Hence going back and applying it to the other code I wrote in here, even though it's not strictly related.

@philbooth
Copy link
Contributor Author

philbooth commented Sep 25, 2018

It just occurred to me that I haven't done anything in this PR to actually enforce these limits, I'm just blithely using the same values as the Python codebase. Is it something that we'd configure in nginx or whatever, or are there hooks in actix-web we can use? (I'll go and RTFM right now, sorry)

Anyway, hopefully it's okay for a follow-up (I'll open an issue if so)...

EDIT: #40

@philbooth
Copy link
Contributor Author

philbooth commented Sep 25, 2018

Is it something that we'd configure in nginx or whatever, or are there hooks in actix-web we can use?

(I mean the _BYTES settings here of course, the _RECORDS ones will need to be enforced in code I realise)

EDIT: Actually, thinking it through sorry, it's only max_request_bytes that could be enforced outside of code anyway. Ignore me.

bbangert
bbangert previously approved these changes Sep 25, 2018
bbangert
bbangert previously approved these changes Sep 26, 2018
pjenvey
pjenvey previously approved these changes Sep 28, 2018
@philbooth
Copy link
Contributor Author

Sorry both, I had to rebase because merge conflicts, so your reviews were dismissed.

On the plus side it was an opportunity to try Phil's suggestion about dereffing state.limits, which worked well. So, winning really.

@pjenvey pjenvey merged commit f142928 into master Sep 28, 2018
@pjenvey pjenvey deleted the pb/25 branch September 28, 2018 16:24
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.

None yet

3 participants