Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mx-conflict #263

Merged
merged 3 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ vendor/
.DS_Store
Thumbs.db

# Temp
result.mobileconfig
/dominion/certs
/dominion/*.key
/dominion/*.crt
/dominion/*.csr
/dominion/*.key
/dominion/*.pfx

# Data directory
/data

# Oscar's staging area
/_
/policy.yaml
/out

# Temp
result.mobileconfig
/apps/ingest/src/windows.rs
22 changes: 11 additions & 11 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The components are:
- [`apps/mattraxd`](apps/mattraxd) - Agent for managed devices that makes script execution and more
- [`apps/landing`](apps/landing) - [Landing website](https://mattrax.app)
- [`apps/docs`](apps/docs) - [Documentation website](https://docs.mattrax.app)
- [`apps/android](apps/android) - Android application for device management

We mainly use the following technologies:
- [SolidJS](https://www.solidjs.com)
Expand Down
2 changes: 1 addition & 1 deletion crates/graph/Cargo.toml → crates/conflict/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "mx-graph"
name = "mx-conflict"
version = "0.0.1"
edition = "2021"
publish = false
Expand Down
File renamed without changes.
34 changes: 11 additions & 23 deletions crates/graph/src/graph.rs → crates/conflict/src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use std::collections::{BTreeMap, HashMap};

use mx_dmvalue::DmValue;
use serde::{Deserialize, Serialize};

use crate::{json_map::JsonMap, ConflictResolutionStrategy, Deploy};
use crate::{ConflictResolutionStrategy, Deploy};

// The order policies are applied to the graph should not affect the result -> So we need to sort everything.

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq)]
pub struct Graph {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty", rename = "n")]
nodes: BTreeMap<String, Child>,
#[serde(default, skip_serializing_if = "Vec::is_empty", rename = "c")]
conflicts: Vec<Conflict>,
}

Expand All @@ -33,7 +30,7 @@ impl Graph {
let Child::Node(node) = entry;

// If this policies attempts to set the same value we can just add a reference as it won't conflict.
if let Some(references) = node.values.0.get_mut(&config.value) {
if let Some(references) = node.values.get_mut(&config.value) {
references.push(Reference {
deploy_pk: deploy.pk,
key: config.key,
Expand All @@ -58,7 +55,6 @@ impl Graph {

let mut references = node
.values
.0
.into_iter()
.map(|(_, v)| v)
.flatten()
Expand All @@ -81,7 +77,6 @@ impl Graph {
// TODO: If value is in the same bucket we can just add the reference

node.values
.0
.get_mut(&config.value)
.get_or_insert(&mut Default::default())
.push(Reference {
Expand Down Expand Up @@ -111,7 +106,6 @@ impl Graph {

let mut references = node
.values
.0
.into_iter()
.map(|(_, v)| v)
.flatten()
Expand All @@ -133,13 +127,13 @@ impl Graph {
oma_uri,
Child::Node(Node {
strategy: config.conflict_resolution_strategy,
values: JsonMap(HashMap::from([(
values: HashMap::from([(
config.value.clone(),
vec![Reference {
deploy_pk: deploy.pk,
key: config.key,
}],
)])),
)]),
}),
);
}
Expand All @@ -155,42 +149,36 @@ impl Graph {
}
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq)]
enum Child {
// TODO: Use edges between nodes instead of full URI as the key so it's more efficient to store
// Edge(BTreeMap<String, Child>),
Node(Node),
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq)]
struct Node {
strategy: ConflictResolutionStrategy,
#[serde(
skip_serializing_if = "JsonMap::is_empty",
default = "Default::default"
)]
values: JsonMap<DmValue, Vec<Reference>>,
values: HashMap<DmValue, Vec<Reference>>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq)]
pub struct Reference {
deploy_pk: u64,
key: String,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq)]
pub struct Conflict {
node: String,
cause: ConflictCause,
references: Vec<Reference>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq)]
pub enum ConflictCause {
/// A multiple configurations setting this node were marked as [ConflictResolutionStrategy::InValueOrder] but had conflicting definitions of the most restrictive policy.
#[serde(rename = "i")]
InvalidInValueOrderDefinition,
/// A configuration setting this node was marked as [ConflictResolutionStrategy::Conflict] and multiple nodes were found.
#[serde(rename = "e")]
ExplicitConflict,
}
1 change: 0 additions & 1 deletion crates/graph/src/lib.rs → crates/conflict/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

mod deploy;
mod graph;
pub(crate) mod json_map;

pub use deploy::{Configuration, ConflictResolutionStrategy, Deploy};
pub use graph::{Conflict, Graph, Reference};
File renamed without changes.
File renamed without changes.
File renamed without changes.
81 changes: 0 additions & 81 deletions crates/graph/src/json_map.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
mx-db = { path = "../db" }
mx-policy = { path = "../policy" }
mx-graph = { path = "../graph" }
mx-conflict = { path = "../conflict" }
ms-mdm = { path = "../ms-mdm" }
ms-mde = { path = "../ms-mde" }
mx-dmvalue = { path = "../dmvalue" }
Expand Down
Loading
Loading