Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions cedar-policy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ nonempty = "0.10"
serde-wasm-bindgen = { version = "0.6", optional = true }
tsify = { version = "0.4.5", optional = true }
wasm-bindgen = { version = "0.2.82", optional = true }
semver = "1.0.23"
lazy_static = "1.5.0"

[features]
# by default, enable all Cedar extensions, but not other crate features
Expand Down
23 changes: 23 additions & 0 deletions cedar-policy/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::io::Read;
use std::str::FromStr;

// PANIC SAFETY: `CARGO_PKG_VERSION` should return a valid SemVer version string
#[allow(clippy::unwrap_used)]
pub(crate) mod version {
use lazy_static::lazy_static;
use semver::Version;

lazy_static! {
// Cedar Rust SDK Semantic Versioning version
static ref SDK_VERSION: Version = env!("CARGO_PKG_VERSION").parse().unwrap();
// Cedar language version
// The patch version field may be unnecessary
static ref LANG_VERSION: Version = Version::new(4, 0, 0);
}
/// Get the Cedar SDK Semantic Versioning version
pub fn get_sdk_version() -> Version {
SDK_VERSION.clone()
}
/// Get the Cedar language version
pub fn get_lang_version() -> Version {
LANG_VERSION.clone()
}
}

/// Entity datatype
#[repr(transparent)]
#[derive(Debug, Clone, PartialEq, Eq, RefCast, Hash)]
Expand Down
1 change: 1 addition & 0 deletions cedar-policy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
/// Rust public API
mod api;

pub use api::version::{get_lang_version, get_sdk_version};
pub use api::*;

/// FFI utilities, see comments in the module itself
Expand Down
14 changes: 14 additions & 0 deletions cedar-policy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5742,6 +5742,20 @@ mod policy_manipulation_functions_tests {
}
}

mod version_tests {
use crate::{get_lang_version, get_sdk_version};

#[test]
fn test_sdk_version() {
assert_eq!(get_sdk_version().to_string(), "4.0.0");
}

#[test]
fn test_lang_version() {
assert_eq!(get_lang_version().to_string(), "4.0.0");
}
}

mod reserved_keywords_in_policies {
use super::*;
use cool_asserts::assert_matches;
Expand Down