Replace config.version field with constant

This commit is contained in:
silverpill 2023-01-25 01:05:21 +00:00
parent e78e3c5102
commit 200675464e
5 changed files with 14 additions and 20 deletions

View file

@ -20,11 +20,11 @@ use crate::utils::urls::guess_protocol;
use super::blockchain::BlockchainConfig;
use super::environment::Environment;
use super::MITRA_VERSION;
struct EnvConfig {
environment: Environment,
config_path: String,
crate_version: String,
}
#[cfg(feature = "production")]
@ -41,11 +41,9 @@ fn parse_env() -> EnvConfig {
.unwrap_or_default();
let config_path = std::env::var("CONFIG_PATH")
.unwrap_or(DEFAULT_CONFIG_PATH.to_string());
let crate_version = env!("CARGO_PKG_VERSION").to_string();
EnvConfig {
environment,
config_path,
crate_version,
}
}
@ -63,9 +61,6 @@ pub struct Config {
#[serde(skip)]
pub config_path: String,
#[serde(skip)]
pub version: String,
// Core settings
pub database_url: String,
pub storage_dir: PathBuf,
@ -130,7 +125,6 @@ impl Config {
pub fn instance(&self) -> Instance {
Instance {
_url: self.try_instance_url().unwrap(),
_version: self.version.clone(),
actor_key: self.instance_rsa_key.clone().unwrap(),
proxy_url: self.proxy_url.clone(),
is_private: matches!(self.environment, Environment::Development),
@ -161,7 +155,6 @@ impl Config {
#[derive(Clone)]
pub struct Instance {
_url: Url,
_version: String,
// Instance actor
pub actor_key: RsaPrivateKey,
// Proxy for outgoing requests
@ -190,7 +183,7 @@ impl Instance {
pub fn agent(&self) -> String {
format!(
"Mitra {version}; {instance_url}",
version=self._version,
version=MITRA_VERSION,
instance_url=self.url(),
)
}
@ -202,7 +195,6 @@ impl Instance {
use crate::utils::crypto_rsa::generate_weak_rsa_key;
Self {
_url: Url::parse(url).unwrap(),
_version: "0.0.0".to_string(),
actor_key: generate_weak_rsa_key().unwrap(),
proxy_url: None,
is_private: true,
@ -260,7 +252,6 @@ pub fn parse_config() -> Config {
// Set parameters from environment
config.environment = env.environment;
config.config_path = env.config_path;
config.version = env.crate_version;
// Validate config
if !config.storage_dir.exists() {
@ -297,7 +288,6 @@ mod tests {
let instance_rsa_key = generate_weak_rsa_key().unwrap();
let instance = Instance {
_url: instance_url,
_version: "1.0.0".to_string(),
actor_key: instance_rsa_key,
proxy_url: None,
is_private: true,
@ -305,7 +295,10 @@ mod tests {
assert_eq!(instance.url(), "https://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]
@ -314,7 +307,6 @@ mod tests {
let instance_rsa_key = generate_weak_rsa_key().unwrap();
let instance = Instance {
_url: instance_url,
_version: "1.0.0".to_string(),
actor_key: instance_rsa_key,
proxy_url: None,
is_private: true,

View file

@ -9,3 +9,5 @@ pub use blockchain::{
};
pub use environment::Environment;
pub use main::{parse_config, Config, Instance};
pub const MITRA_VERSION: &str = env!("CARGO_PKG_VERSION");

View file

@ -12,7 +12,7 @@ use tokio::sync::Mutex;
use mitra::activitypub::views as activitypub;
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::migrate::apply_migrations;
use mitra::ethereum::contracts::get_contracts;
@ -53,7 +53,7 @@ async fn main() -> std::io::Result<()> {
};
log::info!(
"app initialized; version {}, environment = '{:?}'",
config.version,
MITRA_VERSION,
config.environment,
);

View file

@ -1,7 +1,7 @@
use serde::Serialize;
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::mastodon_api::{
MASTODON_API_VERSION,
@ -136,7 +136,7 @@ impl InstanceInfo {
short_description: config.instance_short_description.clone(),
description: markdown_to_html(&config.instance_description),
description_source: config.instance_description.clone(),
version: get_full_api_version(&config.version),
version: get_full_api_version(MITRA_VERSION),
registrations: config.registrations_open,
stats: InstanceStats {
user_count,

View file

@ -2,7 +2,7 @@
use serde::Serialize;
use crate::config::Config;
use crate::config::{Config, MITRA_VERSION};
#[derive(Serialize)]
struct Software {
@ -51,7 +51,7 @@ impl NodeInfo20 {
pub fn new(config: &Config, usage: Usage) -> Self {
let software = Software {
name: "mitra".to_string(),
version: config.version.clone(),
version: MITRA_VERSION.to_string(),
};
let services = Services {
inbound: vec![],