Skip to content

Commit

Permalink
move config into common
Browse files Browse the repository at this point in the history
  • Loading branch information
thebino committed Aug 29, 2023
1 parent 9e841e6 commit d23a478
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ path = "src/lib.rs"
doctest = false

[dependencies]
async-trait = { workspace = true }
axum = { workspace = true }
http = { workspace = true }
async-trait.workspace = true
axum.workspace = true
http.workspace = true
sea-orm = { workspace = true, features = ["sqlx-postgres", "runtime-tokio-rustls"] }
serde = { workspace = true, features = ["derive"] }
time = { workspace = true }
serde_json.workspace = true
time.workspace = true
tracing.workspace = true
uuid = { workspace = true, features = ["serde"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//! This crate offers shared data models for [Photos.network](https://photos.network) core application.
//!
pub mod config;
pub mod http;
pub mod model {
pub mod auth;
Expand Down
2 changes: 1 addition & 1 deletion crates/database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ doctest = false

[dependencies]
async-trait = { workspace = true }
sea-orm = { workspace = true, features = ["sqlx-postgres", "runtime-tokio-rustls", "mock"] }
sea-orm = { workspace = true, features = ["sqlx-sqlite", "sqlx-postgres", "sqlx-mysql", "runtime-tokio-rustls", "macros", "mock", "with-time", "with-uuid" ] }
7 changes: 4 additions & 3 deletions crates/media/src/api/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ impl MediaApi {
where
S: Send + Sync + 'static + Clone,
{
let media_repository: MediaRepositoryState = Arc::new(MediaRepository {
let media_repository: MediaRepository = MediaRepository {
db_url: "",
db: sea_orm::DatabaseConnection::Disconnected,
});
};
let repository_state: MediaRepositoryState = Arc::new(media_repository);

Router::new()
// Returns a list of owned media items for current user
Expand Down Expand Up @@ -86,7 +87,7 @@ impl MediaApi {
// unshares the given album
.route("/albums/:entity_id/unshare", patch(patch_albums_id_unshare))
.layer(tower_http::trace::TraceLayer::new_for_http())
.with_state(media_repository)
.with_state(repository_state)
}
}

Expand Down
22 changes: 12 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ use tower_http::trace::TraceLayer;
use tracing::{debug, error, info};
use tracing_subscriber::{fmt, layer::SubscriberExt};

use config::configuration::Configuration;
use common::config::configuration::Configuration;
use plugin::plugin_manager::PluginManager;

pub mod config;
pub mod plugin;

const CONFIG_PATH: &str = "./config/core.json";
Expand Down Expand Up @@ -92,20 +91,20 @@ pub async fn start_server() -> Result<()> {
fs::create_dir_all("plugins")?;

// read config file
let config = Configuration::new(CONFIG_PATH).expect("Could not parse configuration!");
debug!("Configuration: {}", config);
let configuration = Configuration::new(CONFIG_PATH).expect("Could not parse configuration!");
debug!("Configuration: {}", configuration);

// init application state
let mut app_state = ApplicationState::new(config.clone());
let mut app_state = ApplicationState::new(configuration.clone());

let cfg = ServerConfig {
listen_addr: config.internal_url.to_owned(),
domain: config.external_url.to_owned(),
listen_addr: configuration.internal_url.to_owned(),
domain: configuration.external_url.to_owned(),
use_ssl: true,
realm_keys_base_path: Path::new("config").to_path_buf(),
realms: vec![ConfigRealm {
name: String::from("master"),
domain: Some(config.external_url.to_owned()),
domain: Some(configuration.external_url.to_owned()),
clients: vec![Client {
id: String::from("mobile-app"),
secret: None,
Expand Down Expand Up @@ -151,8 +150,11 @@ pub async fn start_server() -> Result<()> {
app_state.router = Some(router);

// initialize plugin manager
let mut plugin_manager =
PluginManager::new(config.clone(), PLUGIN_PATH.to_string(), &mut app_state)?;
let mut plugin_manager = PluginManager::new(
configuration.clone(),
PLUGIN_PATH.to_string(),
&mut app_state,
)?;

match plugin_manager.init().await {
Ok(_) => info!("PluginManager: initialization succed."),
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use std::path::PathBuf;
use abi_stable::library::{lib_header_from_path, LibrarySuffix, RawLibrary};

use anyhow::Result;
use common::config::configuration::Configuration;

use crate::{config::configuration::Configuration, ApplicationState};
use crate::ApplicationState;
use core_extensions::SelfOps;
use photos_network_plugin::{PluginFactoryRef, PluginId};
use tracing::{debug, error, info};
Expand Down

0 comments on commit d23a478

Please sign in to comment.