aboutsummaryrefslogtreecommitdiffstats
path: root/license-generator/src
AgeCommit message (Collapse)Author
2018-11-10Add a helper function to verify webhook requestsTeddy Wing
The new `request::verified()` takes POST params as a string as does all the work needed to call `paddle::verify_signature()`. This involves extracting the `p_signature` POST parameter to get the signature, and getting the public key PEM. Change `params::parse()` to return a `BTreeMap<Cow<'a, str>, Cow<'a, str>>` instead of `String` keys & values. This is because `paddle::verify_signature()` needs a `(<&str, &str)` iterator. Actually, it still doesn't solve the problem because the types don't match. We need to modify the input type of `verify_signature()`, but at least this change gives us references. Make `params` private to the crate because we no longer need to use it in `main()`.
2018-11-10Parse POST params to a `BTreeMap`Teddy Wing
We want a dictionary to be able to remove the Paddle `p_signature` entry.
2018-11-10Add better messages on environment variable errorTeddy Wing
Otherwise it doesn't indicate the name of the environment variable in the result output: Error: Error(EnvVar(NotPresent), State { next_error: None, backtrace: InternalBacktrace { backtrace: None } })
2018-11-09Purchaser::insert(): Commit the transactionTeddy Wing
I had forgotten to commit the transaction, so the record I was trying to insert wouldn't get persisted in the database.
2018-11-09main(): Create a test purchaserTeddy Wing
Manually check that our purchaser creation and database persistence works. Make `purchaser` entities public in order to call them.
2018-11-09Purchaser::new(): Generate a secret in this methodTeddy Wing
Realised that when we want a new purchaser, we always want to generate a secret. This way we can call `new()` without having to call `generate_secret()` at the call site.
2018-11-09Set up a file loggerTeddy Wing
Get a file path from the `LOG_FILE` environment variable and use it for log output. Call `database::get_database_connection()` and log the error if it fails. Worried about exiting early from the FastCGI program, as DreamHost says this causes problems (https://help.dreamhost.com/hc/en-us/articles/217298967). But I don't see how the program can continue without a database connection. Return a `Result` from `main()` because it's easier to use the `?` operator for errors that happen before logging is initialised.
2018-11-09Add `get_database_connection()`Teddy Wing
Function to establish a database connection using a connection pool. Update `Purchaser::insert()` to take a `PooledConn` instead of a simple `Conn`.
2018-11-09Extract code in `lib.rs` to `errors.rs` and `purchaser.rs`Teddy Wing
Split up the code to get things a bit more organised. I want a function to create a connection to the MySQL database and I don't want to lump it in with the rest.
2018-11-09Purchaser: Remove `with_secret()` functionTeddy Wing
I don't see myself using this since I have the `generate_secret()` function now.
2018-11-09Purchaser::generate_secret(): Use a larger random number poolTeddy Wing
The `random()` function I was using will sample a value from "the full representable range" (https://docs.rs/rand/0.5.5/rand/#the-two-step-process-to-get-a-random-value). We should really be using longer numbers, so set the sample range to integers above and including 1 billion.
2018-11-09Purchaser: Add `generate_secret()` methodTeddy Wing
This new method generates a secret, which is a SHA1 digest of the purchaser's name, email, and a random integer. In order to use the `hexdigest()` method in the 'sha1' crate, I needed to add the feature `std` (https://docs.rs/sha1/0.6.0/sha1/struct.Sha1.html#method.hexdigest). Needed to change the `secret` field to a `String` because otherwise the generated digest string doesn't have a long enough lifetime to assign to it. Update `with_secret()` to use the new `String` type. Update `insert()` to correctly handle the `Option` in `secret`.
2018-11-09Purchaser: Implement `insert()`Teddy Wing
Haven't tested this at all so I have no idea if it works. Just getting a draft committed.
2018-11-09Add `lib.rs`Teddy Wing
Starting to set up database interactions. We need a way to insert purchasers into the database.
2018-11-04Make a simple FastCGI echo serverTeddy Wing
Building on the example from the 'fastcgi' crate: https://docs.rs/fastcgi/1.0.0/fastcgi/index.html prints all request parameters and the request `Stdin`. Post parameters are included in the stdin buffer.
2018-11-03Add 'license-generator' Rust projectTeddy Wing
Generated with: $ cargo new --bin license-generator using $ rustc --version rustc 1.28.0 (9634041f0 2018-07-30) This will be a FastCGI program to respond to a webhook from Paddle, and respond with a generated license key file.