Skip to content

Commit 219470f

Browse files
committed
Add Authorizer Api with NoopAuthorizer.
1 parent 763624e commit 219470f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

rust/api/src/auth.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::error::VssError;
2+
use async_trait::async_trait;
3+
use std::collections::HashMap;
4+
use std::string::ToString;
5+
6+
#[derive(Debug, Clone)]
7+
pub struct AuthResponse {
8+
pub user_token: String,
9+
}
10+
11+
// Interface for authorizer that is run before every request.
12+
#[async_trait]
13+
pub trait Authorizer: Send + Sync {
14+
async fn verify(&self, headers_map: &HashMap<String, String>)
15+
-> Result<AuthResponse, VssError>;
16+
}
17+
18+
// A no-operation authorizer, that lets any user-request go through.
19+
pub struct NoopAuthorizer {}
20+
21+
const UNAUTHENTICATED_USER: &str = "unauth-user";
22+
23+
#[async_trait]
24+
impl Authorizer for NoopAuthorizer {
25+
async fn verify(
26+
&self, _headers_map: &HashMap<String, String>,
27+
) -> Result<AuthResponse, VssError> {
28+
Ok(AuthResponse { user_token: UNAUTHENTICATED_USER.to_string().clone() })
29+
}
30+
}

rust/api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod auth;
12
pub mod error;
23
pub mod kv_store;
34
pub mod types;

0 commit comments

Comments
 (0)