mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 22:39:46 +00:00
adds warnings for extra manifest keys (#1278)
* adds warnings for extra manifest keys * default to warn log level if env not specified
This commit is contained in:
committed by
GitHub
parent
6ef7da9732
commit
798e17f636
24
backend/Cargo.lock
generated
24
backend/Cargo.lock
generated
@@ -404,14 +404,31 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ciborium"
|
name = "ciborium"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "de6836a1b6197d8acdaac74a01af077a26aa6953d2e9251eef061c646b0d432c"
|
checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"half",
|
"ciborium-io",
|
||||||
|
"ciborium-ll",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ciborium-io"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ciborium-ll"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b"
|
||||||
|
dependencies = [
|
||||||
|
"ciborium-io",
|
||||||
|
"half",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cipher"
|
name = "cipher"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@@ -867,6 +884,7 @@ dependencies = [
|
|||||||
"http",
|
"http",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-ws-listener",
|
"hyper-ws-listener",
|
||||||
|
"imbl",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"isocountry",
|
"isocountry",
|
||||||
"itertools 0.10.1",
|
"itertools 0.10.1",
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ hmac = "0.11.0"
|
|||||||
http = "0.2.5"
|
http = "0.2.5"
|
||||||
hyper = "0.14.13"
|
hyper = "0.14.13"
|
||||||
hyper-ws-listener = { git = "https://github.com/Start9Labs/hyper-ws-listener.git", branch = "main" }
|
hyper-ws-listener = { git = "https://github.com/Start9Labs/hyper-ws-listener.git", branch = "main" }
|
||||||
|
imbl = "1.0.1"
|
||||||
indexmap = { version = "1.7.0", features = ["serde"] }
|
indexmap = { version = "1.7.0", features = ["serde"] }
|
||||||
isocountry = "0.3.2"
|
isocountry = "0.3.2"
|
||||||
itertools = "0.10.1"
|
itertools = "0.10.1"
|
||||||
@@ -100,7 +101,7 @@ rpc-toolkit = { version = "*", path = "../rpc-toolkit/rpc-toolkit" }
|
|||||||
rust-argon2 = "0.8.3"
|
rust-argon2 = "0.8.3"
|
||||||
scopeguard = "1.1" # because avahi-sys fucks your shit up
|
scopeguard = "1.1" # because avahi-sys fucks your shit up
|
||||||
serde = { version = "1.0.130", features = ["derive", "rc"] }
|
serde = { version = "1.0.130", features = ["derive", "rc"] }
|
||||||
serde_cbor = { package = "ciborium", version = "0.1.0" }
|
serde_cbor = { package = "ciborium", version = "0.2.0" }
|
||||||
serde_json = "1.0.68"
|
serde_json = "1.0.68"
|
||||||
serde_toml = { package = "toml", version = "0.5.8" }
|
serde_toml = { package = "toml", version = "0.5.8" }
|
||||||
serde_yaml = "0.8.21"
|
serde_yaml = "0.8.21"
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ fn inner_main() -> Result<(), Error> {
|
|||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
),
|
),
|
||||||
context: matches => {
|
context: matches => {
|
||||||
|
if let Err(_) = std::env::var("RUST_LOG") {
|
||||||
|
std::env::set_var("RUST_LOG", "embassy=warn");
|
||||||
|
}
|
||||||
EmbassyLogger::init();
|
EmbassyLogger::init();
|
||||||
SdkContext::init(matches)?
|
SdkContext::init(matches)?
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use color_eyre::eyre::eyre;
|
use color_eyre::eyre::eyre;
|
||||||
|
use imbl::OrdMap;
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
|
use serde_json::Value;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::context::SdkContext;
|
use crate::context::SdkContext;
|
||||||
@@ -9,6 +11,7 @@ use crate::s9pk::builder::S9pkPacker;
|
|||||||
use crate::s9pk::manifest::Manifest;
|
use crate::s9pk::manifest::Manifest;
|
||||||
use crate::s9pk::reader::S9pkReader;
|
use crate::s9pk::reader::S9pkReader;
|
||||||
use crate::util::display_none;
|
use crate::util::display_none;
|
||||||
|
use crate::util::serde::IoFormat;
|
||||||
use crate::volume::Volume;
|
use crate::volume::Volume;
|
||||||
use crate::{Error, ResultExt};
|
use crate::{Error, ResultExt};
|
||||||
|
|
||||||
@@ -30,22 +33,25 @@ pub fn pack(#[context] ctx: SdkContext, #[arg] path: Option<PathBuf>) -> Result<
|
|||||||
} else {
|
} else {
|
||||||
std::env::current_dir()?
|
std::env::current_dir()?
|
||||||
};
|
};
|
||||||
let manifest: Manifest = if path.join("manifest.toml").exists() {
|
let manifest_value: Value = if path.join("manifest.toml").exists() {
|
||||||
let mut s = String::new();
|
IoFormat::Toml.from_reader(File::open(path.join("manifest.toml"))?)?
|
||||||
File::open(path.join("manifest.toml"))?.read_to_string(&mut s)?;
|
|
||||||
serde_toml::from_str(&s).with_kind(crate::ErrorKind::Deserialization)?
|
|
||||||
} else if path.join("manifest.yaml").exists() {
|
} else if path.join("manifest.yaml").exists() {
|
||||||
serde_yaml::from_reader(File::open(path.join("manifest.yaml"))?)
|
IoFormat::Yaml.from_reader(File::open(path.join("manifest.yaml"))?)?
|
||||||
.with_kind(crate::ErrorKind::Deserialization)?
|
|
||||||
} else if path.join("manifest.json").exists() {
|
} else if path.join("manifest.json").exists() {
|
||||||
serde_json::from_reader(File::open(path.join("manifest.json"))?)
|
IoFormat::Json.from_reader(File::open(path.join("manifest.json"))?)?
|
||||||
.with_kind(crate::ErrorKind::Deserialization)?
|
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
eyre!("manifest not found"),
|
eyre!("manifest not found"),
|
||||||
crate::ErrorKind::Pack,
|
crate::ErrorKind::Pack,
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
let manifest: Manifest = serde_json::from_value(manifest_value.clone())
|
||||||
|
.with_kind(crate::ErrorKind::Deserialization)?;
|
||||||
|
let extra_keys =
|
||||||
|
enumerate_extra_keys(&serde_json::to_value(&manifest).unwrap(), &manifest_value);
|
||||||
|
for k in extra_keys {
|
||||||
|
tracing::warn!("Unrecognized Manifest Key: {}", k);
|
||||||
|
}
|
||||||
|
|
||||||
let outfile_path = path.join(format!("{}.s9pk", manifest.id));
|
let outfile_path = path.join(format!("{}.s9pk", manifest.id));
|
||||||
let mut outfile = File::create(outfile_path)?;
|
let mut outfile = File::create(outfile_path)?;
|
||||||
@@ -114,3 +120,45 @@ pub async fn verify(#[arg] path: PathBuf) -> Result<(), Error> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn enumerate_extra_keys(reference: &Value, candidate: &Value) -> Vec<String> {
|
||||||
|
match (reference, candidate) {
|
||||||
|
(Value::Object(m_r), Value::Object(m_c)) => {
|
||||||
|
let om_r: OrdMap<String, Value> = m_r.clone().into_iter().collect();
|
||||||
|
let om_c: OrdMap<String, Value> = m_c.clone().into_iter().collect();
|
||||||
|
let common = om_r.clone().intersection(om_c.clone());
|
||||||
|
let top_extra = common.clone().symmetric_difference(om_c.clone());
|
||||||
|
let mut all_extra = top_extra
|
||||||
|
.keys()
|
||||||
|
.map(|s| format!(".{}", s))
|
||||||
|
.collect::<Vec<String>>();
|
||||||
|
for (k, v) in common {
|
||||||
|
all_extra.extend(
|
||||||
|
enumerate_extra_keys(&v, om_c.get(&k).unwrap())
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| format!(".{}{}", k, s)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
all_extra
|
||||||
|
}
|
||||||
|
(_, Value::Object(m1)) => m1.clone().keys().map(|s| format!(".{}", s)).collect(),
|
||||||
|
_ => Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_enumerate_extra_keys() {
|
||||||
|
use serde_json::json;
|
||||||
|
let extras = enumerate_extra_keys(
|
||||||
|
&json!({
|
||||||
|
"test": 1,
|
||||||
|
"test2": null,
|
||||||
|
}),
|
||||||
|
&json!({
|
||||||
|
"test": 1,
|
||||||
|
"test2": { "test3": null },
|
||||||
|
"test4": null
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
println!("{:?}", extras)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use tracing::metadata::LevelFilter;
|
||||||
use tracing::Subscriber;
|
use tracing::Subscriber;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user