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

feat(rust): implement influxdb token lease manager #8451

Merged
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
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
Loading