-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CARL -> Remove access control rules if they already exist
- Loading branch information
1 parent
2b5c337
commit dae0266
Showing
10 changed files
with
309 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 123 additions & 72 deletions
195
opendut-vpn/opendut-vpn-netbird/src/client/implementation.rs
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
opendut-vpn/opendut-vpn-netbird/src/netbird/access_control.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,14 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub(crate) mod access_control; | ||
pub(crate) mod token; | ||
pub(crate) mod group; | ||
pub(crate) use group::{Group, GroupName}; | ||
|
||
pub(crate) mod setup_key; | ||
pub(crate) use setup_key::SetupKey; | ||
pub mod error; | ||
pub(crate) mod rules; | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(transparent)] | ||
pub struct PeerId(pub String); | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(transparent)] | ||
pub struct GroupId(pub String); | ||
|
||
impl From<&str> for GroupId { | ||
fn from(value: &str) -> Self { | ||
GroupId(value.to_owned()) | ||
} | ||
} | ||
|
||
impl From<String> for GroupId { | ||
fn from(value: String) -> Self { | ||
GroupId(value) | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
opendut-vpn/opendut-vpn-netbird/src/netbird/rules/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
use std::error::Error; | ||
use std::fmt::{Display, Formatter}; | ||
use serde::{Deserialize, Serialize}; | ||
use opendut_types::cluster::ClusterId; | ||
|
||
use crate::netbird::group::GroupId; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[error("Cannot create RuleName from '{value}':\n {cause}")] | ||
pub struct InvalidRuleNameError { | ||
value: String, | ||
cause: Box<dyn Error>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
#[serde(try_from = "String", into = "String")] | ||
pub enum RuleName { | ||
Cluster(ClusterId), | ||
Other(String), | ||
} | ||
|
||
impl RuleName { | ||
const CLUSTER_RULE_PREFIX: &'static str = "opendut-cluster-rule-"; | ||
|
||
pub fn description(&self) -> String { | ||
match self { | ||
RuleName::Cluster(cluster_id) => format!("Rule for the openDuT cluster <{cluster_id}>."), | ||
RuleName::Other(name) => name.to_owned(), | ||
} | ||
} | ||
} | ||
|
||
impl From<ClusterId> for RuleName { | ||
fn from(cluster_id: ClusterId) -> Self { | ||
RuleName::Cluster(cluster_id) | ||
} | ||
} | ||
|
||
impl TryFrom<&str> for RuleName { | ||
type Error = InvalidRuleNameError; | ||
|
||
fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
if let Some(uuid) = value.strip_prefix(RuleName::CLUSTER_RULE_PREFIX) { | ||
ClusterId::try_from(uuid) | ||
.map(|id| Self::Cluster(id)) | ||
.map_err(|cause| InvalidRuleNameError { value: value.to_owned(), cause: cause.into() }) | ||
} | ||
else { | ||
Ok(Self::Other(value.to_owned())) | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<String> for RuleName { | ||
|
||
type Error = InvalidRuleNameError; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { | ||
RuleName::try_from(value.as_str()) | ||
} | ||
} | ||
|
||
impl From<&RuleName> for String { | ||
fn from(value: &RuleName) -> Self { | ||
match value { | ||
RuleName::Cluster(id) => format!("{}{}", RuleName::CLUSTER_RULE_PREFIX, id), | ||
RuleName::Other(name) => name.to_owned(), | ||
} | ||
} | ||
} | ||
|
||
impl From<RuleName> for String { | ||
fn from(value: RuleName) -> Self { | ||
String::from(&value) | ||
} | ||
} | ||
|
||
impl Display for RuleName { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", String::from(self)) | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
#[serde(transparent)] | ||
pub struct RuleId(pub String); | ||
|
||
impl From<&str> for RuleId { | ||
fn from(value: &str) -> Self { | ||
RuleId(value.to_owned()) | ||
} | ||
} | ||
|
||
impl From<String> for RuleId { | ||
fn from(value: String) -> Self { | ||
RuleId(value) | ||
} | ||
} | ||
|
||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct Rule { | ||
pub id: RuleId, | ||
pub name: RuleName, | ||
pub description: String, | ||
pub disabled: bool, | ||
pub flow: RuleFlow, | ||
|
||
pub sources: Vec<GroupInfo>, | ||
pub destinations: Vec<GroupInfo>, | ||
} | ||
|
||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct GroupInfo { | ||
pub id: GroupId, | ||
pub name: String, | ||
pub peers_count: usize, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all="kebab-case")] | ||
pub(crate) enum RuleFlow { | ||
Bidirect, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters