get PEM from memory, handle scope function errors

This commit is contained in:
yggverse 2024-12-07 00:28:11 +02:00
parent 4e354b3e26
commit 2b3852e706
2 changed files with 54 additions and 47 deletions

View File

@ -39,7 +39,6 @@ impl List {
match Item::new_profile_identity_gemini_id( match Item::new_profile_identity_gemini_id(
profile.clone(), profile.clone(),
identity.id, identity.id,
&identity.pem,
auth_url, auth_url,
) { ) {
Ok(item) => list_store.append(&item), Ok(item) => list_store.append(&item),

View File

@ -57,28 +57,33 @@ impl Item {
pub fn new_profile_identity_gemini_id( pub fn new_profile_identity_gemini_id(
profile: Rc<Profile>, profile: Rc<Profile>,
profile_identity_gemini_id: i64, profile_identity_gemini_id: i64,
pem: &str,
auth_url: &str, auth_url: &str,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
match TlsCertificate::from_pem(pem) { // Get PEM by ID
Ok(certificate) => { match profile
// Collect shared certificate scope .identity
let scope = scope(profile.clone(), profile_identity_gemini_id); .gemini
.memory
// Build GObject .get(profile_identity_gemini_id)
Ok(Object::builder() {
// Extract certificate details from PEM string
Ok(ref pem) => match TlsCertificate::from_pem(pem) {
// Collect certificate scopes for item
Ok(ref certificate) => match scope(profile.clone(), profile_identity_gemini_id) {
// Ready to build `Item` GObject
Ok(ref scope) => Ok(Object::builder()
.property("value", profile_identity_gemini_id) .property("value", profile_identity_gemini_id)
.property( .property(
"title", "title",
title::new_for_profile_identity_gemini_id(&certificate), title::new_for_profile_identity_gemini_id(certificate),
) )
.property( .property(
"subtitle", "subtitle",
subtitle::new_for_profile_identity_gemini_id(&certificate, &scope), subtitle::new_for_profile_identity_gemini_id(certificate, scope),
) )
.property( .property(
"tooltip", "tooltip",
tooltip::new_for_profile_identity_gemini_id(&certificate, &scope), tooltip::new_for_profile_identity_gemini_id(certificate, scope),
) )
.property( .property(
"is_active", "is_active",
@ -88,9 +93,12 @@ impl Item {
auth_url, auth_url,
), ),
) )
.build()) .build()),
} Err(_) => todo!(),
},
Err(e) => Err(Error::TlsCertificate(e)), Err(e) => Err(Error::TlsCertificate(e)),
},
Err(_) => todo!(),
} }
} }
@ -109,19 +117,19 @@ impl Item {
// Tools // Tools
fn scope(profile: Rc<Profile>, profile_identity_gemini_id: i64) -> Vec<String> { /// Collect certificate scope vector from `Profile` database for `profile_identity_gemini_id`
fn scope(profile: Rc<Profile>, profile_identity_gemini_id: i64) -> Result<Vec<String>, Error> {
match profile.identity.gemini.auth.database.records_scope(None) {
Ok(result) => {
let mut scope = Vec::new(); let mut scope = Vec::new();
for auth in profile for auth in result
.identity
.gemini
.auth
.database
.records_scope(None)
.unwrap()
.iter() .iter()
.filter(|this| this.profile_identity_gemini_id == profile_identity_gemini_id) .filter(|this| this.profile_identity_gemini_id == profile_identity_gemini_id)
{ {
scope.push(auth.scope.clone()) scope.push(auth.scope.clone())
} }
scope Ok(scope)
}
Err(_) => todo!(),
}
} }