pub struct OpaClient { /* private fields */ }Expand description
Client for evaluating authorization decisions against an OPA server.
Implementations§
Source§impl OpaClient
impl OpaClient
Sourcepub async fn query(
&self,
policy_path: &str,
input: Value,
) -> Result<OpaResponse>
pub async fn query( &self, policy_path: &str, input: Value, ) -> Result<OpaResponse>
Evaluate a policy at the given path with the provided input.
§Arguments
policy_path— The Rego package/rule path (e.g.,authz/allow)input— Arbitrary JSON input for the policy
§Example
let client = OpaClient::new(OpaConfig::default())?;
let input = serde_json::json!({
"user": "alice",
"action": "read",
"resource": "/documents/secret"
});
let response = client.query("authz/allow", input).await?;
if response.is_allowed() {
println!("Access granted");
}Sourcepub async fn evaluate(&self, input: Value) -> Result<OpaResponse>
pub async fn evaluate(&self, input: Value) -> Result<OpaResponse>
Evaluate the default policy path.
Sourcepub async fn is_allowed(&self, input: Value) -> Result<bool>
pub async fn is_allowed(&self, input: Value) -> Result<bool>
Convenience: check if the default policy allows the given input.
Sourcepub async fn health_check(&self) -> Result<bool>
pub async fn health_check(&self) -> Result<bool>
Check OPA server health.
Sourcepub async fn put_policy(&self, policy_id: &str, rego: &str) -> Result<()>
pub async fn put_policy(&self, policy_id: &str, rego: &str) -> Result<()>
Upload a Rego policy to OPA.
Sourcepub async fn delete_policy(&self, policy_id: &str) -> Result<()>
pub async fn delete_policy(&self, policy_id: &str) -> Result<()>
Delete a policy from OPA.
Sourcepub async fn put_data(&self, data_path: &str, data: Value) -> Result<()>
pub async fn put_data(&self, data_path: &str, data: Value) -> Result<()>
Upload data to OPA’s data store.
Sourcepub async fn clear_cache(&self)
pub async fn clear_cache(&self)
Clear the response cache.
Sourcepub async fn cache_size(&self) -> usize
pub async fn cache_size(&self) -> usize
Get the number of cached entries.
Auto Trait Implementations§
impl Freeze for OpaClient
impl !RefUnwindSafe for OpaClient
impl Send for OpaClient
impl Sync for OpaClient
impl Unpin for OpaClient
impl UnsafeUnpin for OpaClient
impl !UnwindSafe for OpaClient
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more