Skip to content

Commit c54b2c3

Browse files
authored
Merge pull request #49 from andrei-21/feature/goodies
Simplify some code
2 parents c7097c0 + c3f8d50 commit c54b2c3

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

rust/auth-impls/src/lib.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,8 @@ const BEARER_PREFIX: &str = "Bearer ";
4242

4343
impl JWTAuthorizer {
4444
/// Create new instance of [`JWTAuthorizer`]
45-
pub async fn new(jwt_issuer_key: DecodingKey) -> JWTAuthorizer {
46-
JWTAuthorizer { jwt_issuer_key }
47-
}
48-
49-
fn extract_token(auth_header: &str) -> Option<&str> {
50-
if auth_header.starts_with(BEARER_PREFIX) {
51-
Some(&auth_header[BEARER_PREFIX.len()..])
52-
} else {
53-
None
54-
}
45+
pub async fn new(jwt_issuer_key: DecodingKey) -> Self {
46+
Self { jwt_issuer_key }
5547
}
5648
}
5749

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

67-
let token = JWTAuthorizer::extract_token(auth_header)
59+
let token = auth_header
60+
.strip_prefix(BEARER_PREFIX)
6861
.ok_or(VssError::AuthError("Invalid token format.".to_string()))?;
6962

7063
let claims =

rust/impls/src/postgres_store.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ impl KvStore for PostgresBackendImpl {
376376

377377
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";
378378

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

rust/server/src/vss_service.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Service<Request<Incoming>> for VssService {
4343
let path = req.uri().path().to_owned();
4444

4545
Box::pin(async move {
46-
let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or("");
46+
let prefix_stripped_path = path.strip_prefix(BASE_PATH_PREFIX).unwrap_or_default();
4747

4848
match prefix_stripped_path {
4949
"/getObject" => {
@@ -103,7 +103,7 @@ async fn handle_request<
103103
let headers_map = parts
104104
.headers
105105
.iter()
106-
.map(|(k, v)| (k.as_str().to_string(), v.to_str().unwrap_or("").to_string()))
106+
.map(|(k, v)| (k.as_str().to_string(), v.to_str().unwrap_or_default().to_string()))
107107
.collect::<HashMap<String, String>>();
108108

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

0 commit comments

Comments
 (0)