Removed secrets
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
/node_modules
|
/node_modules
|
||||||
|
.env
|
||||||
|
|||||||
4
configuration/base.yaml
Normal file
4
configuration/base.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
email_client:
|
||||||
|
timeout_milliseconds: 10000
|
||||||
|
base_url: "https://api.alphonsepaix.xyz"
|
||||||
|
sender_email: "newsletter@alphonsepaix.xyz"
|
||||||
16
configuration/local.yaml
Normal file
16
configuration/local.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
application:
|
||||||
|
port: 8080
|
||||||
|
host: "127.0.0.1"
|
||||||
|
base_url: "http://127.0.0.1:8080"
|
||||||
|
database:
|
||||||
|
host: "127.0.0.1"
|
||||||
|
port: 5432
|
||||||
|
database_name: "newsletter"
|
||||||
|
username: "postgres"
|
||||||
|
password: "password"
|
||||||
|
require_ssl: false
|
||||||
|
timeout_milliseconds: 1000
|
||||||
|
email_client:
|
||||||
|
authorization_token: "secret-token"
|
||||||
|
redis_uri: "redis://127.0.0.1:6379"
|
||||||
|
require_tls: false
|
||||||
4
configuration/production.yaml
Normal file
4
configuration/production.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
application:
|
||||||
|
host: "0.0.0.0"
|
||||||
|
database:
|
||||||
|
timeout_milliseconds: 500
|
||||||
45
scripts/init_db.sh
Executable file
45
scripts/init_db.sh
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
if ! [ -x "$(command -v psql)" ]; then
|
||||||
|
echo >&2 "Error: psql is not installed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [ -x "$(command -v sqlx)" ]; then
|
||||||
|
echo >&2 "Error: sqlx is not installed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DB_USER="${POSTGRES_USER:=postgres}"
|
||||||
|
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
|
||||||
|
DB_NAME="${POSTGRES_DB:=newsletter}"
|
||||||
|
DB_PORT="${POSTGRES_PORT:=5432}"
|
||||||
|
DB_HOST="${POSTGRES_HOST:=localhost}"
|
||||||
|
|
||||||
|
if [[ -z "${SKIP_DOCKER}" ]]; then
|
||||||
|
docker run \
|
||||||
|
-e POSTGRES_USER=${DB_USER} \
|
||||||
|
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
|
||||||
|
-e POSTGRES_DB=${DB_NAME} \
|
||||||
|
-p "127.0.0.1:${DB_PORT}":5432 \
|
||||||
|
-d postgres \
|
||||||
|
postgres -N 1000
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PGPASSWORD="${DB_PASSWORD}"
|
||||||
|
until psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
|
||||||
|
>&2 echo "Postgres is still unavailable - sleeping"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
>&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
|
||||||
|
sqlx database create
|
||||||
|
sqlx migrate run
|
||||||
|
|
||||||
|
>&2 echo "Postgres has been migrated, ready to go!"
|
||||||
@@ -110,7 +110,7 @@ pub struct DatabaseSettings {
|
|||||||
pub host: String,
|
pub host: String,
|
||||||
pub database_name: String,
|
pub database_name: String,
|
||||||
pub require_ssl: bool,
|
pub require_ssl: bool,
|
||||||
pub timeout_millis: u64,
|
pub timeout_milliseconds: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseSettings {
|
impl DatabaseSettings {
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ impl Application {
|
|||||||
configuration.application.host, configuration.application.port
|
configuration.application.host, configuration.application.port
|
||||||
);
|
);
|
||||||
let connection_pool = PgPoolOptions::new()
|
let connection_pool = PgPoolOptions::new()
|
||||||
.acquire_timeout(Duration::from_millis(configuration.database.timeout_millis))
|
.acquire_timeout(Duration::from_millis(
|
||||||
|
configuration.database.timeout_milliseconds,
|
||||||
|
))
|
||||||
.connect_lazy_with(configuration.database.with_db());
|
.connect_lazy_with(configuration.database.with_db());
|
||||||
let email_client = EmailClient::build(configuration.email_client).unwrap();
|
let email_client = EmailClient::build(configuration.email_client).unwrap();
|
||||||
let pool = Pool::new(
|
let pool = Pool::new(
|
||||||
|
|||||||
@@ -108,5 +108,11 @@ async fn subscribe_fails_if_there_is_a_fatal_database_error() {
|
|||||||
|
|
||||||
let response = app.post_subscriptions(body).await;
|
let response = app.post_subscriptions(body).await;
|
||||||
|
|
||||||
assert_eq!(response.status().as_u16(), 500);
|
assert!(
|
||||||
|
response
|
||||||
|
.text()
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.contains("An internal server error occured")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user