Skip to content

Commit

Permalink
feat(rust): implement influxdb token lessor service
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Sep 13, 2024
1 parent 63f2251 commit 43cf5c3
Show file tree
Hide file tree
Showing 33 changed files with 1,561 additions and 446 deletions.
6 changes: 4 additions & 2 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 implementations/rust/ockam/ockam_abac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ winnow = { version = "0.6.18", default-features = false, optional = true, featur
ockam_vault = { path = "../ockam_vault", default-features = false, features = ["rust-crypto"] }
quickcheck = "1.0.3"
rand = "0.8.5"
serde_json = "1.0.128"
tempfile = "3.10.1"

[[bin]]
Expand Down
65 changes: 59 additions & 6 deletions implementations/rust/ockam/ockam_abac/src/policy_expr.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
use core::str::FromStr;
use ockam_core::compat::fmt::{Display, Formatter};
use ockam_core::Result;
use serde::{Deserialize, Serialize};
}
}

use crate::policy_expr::PolicyExpression::{BooleanExpression, FullExpression};
use crate::{BooleanExpr, Expr};
#[cfg(feature = "std")]
use core::str::FromStr;
use minicbor::{CborLen, Decode, Encode};
#[cfg(feature = "std")]
use ockam_core::compat::fmt::{Display, Formatter};
#[cfg(feature = "std")]
use ockam_core::Result;

/// A Policy expression can either be represented with
/// - A full expression with string valued attributes, contain operator, etc...
Expand Down Expand Up @@ -93,6 +96,27 @@ impl TryFrom<String> for PolicyExpression {
}
}

#[cfg(feature = "std")]
impl Serialize for PolicyExpression {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.to_string().serialize(serializer)
}
}

#[cfg(feature = "std")]
impl<'d> Deserialize<'d> for PolicyExpression {
fn deserialize<D>(deserializer: D) -> Result<PolicyExpression, D::Error>
where
D: serde::Deserializer<'d>,
{
let s = String::deserialize(deserializer)?;
PolicyExpression::from_str(s.as_str()).map_err(serde::de::Error::custom)
}
}

#[cfg(test)]
mod tests {
use crate::PolicyExpression::{BooleanExpression, FullExpression};
Expand All @@ -113,4 +137,33 @@ mod tests {
BooleanExpression(BooleanExpr::from_str(boolean_expression).unwrap())
);
}

#[test]
fn serde_json() {
let full_expression = "(= subject.test = \"true\")";
let full_expression = FullExpression(Expr::from_str(full_expression).unwrap());
let full_expression_str = serde_json::to_string(&full_expression).unwrap();
assert_eq!(full_expression_str, "\"(= subject.test = \\\"true\\\")\"");
let full_expression: PolicyExpression = serde_json::from_str(&full_expression_str).unwrap();
assert_eq!(
full_expression,
FullExpression(Expr::from_str("(= subject.test = \"true\")").unwrap())
);

let boolean_expression = "test";
let boolean_expression =
BooleanExpression(BooleanExpr::from_str(boolean_expression).unwrap());
let boolean_expression_str = serde_json::to_string(&boolean_expression).unwrap();
assert_eq!(boolean_expression_str, "\"test\"");
let boolean_expression: PolicyExpression =
serde_json::from_str(&boolean_expression_str).unwrap();
assert_eq!(
boolean_expression,
BooleanExpression(BooleanExpr::from_str("test").unwrap())
);

let invalid_expression = "\"( test = \"true\")\"";
let result: Result<PolicyExpression, _> = serde_json::from_str(invalid_expression);
assert!(result.is_err());
}
}
3 changes: 3 additions & 0 deletions implementations/rust/ockam/ockam_abac/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub enum ResourceType {
#[n(6)]
#[strum(serialize = "relay")]
Relay,
#[n(7)]
#[strum(serialize = "lessor")]
InfluxDBLessor,
}

impl ResourceType {
Expand Down
1 change: 1 addition & 0 deletions implementations/rust/ockam/ockam_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ serde_json = "1.0.118"
sha2 = "0.10.8"
sqlx-build-trust = { version = "0.7.8" }
strip-ansi-escapes = "0.2"
strum = { version = "0.26.3", default-features = false, features = ["derive"] }
sysinfo = "0.30"
thiserror = "1.0"
time = { version = "0.3.36", default-features = false, features = ["std", "formatting", "local-offset", "macros"] }
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion implementations/rust/ockam/ockam_api/src/cloud/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub use secure_clients::*;
pub mod addon;
pub mod email_address;
pub mod enroll;
pub mod lease_manager;
pub mod operation;
pub mod project;
pub mod secure_clients;
Expand Down
Loading

0 comments on commit 43cf5c3

Please sign in to comment.