Skip to content

Commit

Permalink
adapt to renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
shaobo-he-aws committed Apr 27, 2023
1 parent 0bcaeed commit 09afcb9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tiny-todo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ serde_json = "1"
tokio = { version = "1", features = ["full"] }
warp = "0.3.4"
uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
cedar = "2.0"
cedar-policy = "2.0"
thiserror = "1"
itertools = "0.10.5"
6 changes: 3 additions & 3 deletions tiny-todo/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use itertools::Itertools;
use std::path::Path;

use cedar::{
use cedar_policy::{
Authorizer, Context, Decision, Diagnostics, EntityTypeName, ParseErrors, PolicySet, Request,
Schema, SchemaError, Validator,
Schema, SchemaError, Validator, ValidationMode,
};
use thiserror::Error;
use tokio::sync::{
Expand Down Expand Up @@ -174,7 +174,7 @@ impl AppContext {
let policy_src = std::fs::read_to_string(policies_path)?;
let policies = policy_src.parse()?;
let validator = Validator::new(schema);
let output = validator.validate(&policies);
let output = validator.validate(&policies, ValidationMode::Permissive);
if output.validation_passed() {
let authorizer = Authorizer::new();
let (send, recv) = tokio::sync::mpsc::channel(100);
Expand Down
10 changes: 5 additions & 5 deletions tiny-todo/src/entitystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};
use thiserror::Error;

use cedar::{
use cedar_policy::{
Entities, EntityId, EntityTypeName, EvalResult, EvaluationError, RestrictedExpression,
};
use serde::Deserialize;
Expand Down Expand Up @@ -43,8 +43,8 @@ impl Entity {
self.uid.clone()
}

pub fn as_entity(&self) -> cedar::Entity {
cedar::Entity::new(
pub fn as_entity(&self) -> cedar_policy::Entity {
cedar_policy::Entity::new(
self.uid.clone().into(),
self.attrs
.clone()
Expand All @@ -56,7 +56,7 @@ impl Entity {
}

pub fn attr(&self, attr: &str) -> Option<Result<EvalResult, EvaluationError>> {
cedar::Entity::new(
cedar_policy::Entity::new(
self.uid().into(),
self.attrs
.clone()
Expand Down Expand Up @@ -97,7 +97,7 @@ impl EntityStore {
loop {
let new_uid: EntityId = format!("{}", self.uid).parse().unwrap();
self.uid += 1;
let euid = cedar::EntityUid::from_type_name_and_id(ty.clone(), new_uid).into();
let euid = cedar_policy::EntityUid::from_type_name_and_id(ty.clone(), new_uid).into();
if !self.store.contains_key(&euid) {
return euid;
}
Expand Down
4 changes: 2 additions & 2 deletions tiny-todo/src/objects.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use cedar::{EntityTypeName, EvalResult, RestrictedExpression};
use cedar_policy::{EntityTypeName, EvalResult, RestrictedExpression};
use serde::{Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'a> TypedEntity<'a> for List {
.attr(tasks_field)
.ok_or(EntityDecodeError::MissingAttr(tasks_field))??
{
cedar::EvalResult::Set(tasks) => Ok(tasks
cedar_policy::EvalResult::Set(tasks) => Ok(tasks
.iter()
.map(|v| v.try_into())
.collect::<Result<Vec<Task>, _>>()?),
Expand Down
20 changes: 10 additions & 10 deletions tiny-todo/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{ops::Deref, str::FromStr};

use cedar::{ParseErrors, RestrictedExpression};
use cedar_policy::{ParseErrors, RestrictedExpression};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -86,14 +86,14 @@ where
pub struct EntityUid(
#[serde(serialize_with = "serialize_euid")]
#[serde(deserialize_with = "deserialize_euid")]
cedar::EntityUid,
cedar_policy::EntityUid,
);

impl FromStr for EntityUid {
type Err = ParseErrors;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let e: cedar::EntityUid = s.parse()?;
let e: cedar_policy::EntityUid = s.parse()?;
Ok(e.into())
}
}
Expand All @@ -115,41 +115,41 @@ impl From<Vec<EntityUid>> for Lists {
}
}

impl From<cedar::EntityUid> for EntityUid {
fn from(value: cedar::EntityUid) -> Self {
impl From<cedar_policy::EntityUid> for EntityUid {
fn from(value: cedar_policy::EntityUid) -> Self {
Self(value)
}
}

impl Deref for EntityUid {
type Target = cedar::EntityUid;
type Target = cedar_policy::EntityUid;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl From<EntityUid> for cedar::EntityUid {
impl From<EntityUid> for cedar_policy::EntityUid {
fn from(value: EntityUid) -> Self {
value.0
}
}

pub fn serialize_euid<S>(euid: &cedar::EntityUid, s: S) -> Result<S::Ok, S::Error>
pub fn serialize_euid<S>(euid: &cedar_policy::EntityUid, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s.serialize_str(&format!("{euid}"))
}

pub fn deserialize_euid<'de, D>(d: D) -> Result<cedar::EntityUid, D::Error>
pub fn deserialize_euid<'de, D>(d: D) -> Result<cedar_policy::EntityUid, D::Error>
where
D: Deserializer<'de>,
{
struct Visitor;

impl<'ide> serde::de::Visitor<'ide> for Visitor {
type Value = cedar::EntityUid;
type Value = cedar_policy::EntityUid;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
Expand Down

0 comments on commit 09afcb9

Please sign in to comment.