Граф коммитов

111 Коммитов

Автор SHA1 Сообщение Дата
Phil Booth c08434beb9 chore(project): add the MPL 2018-05-04 07:14:43 +01:00
Phil Booth f7dd71456e
refactor(settings): extract common functions for deserialization
Extracts the inline validation code from the settings module to a
dedicated deserialize module, so that the validation rules can be better
re-used elsewhere.

Uses functions rather than newtype structs, for 2 reasons:

1. There's an issue in the config crate where newtype structs aren't
   deserialized. An unmerged PR exists to fix it, but in the meantime
   this changeset works round the problem.

2. When using newtype structs, the tests aren't able to create fresh
   instances of the Settings struct unless it is flattened to a single
   level.

Maybe we can revisit the newtype struct approach down the line when both
of the above are resolved.

https://github.com/mozilla/fxa-email-service/pull/15
r=rfk
2018-05-04 06:27:33 +01:00
Phil Booth 04e33b0afc chore(ci): fix to rust nightly 2018-04-28
Related to https://github.com/SergioBenitez/Rocket/pull/624
2018-05-03 17:28:39 +01:00
Phil Booth a86015fb49 feat(config): add configuration
Imitates, as closely as possible, the convict-based approach we use in
our node repos. The major difference is that validation here has to
happen in the code, we can't define it in config.

Settings are applied in the following order:

* config/default.json
* config/${NODE_ENV}.json (optional)
* config/local.json (optional, git-ignored)
* environment variables

I opted to re-use $NODE_ENV instead of some rust-specific environment
variable so that our dev setups will work with minimal changes. If that
seems too weird though I can change it.

Uses the `config` crate, which was the convictiest dependency I could
find.
2018-04-30 18:54:48 +01:00
Phil Booth 4d1a265c40 chore(project): turn off reorder_impl_items rustfmt setting 2018-04-29 08:15:11 +01:00
Phil Booth 13ffd01594 chore(project): revert a bunch of custom rustfmt settings 2018-04-27 11:30:20 +01:00
Phil Booth b6dad7217c fix(api): limit `to` field to a single recipient 2018-04-27 11:30:20 +01:00
Phil Booth 6c3361c2a1 feat(api): implement a basic /send endpoint
Not wired in to any behaviour, just does some crude validation and then
returns a hard-coded message id. There is some test coverage, but also
some gaps where I haven't figured out how we should do stuff yet:

* The validation code is punishingly verbose. I evauated a couple of
  crates to implement validation, `accord` and `validator`, and opted
  for `validator`. However they both seem quite simple, for instance
  there's no support for nested objects or values packed inside arrays.
  This meant we couldn't lean on the nice, readable macro syntax that's
  available and have to explitly validate fields using Rocket's FromData
  trait instead.

* Rocket has a feature called error catchers, which I couldn't get to
  work. These are supposed to let you return custom error data but, no
  matter what I tried, it always seemed to return the default error
  response for each type (which is an html string). And even if I could
  get those to work, I couldn't see a way to propagate rich error
  information, e.g. names of invalid parameters, into the catcher
  without having to validate all of the parameters a second time inside
  the catcher.

* I tried to write a test case that fired unicode at the endpoint and it
  failed.

I'm sure the root cause of these problems is just my own lack of
expertise and we'll figure it out eventually. In the meantime, this
seemed like enough to get us started. I'll open issues to cover the
above.

In terms of code structure, I've just lumped most stuff in to the send
module for now. As we add more functionality, I expect the natural
boundaries to reveal themselves. No point agonising over it yet.
2018-04-27 11:30:20 +01:00
Phil Booth b616c36ca3 chore(project): add ci config 2018-04-25 15:40:51 +01:00
Phil Booth a7b1f51013 chore(project): add rocket dependency 2018-04-25 10:27:43 +01:00
Phil Booth 88897ee78c chore(project): initial boilerplate 2018-04-25 10:27:43 +01:00