Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 4 additions & 11 deletions rust/auth-impls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,8 @@ const BEARER_PREFIX: &str = "Bearer ";

impl JWTAuthorizer {
/// Create new instance of [`JWTAuthorizer`]
pub async fn new(jwt_issuer_key: DecodingKey) -> JWTAuthorizer {
JWTAuthorizer { jwt_issuer_key }
}

fn extract_token(auth_header: &str) -> Option<&str> {
if auth_header.starts_with(BEARER_PREFIX) {
Some(&auth_header[BEARER_PREFIX.len()..])
} else {
None
}
pub async fn new(jwt_issuer_key: DecodingKey) -> Self {
Self { jwt_issuer_key }
}
}

Expand All @@ -64,7 +56,8 @@ impl Authorizer for JWTAuthorizer {
.get("Authorization")
.ok_or(VssError::AuthError("Authorization header not found.".to_string()))?;

let token = JWTAuthorizer::extract_token(auth_header)
let token = auth_header
.strip_prefix(BEARER_PREFIX)
.ok_or(VssError::AuthError("Invalid token format.".to_string()))?;

let claims =
Expand Down
4 changes: 2 additions & 2 deletions rust/impls/src/postgres_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ impl KvStore for PostgresBackendImpl {

let stmt = "SELECT key, version FROM vss_db WHERE user_token = $1 AND store_id = $2 AND key > $3 AND key LIKE $4 ORDER BY key LIMIT $5";

let key_like = format!("{}%", key_prefix.as_deref().unwrap_or(""));
let page_token_param = page_token.as_deref().unwrap_or("");
let key_like = format!("{}%", key_prefix.as_deref().unwrap_or_default());
let page_token_param = page_token.as_deref().unwrap_or_default();
let params: Vec<&(dyn tokio_postgres::types::ToSql + Sync)> =
vec![&user_token, &store_id, &page_token_param, &key_like, &limit];

Expand Down
4 changes: 2 additions & 2 deletions rust/server/src/vss_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Service<Request<Incoming>> for VssService {
let path = req.uri().path().to_owned();

Box::pin(async move {
let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or("");
let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or_default();

match prefix_stripped_path {
"/getObject" => {
Expand Down Expand Up @@ -103,7 +103,7 @@ async fn handle_request<
let headers_map = parts
.headers
.iter()
.map(|(k, v)| (k.as_str().to_string(), v.to_str().unwrap_or("").to_string()))
.map(|(k, v)| (k.as_str().to_string(), v.to_str().unwrap_or_default().to_string()))
.collect::<HashMap<String, String>>();

let user_token = match authorizer.verify(&headers_map).await {
Expand Down