remove scheme from scope, rename build constructors

This commit is contained in:
yggverse 2025-01-23 11:46:43 +02:00
parent 9371f16798
commit 089a91d5a2
25 changed files with 103 additions and 72 deletions

View file

@ -65,8 +65,10 @@ impl Memory {
let mut result = Vec::new();
// Get all records starts with `scope`
let query = filter_scope(request);
for (scope, &profile_identity_id) in self.index.borrow().iter() {
if request.starts_with(scope) {
if query.starts_with(scope) {
result.push(Auth {
profile_identity_id,
scope: scope.clone(),
@ -81,3 +83,24 @@ impl Memory {
result.first().cloned()
}
}
/// Get valid identity scope for given URL
/// * helper function for different protocol drivers implementation
fn filter_scope(url: &str) -> String {
use gtk::glib::{Regex, RegexCompileFlags, RegexMatchFlags};
match Regex::split_simple(
r"^\w+://(.*)",
url,
RegexCompileFlags::DEFAULT,
RegexMatchFlags::DEFAULT,
)
.get(1)
{
Some(postfix) => postfix.to_string(),
None => url.to_string(),
}
.trim()
.trim_end_matches("/")
.to_lowercase()
}