Skip to content

Commit

Permalink
wip: At least it runs now
Browse files Browse the repository at this point in the history
  • Loading branch information
Eragonfr committed Mar 5, 2024
1 parent bd24d7c commit e2b8563
Show file tree
Hide file tree
Showing 36 changed files with 2,414 additions and 60 deletions.
80 changes: 80 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ members = [
"tokenserver-auth",
"tokenserver-common",
"tokenserver-db",
"tokenserver-db-common",
"tokenserver-db-mysql",
"tokenserver-db-sqlite",
"tokenserver-settings",
"syncserver",
]
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ PYTHON_SITE_PACKGES = $(shell $(SRC_ROOT)/venv/bin/python -c "from distutils.sys

clippy_sqlite:
# Matches what's run in circleci
cargo clippy --workspace --all-targets --no-default-features --features=syncstorage-db/sqlite -- -D warnings
cargo clippy --workspace --all-targets --no-default-features --features=syncstorage-db/sqlite,tokenserver-db/sqlite --features=py_verifier -- -D warnings

clippy_mysql:
# Matches what's run in circleci
cargo clippy --workspace --all-targets --no-default-features --features=syncstorage-db/mysql --features=py_verifier -- -D warnings
cargo clippy --workspace --all-targets --no-default-features --features=syncstorage-db/mysql,tokenserver-db/mysql --features=py_verifier -- -D warnings

clippy_spanner:
# Matches what's run in circleci
cargo clippy --workspace --all-targets --no-default-features --features=syncstorage-db/spanner --features=py_verifier -- -D warnings
cargo clippy --workspace --all-targets --no-default-features --features=syncstorage-db/spanner,tokenserver-db/mysql --features=py_verifier -- -D warnings

clean:
cargo clean
Expand Down Expand Up @@ -57,9 +57,9 @@ run_mysql: python
# See https://github.com/PyO3/pyo3/issues/1741 for discussion re: why we need to set the
# below env var
PYTHONPATH=$(PYTHON_SITE_PACKGES) \
RUST_LOG=debug \
RUST_LOG=debug \
RUST_BACKTRACE=full \
cargo run --no-default-features --features=syncstorage-db/mysql --features=py_verifier -- --config config/local.toml
cargo run --no-default-features --features=syncstorage-db/mysql,tokenserver-db/mysql --features=py_verifier -- --config config/local.toml

run_sqlite: python
PATH="./venv/bin:$(PATH)" \
Expand All @@ -68,7 +68,7 @@ run_sqlite: python
PYTHONPATH=$(PYTHON_SITE_PACKGES) \
RUST_LOG=debug \
RUST_BACKTRACE=full \
cargo run --no-default-features --features=syncstorage-db/sqlite -- --config config/local.toml
cargo run --no-default-features --features=syncstorage-db/sqlite,tokenserver-db/sqlite --features=py_verifier -- --config config/local.toml

run_spanner: python
GOOGLE_APPLICATION_CREDENTIALS=$(PATH_TO_SYNC_SPANNER_KEYS) \
Expand All @@ -79,7 +79,7 @@ run_spanner: python
PATH="./venv/bin:$(PATH)" \
RUST_LOG=debug \
RUST_BACKTRACE=full \
cargo run --no-default-features --features=syncstorage-db/spanner --features=py_verifier -- --config config/local.toml
cargo run --no-default-features --features=syncstorage-db/spanner,tokenserver-db/mysql --features=py_verifier -- --config config/local.toml

test_mysql:
SYNC_SYNCSTORAGE__DATABASE_URL=mysql://sample_user:sample_password@localhost/syncstorage_rs \
Expand Down
31 changes: 31 additions & 0 deletions tokenserver-db-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "tokenserver-db-common"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

[dependencies]
backtrace.workspace = true
futures.workspace = true
http.workspace = true
serde.workspace = true
serde_derive.workspace = true
serde_json.workspace = true
slog-scope.workspace = true

async-trait = "0.1.40"
diesel = { version = "1.4", features = ["mysql", "r2d2"] }
diesel_logger = "0.1.1"
diesel_migrations = { version = "1.4.0", features = ["mysql"] }
syncserver-common = { path = "../syncserver-common" }
syncserver-db-common = { path = "../syncserver-db-common" }
thiserror = "1.0.26"
tokenserver-common = { path = "../tokenserver-common" }
tokenserver-settings = { path = "../tokenserver-settings" }
tokio = { workspace = true, features = ["macros", "sync"] }

[dev-dependencies]
env_logger.workspace = true

syncserver-settings = { path = "../syncserver-settings" }
22 changes: 11 additions & 11 deletions tokenserver-db/src/error.rs → tokenserver-db-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use syncserver_db_common::error::SqlError;
use thiserror::Error;
use tokenserver_common::TokenserverError;

pub(crate) type DbFuture<'a, T> = syncserver_db_common::DbFuture<'a, T, DbError>;
pub(crate) type DbResult<T> = Result<T, DbError>;
pub type DbFuture<'a, T> = syncserver_db_common::DbFuture<'a, T, DbError>;
pub type DbResult<T> = Result<T, DbError>;

/// An error type that represents any database-related errors that may occur while processing a
/// tokenserver request.
Expand All @@ -20,15 +20,15 @@ pub struct DbError {
}

impl DbError {
pub(crate) fn internal(msg: String) -> Self {
pub fn internal(msg: String) -> Self {
DbErrorKind::Internal(msg).into()
}
}

#[derive(Debug, Error)]
enum DbErrorKind {
#[error("{}", _0)]
Mysql(SqlError),
SqlError(SqlError),

#[error("Unexpected error: {}", _0)]
Internal(String),
Expand All @@ -37,9 +37,9 @@ enum DbErrorKind {
impl From<DbErrorKind> for DbError {
fn from(kind: DbErrorKind) -> Self {
match kind {
DbErrorKind::Mysql(ref mysql_error) => Self {
status: mysql_error.status,
backtrace: Box::new(mysql_error.backtrace.clone()),
DbErrorKind::SqlError(ref sql_error) => Self {
status: sql_error.status,
backtrace: Box::new(sql_error.backtrace.clone()),
kind,
},
DbErrorKind::Internal(_) => Self {
Expand Down Expand Up @@ -81,24 +81,24 @@ impl_fmt_display!(DbError, DbErrorKind);
from_error!(
diesel::result::Error,
DbError,
|error: diesel::result::Error| DbError::from(DbErrorKind::Mysql(SqlError::from(error)))
|error: diesel::result::Error| DbError::from(DbErrorKind::SqlError(SqlError::from(error)))
);
from_error!(
diesel::result::ConnectionError,
DbError,
|error: diesel::result::ConnectionError| DbError::from(DbErrorKind::Mysql(SqlError::from(
|error: diesel::result::ConnectionError| DbError::from(DbErrorKind::SqlError(SqlError::from(
error
)))
);
from_error!(
diesel::r2d2::PoolError,
DbError,
|error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::Mysql(SqlError::from(error)))
|error: diesel::r2d2::PoolError| DbError::from(DbErrorKind::SqlError(SqlError::from(error)))
);
from_error!(
diesel_migrations::RunMigrationsError,
DbError,
|error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::Mysql(
|error: diesel_migrations::RunMigrationsError| DbError::from(DbErrorKind::SqlError(
SqlError::from(error)
))
);
1 change: 1 addition & 0 deletions tokenserver-db-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod error;
32 changes: 32 additions & 0 deletions tokenserver-db-mysql/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "tokenserver-db-mysql"
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

[dependencies]
backtrace.workspace = true
futures.workspace = true
http.workspace = true
serde.workspace = true
serde_derive.workspace = true
serde_json.workspace = true
slog-scope.workspace = true

async-trait = "0.1.40"
diesel = { version = "1.4", features = ["mysql", "r2d2"] }
diesel_logger = "0.1.1"
diesel_migrations = { version = "1.4.0", features = ["mysql"] }
syncserver-common = { path = "../syncserver-common" }
syncserver-db-common = { path = "../syncserver-db-common" }
thiserror = "1.0.26"
tokenserver-common = { path = "../tokenserver-common" }
tokenserver-db-common = { path = "../tokenserver-db-common" }
tokenserver-settings = { path = "../tokenserver-settings" }
tokio = { workspace = true, features = ["macros", "sync"] }

[dev-dependencies]
env_logger.workspace = true

syncserver-settings = { path = "../syncserver-settings" }
6 changes: 6 additions & 0 deletions tokenserver-db-mysql/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;

//pub mod models;
pub mod pool;

0 comments on commit e2b8563

Please sign in to comment.