Skip to content

Commit

Permalink
fix: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
sciencefidelity committed Sep 15, 2024
1 parent e89281f commit 915e2f3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 23 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
use flake
dotenv

12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
{
devShells.default = mkShell {
buildInputs = [
docker-client
pkg-config
postgresql
sqlx-cli
(rust-bin.stable.latest.default.override {
extensions = [ "rust-analyzer" "rust-src" ];
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eroteme::{oneshot, setup_store, Config};
use eroteme::{oneshot, store, Config};
use futures_util::FutureExt;
use reqwest::header;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn main() -> Result<(), handle_errors::Error> {
.write_all(&s.stderr)
.expect("failed to write to stdout");

let store = setup_store(&config).await?;
let store = store::setup(&config).await?;

let handler = oneshot(store).await;

Expand Down
24 changes: 14 additions & 10 deletions scripts/init_db.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/bin/sh

if ! command -v psql >/dev/null 2>&1
then
if ! command -v psql >/dev/null 2>&1; then
echo >&2 "Error: psql is not installed."
exit 1
fi

if ! command -v sqlx >/dev/null 2>&1
then
if ! command -v sqlx >/dev/null 2>&1; then
echo >&2 "Error: sqlx is not installed."
echo >&2 "Use:"
echo >&2 " cargo install --version='~0.7' sqlx-cli" \
Expand All @@ -24,7 +22,15 @@ DB_HOST="${POSTGRES_HOST:=localhost}"

if [ -z "${SKIP_DOCKER}" ]
then
docker run \
RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
echo >&2 "there is a postgres container already running, kill it with"
echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
exit 1
fi
docker \
-H ssh://sao \
run \
-e POSTGRES_USER=${DB_USER} \
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
-e POSTGRES_DB=${DB_NAME} \
Expand All @@ -33,16 +39,14 @@ then
postgres -N 1000
fi

export PGPASSWORD="${DB_PASSWORD}"
until psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
echo "Postgres is still unavailable - sleeping"
sleep 1
done

echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"
>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!"

DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
export DATABASE_URL
export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
sqlx database create
sqlx migrate run

Expand Down
4 changes: 2 additions & 2 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eroteme::setup_store;
use eroteme::store;
use eroteme::Config;
use std::env;

Expand All @@ -7,7 +7,7 @@ async fn main() -> Result<(), handle_errors::Error> {
dotenv::dotenv().ok();

let config = Config::new().expect("failed to set config");
let store = setup_store(&config).await?;
let store = store::setup(&config).await?;

tracing::info!("Eroteme build ID {}", env!("EROTEME_VERSION"));
eroteme::run(config, store).await;
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use router::build_routes;
pub mod routes;

pub mod store;
pub use store::setup_store;
use store::Store;

pub mod types;
Expand All @@ -28,6 +27,9 @@ pub async fn run(config: Config, store: Store) {
warp::serve(routes).run(([0, 0, 0, 0], config.port)).await;
}

/// # Panics
///
/// Will panic if socket address in not valid.
pub async fn oneshot(store: Store) -> OneShotHandler {
let routes = build_routes(store).await;
let (tx, rx) = oneshot::channel::<i32>();
Expand Down
2 changes: 1 addition & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) async fn build_routes(store: Store) -> impl Filter<Extract = impl Rep
let login = warp::post()
.and(warp::path("login"))
.and(warp::path::end())
.and(store_filter.clone())
.and(store_filter)
.and(warp::body::json())
.and_then(routes::login);

Expand Down
5 changes: 4 additions & 1 deletion src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ impl Store {
}
}

pub async fn setup_store(config: &Config) -> Result<Store, handle_errors::Error> {
/// # Errors
///
/// Will return `Err` if the database migration fails.
pub async fn setup(config: &Config) -> Result<Store, handle_errors::Error> {
let store = Store::new(&format!(
"postgres://{}:{}@{}:{}/{}",
config.db_user, config.db_password, config.db_host, config.db_port, config.db_name
Expand Down

0 comments on commit 915e2f3

Please sign in to comment.