Skip to content

Commit

Permalink
refactor: shuttle-common/backend -> shuttle-backends (#1698)
Browse files Browse the repository at this point in the history
* wip: move backends feature to crate

* move test utils to backends

* resolve imports

* trim dev deps

* fix: ci tests

* fix: rebase conflicts
  • Loading branch information
jonaro00 committed Mar 21, 2024
1 parent 29646a3 commit ee7809d
Show file tree
Hide file tree
Showing 71 changed files with 732 additions and 724 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,10 @@ workflows:
parameters:
crate:
# - shuttle-admin # no tests
- shuttle-backends
- shuttle-codegen
- shuttle-common
# - shuttle-common-tests # no tests
# - shuttle-gateway # TODO: move docker-dependant tests to integration tests and activate this
- test-workspace-member-with-integration:
name: << matrix.crate >>
matrix:
Expand Down
65 changes: 51 additions & 14 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver = "2"
members = [
"admin",
"auth",
"auth", "backends",
"cargo-shuttle",
"codegen",
"common",
Expand Down Expand Up @@ -30,6 +30,7 @@ repository = "https://github.com/shuttle-hq/shuttle"

# https://doc.rust-lang.org/cargo/reference/workspaces.html#the-workspacedependencies-table
[workspace.dependencies]
shuttle-backends = { path = "backends", version = "0.42.0" }
shuttle-codegen = { path = "codegen", version = "0.42.0" }
shuttle-common = { path = "common", version = "0.42.0" }
shuttle-common-tests = { path = "common-tests", version = "0.42.0" }
Expand Down
1 change: 1 addition & 0 deletions admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "shuttle-admin"
version = "0.42.0"
edition = "2021"
publish = false

[dependencies]
shuttle-common = { workspace = true, features = ["models"] }
Expand Down
10 changes: 4 additions & 6 deletions auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ version = "0.42.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
publish = false

[dependencies]
shuttle-common = { workspace = true, features = [
"backend",
"models",
"persist",
] }
shuttle-backends = { workspace = true }
shuttle-common = { workspace = true, features = ["models", "persist"] }

anyhow = { workspace = true }
async-stripe = { version = "0.25.1", default-features = false, features = ["checkout", "runtime-tokio-hyper-rustls"] }
Expand Down Expand Up @@ -41,7 +39,7 @@ once_cell = { workspace = true }
portpicker = { workspace = true }
pretty_assertions = { workspace = true }
serde_json = { workspace = true }
shuttle-common = { workspace = true, features = ["test-utils"] }
shuttle-backends = { workspace = true, features = ["test-utils"] }
shuttle-common-tests = { workspace = true }
tower = { workspace = true, features = ["util"] }
wiremock = { workspace = true }
8 changes: 3 additions & 5 deletions auth/src/api/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use axum::{
routing::{delete, get, post, put},
Router, Server,
};
use shuttle_common::{
backends::{
client::PermissionsDal,
metrics::{Metrics, TraceLayer},
},
use shuttle_backends::{
client::PermissionsDal,
metrics::{Metrics, TraceLayer},
request_span,
};
use sqlx::PgPool;
Expand Down
4 changes: 2 additions & 2 deletions auth/src/api/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub(crate) async fn convert_key(
State(user_manager): State<UserManagerState>,
State(key_manager): State<KeyManagerState>,
key: Key,
) -> Result<Json<shuttle_common::backends::auth::ConvertResponse>, StatusCode> {
) -> Result<Json<shuttle_backends::auth::ConvertResponse>, StatusCode> {
let user = user_manager
.get_user_by_key(key.into())
.await
Expand All @@ -105,7 +105,7 @@ pub(crate) async fn convert_key(

let token = claim.into_token(key_manager.private_key())?;

let response = shuttle_common::backends::auth::ConvertResponse { token };
let response = shuttle_backends::auth::ConvertResponse { token };

Ok(Json(response))
}
Expand Down
2 changes: 1 addition & 1 deletion auth/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};

use serde::{ser::SerializeMap, Serialize};
use shuttle_common::backends::client;
use shuttle_backends::client;
use shuttle_common::models::error::ApiError;
use stripe::StripeError;

Expand Down
3 changes: 2 additions & 1 deletion auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ mod user;
use std::io;

use args::StartArgs;
use shuttle_common::{backends::client::permit, claims::AccountTier, ApiKey};
use shuttle_backends::client::permit;
use shuttle_common::{claims::AccountTier, ApiKey};
use sqlx::{migrate::Migrator, query, PgPool};
use tracing::info;
pub use user::User;
Expand Down
3 changes: 2 additions & 1 deletion auth/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::io;

use clap::Parser;
use shuttle_common::{backends::trace::setup_tracing, claims::AccountTier, log::Backend};
use shuttle_backends::trace::setup_tracing;
use shuttle_common::{claims::AccountTier, log::Backend};
use sqlx::migrate::Migrator;
use tracing::trace;

Expand Down
8 changes: 2 additions & 6 deletions auth/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ use axum::{
TypedHeader,
};
use chrono::{DateTime, Utc};
use shuttle_backends::{client::PermissionsDal, headers::XShuttleAdminSecret};
use shuttle_common::{
backends::{client::PermissionsDal, headers::XShuttleAdminSecret},
claims::AccountTier,
limits::Limits,
models,
models::user::UserId,
ApiKey, Secret,
claims::AccountTier, limits::Limits, models, models::user::UserId, ApiKey, Secret,
};
use sqlx::{postgres::PgRow, query, FromRow, PgPool, Row};
use stripe::{SubscriptionId, SubscriptionStatus};
Expand Down
3 changes: 1 addition & 2 deletions auth/tests/api/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use hyper::http::{header::AUTHORIZATION, Request};
use once_cell::sync::Lazy;
use serde_json::{json, Value};
use shuttle_auth::{pgpool_init, ApiBuilder};
use shuttle_backends::{headers::X_SHUTTLE_ADMIN_SECRET, test_utils::gateway::PermissionsMock};
use shuttle_common::{
backends::headers::X_SHUTTLE_ADMIN_SECRET,
claims::{AccountTier, Claim},
models::user,
test_utils::PermissionsMock,
};
use shuttle_common_tests::postgres::DockerInstance;
use sqlx::query;
Expand Down
56 changes: 56 additions & 0 deletions backends/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[package]
name = "shuttle-backends"
version = "0.42.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
publish = false

[dependencies]
shuttle-common = { workspace = true, features = ["axum", "claims", "models"] }
shuttle-proto = { workspace = true, features = ["resource-recorder-client"] }

anyhow = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true, features = ["matched-path"] }
bytes = { workspace = true }
headers = { workspace = true }
http = { workspace = true }
http-body = { workspace = true }
hyper = { workspace = true }
opentelemetry = { workspace = true }
opentelemetry_sdk = { workspace = true }
opentelemetry-appender-tracing = { workspace = true }
opentelemetry-http = { workspace = true }
opentelemetry-otlp = { workspace = true }
pin-project = { workspace = true }
portpicker = { workspace = true, optional = true }
reqwest = { workspace = true, features = ["json"] }
# keep locked to not accidentally invalidate someone's project name
rustrict = { version = "=0.7.12" }
serde = { workspace = true, features = ["derive", "std"] }
serde_json = { workspace = true }
sqlx = { workspace = true, optional = true }
strum = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tonic = { workspace = true }
tower = { workspace = true }
tower-http = { workspace = true }
tracing = { workspace = true, features = ["std"] }
tracing-opentelemetry = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"]}
ttl_cache = { workspace = true }
wiremock = { workspace = true, optional = true }

[features]
sqlx = ["dep:sqlx"]
test-utils = ["portpicker", "wiremock"]

[dev-dependencies]
base64 = { workspace = true }
jsonwebtoken = { workspace = true }
ring = { workspace = true }
serial_test = "3.0.0"
test-context = { workspace = true }
tracing-fluent-assertions = "0.3.0"
Loading

0 comments on commit ee7809d

Please sign in to comment.