mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
preliminary support for tor key pointers
This commit is contained in:
committed by
Aiden McClelland
parent
4c29d8c372
commit
79db44e34f
@@ -6,7 +6,7 @@ use bollard::container::KillContainerOptions;
|
|||||||
use futures::future::{BoxFuture, FutureExt};
|
use futures::future::{BoxFuture, FutureExt};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use patch_db::DbHandle;
|
use patch_db::{DbHandle, ModelData, OptionModel};
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use rpc_toolkit::command;
|
use rpc_toolkit::command;
|
||||||
@@ -21,7 +21,7 @@ use crate::db::util::WithRevision;
|
|||||||
use crate::dependencies::{
|
use crate::dependencies::{
|
||||||
update_current_dependents, BreakageRes, DependencyError, TaggedDependencyError,
|
update_current_dependents, BreakageRes, DependencyError, TaggedDependencyError,
|
||||||
};
|
};
|
||||||
use crate::s9pk::manifest::PackageId;
|
use crate::s9pk::manifest::{Manifest, ManifestModel, PackageId};
|
||||||
use crate::status::handle_broken_dependents;
|
use crate::status::handle_broken_dependents;
|
||||||
use crate::util::{
|
use crate::util::{
|
||||||
display_none, display_serializable, parse_duration, parse_stdin_deserializable, IoFormat,
|
display_none, display_serializable, parse_duration, parse_stdin_deserializable, IoFormat,
|
||||||
@@ -63,6 +63,8 @@ pub enum ConfigurationError {
|
|||||||
NoMatch(#[from] NoMatchWithPath),
|
NoMatch(#[from] NoMatchWithPath),
|
||||||
#[error("System Error: {0}")]
|
#[error("System Error: {0}")]
|
||||||
SystemError(Error),
|
SystemError(Error),
|
||||||
|
#[error("Permission Denied: {0}")]
|
||||||
|
PermissionDenied(ValueSpecPointer),
|
||||||
}
|
}
|
||||||
impl From<ConfigurationError> for Error {
|
impl From<ConfigurationError> for Error {
|
||||||
fn from(err: ConfigurationError) -> Self {
|
fn from(err: ConfigurationError) -> Self {
|
||||||
@@ -326,8 +328,20 @@ pub fn configure<'a, Db: DbHandle>(
|
|||||||
spec.gen(&mut rand::rngs::StdRng::from_entropy(), timeout)?
|
spec.gen(&mut rand::rngs::StdRng::from_entropy(), timeout)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let manifest = crate::db::DatabaseModel::new()
|
||||||
|
.package_data()
|
||||||
|
.idx_model(id)
|
||||||
|
.and_then(|m| m.installed())
|
||||||
|
.map::<_, Manifest>(|i| i.manifest())
|
||||||
|
.expect(db)
|
||||||
|
.await?
|
||||||
|
.get(db, true)
|
||||||
|
.await
|
||||||
|
.with_kind(crate::ErrorKind::NotFound)?;
|
||||||
|
|
||||||
spec.matches(&config)?; // check that new config matches spec
|
spec.matches(&config)?; // check that new config matches spec
|
||||||
spec.update(ctx, db, &*overrides, &mut config).await?; // dereference pointers in the new config
|
spec.update(ctx, db, &*manifest, &*overrides, &mut config)
|
||||||
|
.await?; // dereference pointers in the new config
|
||||||
|
|
||||||
// create backreferences to pointers
|
// create backreferences to pointers
|
||||||
let mut sys = pkg_model.clone().system_pointers().get_mut(db).await?;
|
let mut sys = pkg_model.clone().system_pointers().get_mut(db).await?;
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ use async_trait::async_trait;
|
|||||||
use indexmap::{IndexMap, IndexSet};
|
use indexmap::{IndexMap, IndexSet};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use jsonpath_lib::Compiled as CompiledJsonPath;
|
use jsonpath_lib::Compiled as CompiledJsonPath;
|
||||||
use lazy_static::__Deref;
|
|
||||||
use patch_db::{DbHandle, OptionModel};
|
use patch_db::{DbHandle, OptionModel};
|
||||||
use rand::{CryptoRng, Rng};
|
use rand::{CryptoRng, Rng};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use serde_json::{Number, Value};
|
use serde_json::{Number, Value};
|
||||||
|
use sqlx::SqlitePool;
|
||||||
|
|
||||||
use super::util::{self, CharSet, NumRange, UniqueBy, STATIC_NULL};
|
use super::util::{self, CharSet, NumRange, UniqueBy, STATIC_NULL};
|
||||||
use super::{Config, MatchError, NoMatchWithPath, TimeoutError, TypeOf};
|
use super::{Config, MatchError, NoMatchWithPath, TimeoutError, TypeOf};
|
||||||
@@ -41,6 +41,7 @@ pub trait ValueSpec {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError>;
|
) -> Result<(), ConfigurationError>;
|
||||||
@@ -156,10 +157,13 @@ where
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
self.inner.update(ctx, db, config_overrides, value).await
|
self.inner
|
||||||
|
.update(ctx, db, manifest, config_overrides, value)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
self.inner.pointers(value)
|
self.inner.pointers(value)
|
||||||
@@ -197,10 +201,13 @@ where
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
self.inner.update(ctx, db, config_overrides, value).await
|
self.inner
|
||||||
|
.update(ctx, db, manifest, config_overrides, value)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
self.inner.pointers(value)
|
self.inner.pointers(value)
|
||||||
@@ -271,10 +278,13 @@ where
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
self.inner.update(ctx, db, config_overrides, value).await
|
self.inner
|
||||||
|
.update(ctx, db, manifest, config_overrides, value)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
self.inner.pointers(value)
|
self.inner.pointers(value)
|
||||||
@@ -382,18 +392,19 @@ impl ValueSpec for ValueSpecAny {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
match self {
|
match self {
|
||||||
ValueSpecAny::Boolean(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::Boolean(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::Enum(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::Enum(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::List(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::List(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::Number(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::Number(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::Object(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::Object(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::String(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::String(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::Union(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::Union(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecAny::Pointer(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecAny::Pointer(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
@@ -473,8 +484,9 @@ impl ValueSpec for ValueSpecBoolean {
|
|||||||
}
|
}
|
||||||
async fn update<Db: DbHandle>(
|
async fn update<Db: DbHandle>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
_ctx: &RpcContext,
|
||||||
_db: &mut Db,
|
_db: &mut Db,
|
||||||
|
_manifest: &Manifest,
|
||||||
_config_overrides: &BTreeMap<PackageId, Config>,
|
_config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
_value: &mut Value,
|
_value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
@@ -561,8 +573,9 @@ impl ValueSpec for ValueSpecEnum {
|
|||||||
}
|
}
|
||||||
async fn update<Db: DbHandle>(
|
async fn update<Db: DbHandle>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
_ctx: &RpcContext,
|
||||||
_db: &mut Db,
|
_db: &mut Db,
|
||||||
|
_manifest: &Manifest,
|
||||||
_config_overrides: &BTreeMap<PackageId, Config>,
|
_config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
_value: &mut Value,
|
_value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
@@ -648,12 +661,17 @@ where
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
if let Value::Array(ref mut ls) = value {
|
if let Value::Array(ref mut ls) = value {
|
||||||
for (i, val) in ls.into_iter().enumerate() {
|
for (i, val) in ls.into_iter().enumerate() {
|
||||||
match self.spec.update(ctx, db, config_overrides, val).await {
|
match self
|
||||||
|
.spec
|
||||||
|
.update(ctx, db, manifest, config_overrides, val)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Err(ConfigurationError::NoMatch(e)) => {
|
Err(ConfigurationError::NoMatch(e)) => {
|
||||||
Err(ConfigurationError::NoMatch(e.prepend(format!("{}", i))))
|
Err(ConfigurationError::NoMatch(e.prepend(format!("{}", i))))
|
||||||
}
|
}
|
||||||
@@ -750,15 +768,16 @@ impl ValueSpec for ValueSpecList {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
match self {
|
match self {
|
||||||
ValueSpecList::Enum(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecList::Enum(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecList::Number(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecList::Number(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecList::Object(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecList::Object(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecList::String(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecList::String(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
ValueSpecList::Union(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecList::Union(a) => a.update(ctx, db, manifest, config_overrides, value).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
@@ -871,8 +890,9 @@ impl ValueSpec for ValueSpecNumber {
|
|||||||
}
|
}
|
||||||
async fn update<Db: DbHandle>(
|
async fn update<Db: DbHandle>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
_ctx: &RpcContext,
|
||||||
_db: &mut Db,
|
_db: &mut Db,
|
||||||
|
_manifest: &Manifest,
|
||||||
_config_overrides: &BTreeMap<PackageId, Config>,
|
_config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
_value: &mut Value,
|
_value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
@@ -935,11 +955,14 @@ impl ValueSpec for ValueSpecObject {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
if let Value::Object(o) = value {
|
if let Value::Object(o) = value {
|
||||||
self.spec.update(ctx, db, config_overrides, o).await
|
self.spec
|
||||||
|
.update(ctx, db, manifest, config_overrides, o)
|
||||||
|
.await
|
||||||
} else {
|
} else {
|
||||||
Err(ConfigurationError::NoMatch(NoMatchWithPath::new(
|
Err(ConfigurationError::NoMatch(NoMatchWithPath::new(
|
||||||
MatchError::InvalidType("object", value.type_of()),
|
MatchError::InvalidType("object", value.type_of()),
|
||||||
@@ -1034,6 +1057,7 @@ impl ConfigSpec {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
cfg: &mut Config,
|
cfg: &mut Config,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
@@ -1041,10 +1065,11 @@ impl ConfigSpec {
|
|||||||
match cfg.get_mut(k) {
|
match cfg.get_mut(k) {
|
||||||
None => {
|
None => {
|
||||||
let mut v = Value::Null;
|
let mut v = Value::Null;
|
||||||
vs.update(ctx, db, config_overrides, &mut v).await?;
|
vs.update(ctx, db, manifest, config_overrides, &mut v)
|
||||||
|
.await?;
|
||||||
cfg.insert(k.clone(), v);
|
cfg.insert(k.clone(), v);
|
||||||
}
|
}
|
||||||
Some(v) => match vs.update(ctx, db, config_overrides, v).await {
|
Some(v) => match vs.update(ctx, db, manifest, config_overrides, v).await {
|
||||||
Err(ConfigurationError::NoMatch(e)) => {
|
Err(ConfigurationError::NoMatch(e)) => {
|
||||||
Err(ConfigurationError::NoMatch(e.prepend(k.clone())))
|
Err(ConfigurationError::NoMatch(e.prepend(k.clone())))
|
||||||
}
|
}
|
||||||
@@ -1124,8 +1149,9 @@ impl ValueSpec for ValueSpecString {
|
|||||||
}
|
}
|
||||||
async fn update<Db: DbHandle>(
|
async fn update<Db: DbHandle>(
|
||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
_ctx: &RpcContext,
|
||||||
_db: &mut Db,
|
_db: &mut Db,
|
||||||
|
_manifest: &Manifest,
|
||||||
_config_overrides: &BTreeMap<PackageId, Config>,
|
_config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
_value: &mut Value,
|
_value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
@@ -1336,6 +1362,7 @@ impl ValueSpec for ValueSpecUnion {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
@@ -1348,7 +1375,7 @@ impl ValueSpec for ValueSpecUnion {
|
|||||||
None => Err(ConfigurationError::NoMatch(NoMatchWithPath::new(
|
None => Err(ConfigurationError::NoMatch(NoMatchWithPath::new(
|
||||||
MatchError::Union(tag.clone(), self.variants.keys().cloned().collect()),
|
MatchError::Union(tag.clone(), self.variants.keys().cloned().collect()),
|
||||||
))),
|
))),
|
||||||
Some(spec) => spec.update(ctx, db, config_overrides, o).await,
|
Some(spec) => spec.update(ctx, db, manifest, config_overrides, o).await,
|
||||||
},
|
},
|
||||||
Some(other) => Err(ConfigurationError::NoMatch(
|
Some(other) => Err(ConfigurationError::NoMatch(
|
||||||
NoMatchWithPath::new(MatchError::InvalidType("string", other.type_of()))
|
NoMatchWithPath::new(MatchError::InvalidType("string", other.type_of()))
|
||||||
@@ -1477,12 +1504,17 @@ impl ValueSpec for ValueSpecPointer {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
match self {
|
match self {
|
||||||
ValueSpecPointer::Package(a) => a.update(ctx, db, config_overrides, value).await,
|
ValueSpecPointer::Package(a) => {
|
||||||
ValueSpecPointer::System(a) => a.update(ctx, db, config_overrides, value).await,
|
a.update(ctx, db, manifest, config_overrides, value).await
|
||||||
|
}
|
||||||
|
ValueSpecPointer::System(a) => {
|
||||||
|
a.update(ctx, db, manifest, config_overrides, value).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn pointers(&self, _value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, _value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
@@ -1505,6 +1537,7 @@ impl ValueSpec for ValueSpecPointer {
|
|||||||
#[serde(tag = "target")]
|
#[serde(tag = "target")]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum PackagePointerSpec {
|
pub enum PackagePointerSpec {
|
||||||
|
TorKey(TorKeyPointer),
|
||||||
TorAddress(TorAddressPointer),
|
TorAddress(TorAddressPointer),
|
||||||
LanAddress(LanAddressPointer),
|
LanAddress(LanAddressPointer),
|
||||||
Config(ConfigPointer),
|
Config(ConfigPointer),
|
||||||
@@ -1512,6 +1545,7 @@ pub enum PackagePointerSpec {
|
|||||||
impl PackagePointerSpec {
|
impl PackagePointerSpec {
|
||||||
pub fn package_id(&self) -> &PackageId {
|
pub fn package_id(&self) -> &PackageId {
|
||||||
match self {
|
match self {
|
||||||
|
PackagePointerSpec::TorKey(TorKeyPointer { package_id, .. }) => package_id,
|
||||||
PackagePointerSpec::TorAddress(TorAddressPointer { package_id, .. }) => package_id,
|
PackagePointerSpec::TorAddress(TorAddressPointer { package_id, .. }) => package_id,
|
||||||
PackagePointerSpec::LanAddress(LanAddressPointer { package_id, .. }) => package_id,
|
PackagePointerSpec::LanAddress(LanAddressPointer { package_id, .. }) => package_id,
|
||||||
PackagePointerSpec::Config(ConfigPointer { package_id, .. }) => package_id,
|
PackagePointerSpec::Config(ConfigPointer { package_id, .. }) => package_id,
|
||||||
@@ -1521,9 +1555,11 @@ impl PackagePointerSpec {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
) -> Result<Value, ConfigurationError> {
|
) -> Result<Value, ConfigurationError> {
|
||||||
match &self {
|
match &self {
|
||||||
|
PackagePointerSpec::TorKey(key) => key.deref(&manifest.id, &ctx.secret_store).await,
|
||||||
PackagePointerSpec::TorAddress(tor) => tor.deref(db).await,
|
PackagePointerSpec::TorAddress(tor) => tor.deref(db).await,
|
||||||
PackagePointerSpec::LanAddress(lan) => lan.deref(db).await,
|
PackagePointerSpec::LanAddress(lan) => lan.deref(db).await,
|
||||||
PackagePointerSpec::Config(cfg) => cfg.deref(ctx, db, config_overrides).await,
|
PackagePointerSpec::Config(cfg) => cfg.deref(ctx, db, config_overrides).await,
|
||||||
@@ -1533,6 +1569,7 @@ impl PackagePointerSpec {
|
|||||||
impl fmt::Display for PackagePointerSpec {
|
impl fmt::Display for PackagePointerSpec {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
PackagePointerSpec::TorKey(key) => write!(f, "{}", key),
|
||||||
PackagePointerSpec::TorAddress(tor) => write!(f, "{}", tor),
|
PackagePointerSpec::TorAddress(tor) => write!(f, "{}", tor),
|
||||||
PackagePointerSpec::LanAddress(lan) => write!(f, "{}", lan),
|
PackagePointerSpec::LanAddress(lan) => write!(f, "{}", lan),
|
||||||
PackagePointerSpec::Config(cfg) => write!(f, "{}", cfg),
|
PackagePointerSpec::Config(cfg) => write!(f, "{}", cfg),
|
||||||
@@ -1570,10 +1607,11 @@ impl ValueSpec for PackagePointerSpec {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
manifest: &Manifest,
|
||||||
config_overrides: &BTreeMap<PackageId, Config>,
|
config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
*value = self.deref(ctx, db, config_overrides).await?;
|
*value = self.deref(ctx, db, manifest, config_overrides).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn pointers(&self, _value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
fn pointers(&self, _value: &Value) -> Result<HashSet<ValueSpecPointer>, NoMatchWithPath> {
|
||||||
@@ -1670,7 +1708,7 @@ impl ConfigPointer {
|
|||||||
if let Some(cfg) = config_overrides.get(&self.package_id) {
|
if let Some(cfg) = config_overrides.get(&self.package_id) {
|
||||||
Ok(self.select(&Value::Object(cfg.clone())))
|
Ok(self.select(&Value::Object(cfg.clone())))
|
||||||
} else {
|
} else {
|
||||||
let manifest_model: OptionModel<_> = crate::db::DatabaseModel::new()
|
let manifest_model: OptionModel<Manifest> = crate::db::DatabaseModel::new()
|
||||||
.package_data()
|
.package_data()
|
||||||
.idx_model(&self.package_id)
|
.idx_model(&self.package_id)
|
||||||
.and_then(|pde| pde.installed())
|
.and_then(|pde| pde.installed())
|
||||||
@@ -1773,6 +1811,44 @@ impl Hash for ConfigSelector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
|
#[serde(tag = "target")]
|
||||||
|
pub struct TorKeyPointer {
|
||||||
|
package_id: PackageId,
|
||||||
|
interface: InterfaceId,
|
||||||
|
}
|
||||||
|
impl TorKeyPointer {
|
||||||
|
async fn deref(
|
||||||
|
&self,
|
||||||
|
source_package: &PackageId,
|
||||||
|
secrets: &SqlitePool,
|
||||||
|
) -> Result<Value, ConfigurationError> {
|
||||||
|
if &self.package_id != source_package {
|
||||||
|
return Err(ConfigurationError::PermissionDenied(
|
||||||
|
ValueSpecPointer::Package(PackagePointerSpec::TorKey(self.clone())),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let x = sqlx::query!(
|
||||||
|
"SELECT key FROM tor WHERE package = ? AND interface = ?",
|
||||||
|
*self.package_id,
|
||||||
|
*self.interface
|
||||||
|
)
|
||||||
|
.fetch_one(secrets)
|
||||||
|
.await
|
||||||
|
.map_err(|e| ConfigurationError::SystemError(e.into()))?;
|
||||||
|
Ok(Value::String(base32::encode(
|
||||||
|
base32::Alphabet::RFC4648 { padding: false },
|
||||||
|
&x.key,
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl fmt::Display for TorKeyPointer {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "{}: tor-key: {}", self.package_id, self.interface)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
#[serde(tag = "target")]
|
#[serde(tag = "target")]
|
||||||
@@ -1809,6 +1885,7 @@ impl ValueSpec for SystemPointerSpec {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
|
_manifest: &Manifest,
|
||||||
_config_overrides: &BTreeMap<PackageId, Config>,
|
_config_overrides: &BTreeMap<PackageId, Config>,
|
||||||
value: &mut Value,
|
value: &mut Value,
|
||||||
) -> Result<(), ConfigurationError> {
|
) -> Result<(), ConfigurationError> {
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ where
|
|||||||
pub struct Manifest {
|
pub struct Manifest {
|
||||||
pub id: PackageId,
|
pub id: PackageId,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
#[model]
|
||||||
pub version: Version,
|
pub version: Version,
|
||||||
pub description: Description,
|
pub description: Description,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ impl Map for Volumes {
|
|||||||
self.0.get(key)
|
self.0.get(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub type VolumesModel = MapModel<Volumes>;
|
||||||
impl HasModel for Volumes {
|
impl HasModel for Volumes {
|
||||||
type Model = MapModel<Self>;
|
type Model = MapModel<Self>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user