Skip to content

Commit

Permalink
Upgraded cedar to 4.2.0 (#83)
Browse files Browse the repository at this point in the history
* Upgraded cedar to 4.2.0

Signed-off-by: Kelley Li <lkli@amazon.com>

* fixed formatting errors

Signed-off-by: Kelley Li <lkli@amazon.com>

* fixed formatting errors

Signed-off-by: Kelley Li <lkli@amazon.com>

* Redid errors returned by generate_response

Signed-off-by: Kelley Li <lkli@amazon.com>

* fixed clippy errors

Signed-off-by: Kelley Li <lkli@amazon.com>

---------

Signed-off-by: Kelley Li <lkli@amazon.com>
  • Loading branch information
l-kli authored Dec 4, 2024
1 parent d9cf472 commit ab31fff
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 270 deletions.
268 changes: 129 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bench = false
async-trait = "0.1.71"
chrono = "0.4.26"
derive_builder = "0.12.0"
futures = { version = "0.3.28", features = ["std"] }
futures = { version = "0.3.31", features = ["std"] }
fs2 = "0.4.3"
once_cell = "1.18.0"
rand = "0.8.5"
Expand All @@ -33,10 +33,10 @@ tracing-core = "0.1.31"
tracing-subscriber = "0.3.17"

# Cedar
cedar-policy = "3.1.0"
cedar-policy-core = "3.1.0"
cedar-policy-formatter = "3.1.0"
cedar-policy-validator = "3.1.0"
cedar-policy = "4.2.0"
cedar-policy-core = "4.2.0"
cedar-policy-formatter = "4.2.0"
cedar-policy-validator = "4.2.0"

[features]
# Experimental features.
Expand Down
2 changes: 1 addition & 1 deletion benches/data_gen/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl From<Entity> for EntityUidRepr {
fn from(value: Entity) -> Self {
EntityUidRepr {
type_name: value.uid().type_name().to_string(),
id: value.uid().id().to_string(),
id: value.uid().to_string(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion benches/data_gen/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use rand::Rng;

/// Alphabet as an &str
pub const ALPHA: &str = "abcdefghijklmnopqrstuvwxyz";
#[allow(clippy::single_char_add_str)]
pub fn random_string(n: u32, charset: &str) -> String {
let mut rng = rand::thread_rng();

let mut res = "".to_string();
for _i in 0..n as usize {
let random_index: usize = rng.gen_range(0..charset.len());
res.push_str(&charset.chars().nth(random_index).unwrap().to_string());
res.push(charset.chars().nth(random_index).unwrap());
}
res
}
6 changes: 3 additions & 3 deletions benches/is_authorized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use std::sync::Arc;

fn construct_request() -> Request {
Request::new(
Some("Principal::\"request\"".parse().unwrap()),
Some("Action::\"request\"".parse().unwrap()),
Some("Resource::\"request\"".parse().unwrap()),
"Principal::\"request\"".parse().unwrap(),
"Action::\"request\"".parse().unwrap(),
"Resource::\"request\"".parse().unwrap(),
Context::empty(),
None,
)
Expand Down
8 changes: 1 addition & 7 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# This file defines configuration for the cargo deny command
# Ref: https://github.com/EmbarkStudios/cargo-deny
[graph]
targets = []

[advisories]
vulnerability = "deny"
unmaintained = "deny"
notice = "deny"
unsound = "deny"
ignore = []

[bans]
Expand Down Expand Up @@ -37,9 +34,6 @@ unknown-registry = "deny"
unknown-git = "deny"

[licenses]
unlicensed = "deny"
allow-osi-fsf-free = "neither"
copyleft = "deny"
confidence-threshold = 0.93
allow = [
"Apache-2.0",
Expand Down
12 changes: 6 additions & 6 deletions src/public/file/entity_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::io::Error;
use std::sync::Arc;

use async_trait::async_trait;
use cedar_policy::{Entities, EntitiesError, Request, Schema};
use cedar_policy::{entities_errors::EntitiesError, Entities, Request, Schema};
use derive_builder::Builder;
use thiserror::Error;
use tokio::sync::RwLock;
Expand Down Expand Up @@ -172,7 +172,7 @@ impl EntityProvider {

let entities = if let Some(schema_path) = configuration.schema_path.as_ref() {
let schema_file = File::open(schema_path)?;
let schema = Schema::from_file(schema_file)
let schema = Schema::from_json_file(schema_file)
.map_err(|_schema_error| SchemaParseErrorWrapper::new(schema_path.clone()))?;
let res = Entities::from_json_file(entities_file, Some(&schema)).map_err(
|entities_error| {
Expand Down Expand Up @@ -227,7 +227,7 @@ impl UpdateProviderData for EntityProvider {
let schema_file = File::open(schema_path).map_err(|e| {
UpdateProviderDataError::General(Box::new(ProviderError::IOError(e)))
})?;
let schema = Schema::from_file(schema_file).map_err(|_| {
let schema = Schema::from_json_file(schema_file).map_err(|_| {
UpdateProviderDataError::General(Box::new(ProviderError::SchemaParseError(
schema_path.to_string(),
)))
Expand Down Expand Up @@ -335,9 +335,9 @@ mod test {
.unwrap()
.get_entities(
&Request::new(
Some(r#"User::"Eric""#.parse().unwrap()),
Some(r#"Action::"View""#.parse().unwrap()),
Some(r#"Box::"10""#.parse().unwrap()),
r#"User::"Eric""#.parse().unwrap(),
r#"Action::"View""#.parse().unwrap(),
r#"Box::"10""#.parse().unwrap(),
Context::empty(),
None,
)
Expand Down
6 changes: 3 additions & 3 deletions src/public/file/policy_set_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ mod test {
.unwrap()
.get_policy_set(
&Request::new(
Some(r#"User::"Adam""#.parse().unwrap()),
Some(r#"Action::"View""#.parse().unwrap()),
Some(r#"Box::"10""#.parse().unwrap()),
r#"User::"Adam""#.parse().unwrap(),
r#"Action::"View""#.parse().unwrap(),
r#"Box::"10""#.parse().unwrap(),
Context::empty(),
None,
)
Expand Down
2 changes: 1 addition & 1 deletion src/public/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const DEFAULT_REQUESTER_NAME: &str = "cedar::simple::authorizer";
#[builder(setter(into))]
pub struct Config {
/// `format` is used to specify the log rotation format.
/// By default the log rotation format is OpenCyberSecurityFramework (OCSF).
/// By default the log rotation format is `OpenCyberSecurityFramework` (OCSF).
#[builder(default)]
pub format: Format,

Expand Down
Loading

0 comments on commit ab31fff

Please sign in to comment.