Replace config.version field with constant
This commit is contained in:
parent
e78e3c5102
commit
200675464e
5 changed files with 14 additions and 20 deletions
|
@ -20,11 +20,11 @@ use crate::utils::urls::guess_protocol;
|
||||||
|
|
||||||
use super::blockchain::BlockchainConfig;
|
use super::blockchain::BlockchainConfig;
|
||||||
use super::environment::Environment;
|
use super::environment::Environment;
|
||||||
|
use super::MITRA_VERSION;
|
||||||
|
|
||||||
struct EnvConfig {
|
struct EnvConfig {
|
||||||
environment: Environment,
|
environment: Environment,
|
||||||
config_path: String,
|
config_path: String,
|
||||||
crate_version: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "production")]
|
#[cfg(feature = "production")]
|
||||||
|
@ -41,11 +41,9 @@ fn parse_env() -> EnvConfig {
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let config_path = std::env::var("CONFIG_PATH")
|
let config_path = std::env::var("CONFIG_PATH")
|
||||||
.unwrap_or(DEFAULT_CONFIG_PATH.to_string());
|
.unwrap_or(DEFAULT_CONFIG_PATH.to_string());
|
||||||
let crate_version = env!("CARGO_PKG_VERSION").to_string();
|
|
||||||
EnvConfig {
|
EnvConfig {
|
||||||
environment,
|
environment,
|
||||||
config_path,
|
config_path,
|
||||||
crate_version,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +61,6 @@ pub struct Config {
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub config_path: String,
|
pub config_path: String,
|
||||||
|
|
||||||
#[serde(skip)]
|
|
||||||
pub version: String,
|
|
||||||
|
|
||||||
// Core settings
|
// Core settings
|
||||||
pub database_url: String,
|
pub database_url: String,
|
||||||
pub storage_dir: PathBuf,
|
pub storage_dir: PathBuf,
|
||||||
|
@ -130,7 +125,6 @@ impl Config {
|
||||||
pub fn instance(&self) -> Instance {
|
pub fn instance(&self) -> Instance {
|
||||||
Instance {
|
Instance {
|
||||||
_url: self.try_instance_url().unwrap(),
|
_url: self.try_instance_url().unwrap(),
|
||||||
_version: self.version.clone(),
|
|
||||||
actor_key: self.instance_rsa_key.clone().unwrap(),
|
actor_key: self.instance_rsa_key.clone().unwrap(),
|
||||||
proxy_url: self.proxy_url.clone(),
|
proxy_url: self.proxy_url.clone(),
|
||||||
is_private: matches!(self.environment, Environment::Development),
|
is_private: matches!(self.environment, Environment::Development),
|
||||||
|
@ -161,7 +155,6 @@ impl Config {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
_url: Url,
|
_url: Url,
|
||||||
_version: String,
|
|
||||||
// Instance actor
|
// Instance actor
|
||||||
pub actor_key: RsaPrivateKey,
|
pub actor_key: RsaPrivateKey,
|
||||||
// Proxy for outgoing requests
|
// Proxy for outgoing requests
|
||||||
|
@ -190,7 +183,7 @@ impl Instance {
|
||||||
pub fn agent(&self) -> String {
|
pub fn agent(&self) -> String {
|
||||||
format!(
|
format!(
|
||||||
"Mitra {version}; {instance_url}",
|
"Mitra {version}; {instance_url}",
|
||||||
version=self._version,
|
version=MITRA_VERSION,
|
||||||
instance_url=self.url(),
|
instance_url=self.url(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -202,7 +195,6 @@ impl Instance {
|
||||||
use crate::utils::crypto_rsa::generate_weak_rsa_key;
|
use crate::utils::crypto_rsa::generate_weak_rsa_key;
|
||||||
Self {
|
Self {
|
||||||
_url: Url::parse(url).unwrap(),
|
_url: Url::parse(url).unwrap(),
|
||||||
_version: "0.0.0".to_string(),
|
|
||||||
actor_key: generate_weak_rsa_key().unwrap(),
|
actor_key: generate_weak_rsa_key().unwrap(),
|
||||||
proxy_url: None,
|
proxy_url: None,
|
||||||
is_private: true,
|
is_private: true,
|
||||||
|
@ -260,7 +252,6 @@ pub fn parse_config() -> Config {
|
||||||
// Set parameters from environment
|
// Set parameters from environment
|
||||||
config.environment = env.environment;
|
config.environment = env.environment;
|
||||||
config.config_path = env.config_path;
|
config.config_path = env.config_path;
|
||||||
config.version = env.crate_version;
|
|
||||||
|
|
||||||
// Validate config
|
// Validate config
|
||||||
if !config.storage_dir.exists() {
|
if !config.storage_dir.exists() {
|
||||||
|
@ -297,7 +288,6 @@ mod tests {
|
||||||
let instance_rsa_key = generate_weak_rsa_key().unwrap();
|
let instance_rsa_key = generate_weak_rsa_key().unwrap();
|
||||||
let instance = Instance {
|
let instance = Instance {
|
||||||
_url: instance_url,
|
_url: instance_url,
|
||||||
_version: "1.0.0".to_string(),
|
|
||||||
actor_key: instance_rsa_key,
|
actor_key: instance_rsa_key,
|
||||||
proxy_url: None,
|
proxy_url: None,
|
||||||
is_private: true,
|
is_private: true,
|
||||||
|
@ -305,7 +295,10 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(instance.url(), "https://example.com");
|
assert_eq!(instance.url(), "https://example.com");
|
||||||
assert_eq!(instance.hostname(), "example.com");
|
assert_eq!(instance.hostname(), "example.com");
|
||||||
assert_eq!(instance.agent(), "Mitra 1.0.0; https://example.com");
|
assert_eq!(
|
||||||
|
instance.agent(),
|
||||||
|
format!("Mitra {}; https://example.com", MITRA_VERSION),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -314,7 +307,6 @@ mod tests {
|
||||||
let instance_rsa_key = generate_weak_rsa_key().unwrap();
|
let instance_rsa_key = generate_weak_rsa_key().unwrap();
|
||||||
let instance = Instance {
|
let instance = Instance {
|
||||||
_url: instance_url,
|
_url: instance_url,
|
||||||
_version: "1.0.0".to_string(),
|
|
||||||
actor_key: instance_rsa_key,
|
actor_key: instance_rsa_key,
|
||||||
proxy_url: None,
|
proxy_url: None,
|
||||||
is_private: true,
|
is_private: true,
|
||||||
|
|
|
@ -9,3 +9,5 @@ pub use blockchain::{
|
||||||
};
|
};
|
||||||
pub use environment::Environment;
|
pub use environment::Environment;
|
||||||
pub use main::{parse_config, Config, Instance};
|
pub use main::{parse_config, Config, Instance};
|
||||||
|
|
||||||
|
pub const MITRA_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
|
@ -12,7 +12,7 @@ use tokio::sync::Mutex;
|
||||||
|
|
||||||
use mitra::activitypub::views as activitypub;
|
use mitra::activitypub::views as activitypub;
|
||||||
use mitra::atom::views as atom;
|
use mitra::atom::views as atom;
|
||||||
use mitra::config::{parse_config, Environment};
|
use mitra::config::{parse_config, Environment, MITRA_VERSION};
|
||||||
use mitra::database::{get_database_client, create_pool};
|
use mitra::database::{get_database_client, create_pool};
|
||||||
use mitra::database::migrate::apply_migrations;
|
use mitra::database::migrate::apply_migrations;
|
||||||
use mitra::ethereum::contracts::get_contracts;
|
use mitra::ethereum::contracts::get_contracts;
|
||||||
|
@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
};
|
};
|
||||||
log::info!(
|
log::info!(
|
||||||
"app initialized; version {}, environment = '{:?}'",
|
"app initialized; version {}, environment = '{:?}'",
|
||||||
config.version,
|
MITRA_VERSION,
|
||||||
config.environment,
|
config.environment,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{to_value, Value};
|
use serde_json::{to_value, Value};
|
||||||
|
|
||||||
use crate::config::{BlockchainConfig, Config};
|
use crate::config::{BlockchainConfig, Config, MITRA_VERSION};
|
||||||
use crate::ethereum::contracts::ContractSet;
|
use crate::ethereum::contracts::ContractSet;
|
||||||
use crate::mastodon_api::{
|
use crate::mastodon_api::{
|
||||||
MASTODON_API_VERSION,
|
MASTODON_API_VERSION,
|
||||||
|
@ -136,7 +136,7 @@ impl InstanceInfo {
|
||||||
short_description: config.instance_short_description.clone(),
|
short_description: config.instance_short_description.clone(),
|
||||||
description: markdown_to_html(&config.instance_description),
|
description: markdown_to_html(&config.instance_description),
|
||||||
description_source: config.instance_description.clone(),
|
description_source: config.instance_description.clone(),
|
||||||
version: get_full_api_version(&config.version),
|
version: get_full_api_version(MITRA_VERSION),
|
||||||
registrations: config.registrations_open,
|
registrations: config.registrations_open,
|
||||||
stats: InstanceStats {
|
stats: InstanceStats {
|
||||||
user_count,
|
user_count,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::{Config, MITRA_VERSION};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct Software {
|
struct Software {
|
||||||
|
@ -51,7 +51,7 @@ impl NodeInfo20 {
|
||||||
pub fn new(config: &Config, usage: Usage) -> Self {
|
pub fn new(config: &Config, usage: Usage) -> Self {
|
||||||
let software = Software {
|
let software = Software {
|
||||||
name: "mitra".to_string(),
|
name: "mitra".to_string(),
|
||||||
version: config.version.clone(),
|
version: MITRA_VERSION.to_string(),
|
||||||
};
|
};
|
||||||
let services = Services {
|
let services = Services {
|
||||||
inbound: vec![],
|
inbound: vec![],
|
||||||
|
|
Loading…
Reference in a new issue