-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make non-json isAuthorized and validate public, rework wasm interfaces
- Loading branch information
Showing
8 changed files
with
118 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
//! This module contains the entry point to the wasm isAuthorized functionality. | ||
use cedar_policy::frontend::{is_authorized::json_is_authorized, utils::InterfaceResult}; | ||
|
||
use cedar_policy::frontend::is_authorized::{ | ||
is_authorized, AuthorizationAnswer, AuthorizationCall, InterfaceResponse, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use tsify::Tsify; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(js_name = isAuthorized)] | ||
pub fn wasm_is_authorized(input: &str) -> InterfaceResult { | ||
json_is_authorized(input) | ||
#[derive(Tsify, Debug, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub enum IsAuthorizedResult { | ||
Success { response: InterfaceResponse }, | ||
Error { errors: Vec<String> }, | ||
} | ||
|
||
#[wasm_bindgen(js_name = "isAuthorized")] | ||
pub fn wasm_is_authorized(call: AuthorizationCall) -> IsAuthorizedResult { | ||
match is_authorized(call) { | ||
AuthorizationAnswer::Success { response } => IsAuthorizedResult::Success { response }, | ||
AuthorizationAnswer::ParseFailed { errors } => IsAuthorizedResult::Error { errors }, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
use cedar_policy::frontend::{utils::InterfaceResult, validate::json_validate}; | ||
use cedar_policy::frontend::validate::{validate, ValidateAnswer, ValidateCall, ValidationNote}; | ||
use serde::{Deserialize, Serialize}; | ||
use tsify::Tsify; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[derive(Tsify, Debug, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub enum ValidateResult { | ||
Success { notes: Vec<ValidationNote> }, | ||
Error { errors: Vec<String> }, | ||
} | ||
|
||
#[wasm_bindgen(js_name = "validate")] | ||
pub fn wasm_validate(input: &str) -> InterfaceResult { | ||
json_validate(input) | ||
pub fn wasm_validate(call: ValidateCall) -> ValidateResult { | ||
match validate(&call) { | ||
Ok(answer) => match answer { | ||
ValidateAnswer::Success { notes } => ValidateResult::Success { notes }, | ||
ValidateAnswer::ParseFailed { errors } => ValidateResult::Error { errors }, | ||
}, | ||
Err(err) => ValidateResult::Error { | ||
errors: vec![err.to_string()], | ||
}, | ||
} | ||
} |