Rename the project and add more README docs

This commit is contained in:
Tyler Hallada 2020-10-12 20:53:19 -04:00
parent 7fa6fe2b04
commit db8ccb3ca4
5 changed files with 983 additions and 924 deletions

1812
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
[package]
name = "shopkeeper"
name = "bazaar_realm_api"
version = "0.1.0"
authors = ["Tyler Hallada <tyler@hallada.net>"]
edition = "2018"

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Tyler Hallada
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,30 +1,57 @@
# Development Setup
# BazaarRealmAPI
The API for the Bazaar Realm Skyrim mod which is responsible for storing and
serving data related to the mod to all users.
Right now, the types of data the API stores and the endpoints to access them
are (all prefixed under `/v1`, the API version):
* `/owners`: Every player character that has registered with this API server.
Contains their unique api key. Owners own shops.
* `/shops`: Metadata about each shop including name, description, and who owns
it.
* `/interior_ref_lists`: Lists of in-game ObjectReferences that are in the
interior of individual shops. When a user visits a shop, these references
are loaded into the cell.
* `/merchandise_lists`: Lists of in-game Forms that are in the merchant chest
of individual shops. When a user visits a shop, these forms are loaded
onto the shop's shelves and are purchasable.
Bazaar Realm was designed to allow users to change the API they are using the
mod under, if they wish. The API can run on a small server with minimal
resources, which should be suitable for a small group of friends to share
shops with each other.
It uses the [`warp`](https://crates.io/crates/warp) web server framework and
[`sqlx`](https://crates.io/crates/sqlx) for database queries to a [PostgreSQL
database](https://www.postgresql.org).
## Development Setup
1. Install and run postgres.
2. Create postgres user and database (and add uuid extension while you're there
):
```
createuser shopkeeper
createdb shopkeeper
createuser bazaarrealm
createdb bazaarrealm
sudo -u postgres -i psql
postgres=# ALTER DATABASE shopkeeper OWNER TO shopkeeper;
\password shopkeeper
postgres=# ALTER DATABASE bazaarrealm OWNER TO bazaarrealm;
\password bazaarrealm
postgres=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
# Or, on Windows in PowerShell:
& 'C:\Program Files\PostgreSQL\13\bin\createuser.exe' -U postgres shopkeeper
& 'C:\Program Files\PostgreSQL\13\bin\createdb.exe' -U postgres shopkeeper
& 'C:\Program Files\PostgreSQL\13\bin\createuser.exe' -U postgres bazaarrealm
& 'C:\Program Files\PostgreSQL\13\bin\createdb.exe' -U postgres bazaarrealm
& 'C:\Program Files\PostgreSQL\13\bin\psql.exe' -U postgres
postgres=# ALTER DATABASE shopkeeper OWNER TO shopkeeper;
\password shopkeeper
postgres=# ALTER DATABASE bazaarrealm OWNER TO bazaarrealm;
\password bazaarrealm
postgres=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
```
3. Save password somewhere safe and then and add a `.env` file to the project
directory with the contents:
```
DATABASE_URL=postgresql://shopkeeper:<password>@localhost/shopkeeper
RUST_LOG="shopkeeper=debug"
DATABASE_URL=postgresql://bazaarrealm:<password>@localhost/bazaarrealm
RUST_LOG="bazaar_realm_api=debug"
HOST="http://localhost:3030"
```
4. Create a new file at `src/db/refinery.toml` with the contents:
@ -33,16 +60,16 @@ HOST="http://localhost:3030"
db_type = "Postgres"
db_host = "localhost"
db_port = "5432"
db_user = "shopkeeper"
db_user = "bazaarrealm"
db_pass = "<database-password-here>"
db_name = "shopkeeper"
db_name = "bazaarrealm"
```
5. Run `cargo run -- -m` which will compile the app in debug mode and run the
database migrations.
6. Run `./devserver.sh` to run the dev server (by default it listens at
`127.0.0.1:3030`).
# Testing Data
## Testing Data
Using [httpie](https://httpie.org/) you can use the json files in
`test_data/` to seed the database with data.
@ -63,10 +90,23 @@ http GET "http://localhost:3030/v1/interior_ref_lists"
http GET "http://localhost:3030/v1/merchandise_lists"
```
## Authentication
I don't want to require users of Bazaar Realm to have to remember a password,
so I forgoed the typical username and password authentication in favor of a
unique UUID identifier instead. This is the api key that the
`BazaarRealmClient` generates when the user first starts the mod in a game.
The api key is stored in the save game files for the player character and is
required to be sent with any API request that modifies data.
Yes, it's not most secure solution, but I'm not convinced security is a huge
concern here. As long as users don't share their API key or the save game
files that contain it, their data should be secure.
# Todo
* Add update endpoints.
* Add endpoints for the other models.
* Make self-contained docker container that can run the app without any setup.
* Add rate-limiting per IP address. The `tower` crate has a service that might
be useful for this.
be useful for this.

View File

@ -58,7 +58,7 @@ struct ErrorMessage {
async fn main() -> Result<()> {
dotenv().ok();
let env_log_filter =
env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,shopkeeper=info".to_owned());
env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,bazaar_realm_api=info".to_owned());
tracing_subscriber::fmt()
.with_env_filter(env_log_filter)
.with_span_events(FmtSpan::CLOSE)