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,40 +57,48 @@ 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() {
.property("value", profile_identity_gemini_id) // Extract certificate details from PEM string
.property( Ok(ref pem) => match TlsCertificate::from_pem(pem) {
"title", // Collect certificate scopes for item
title::new_for_profile_identity_gemini_id(&certificate), Ok(ref certificate) => match scope(profile.clone(), profile_identity_gemini_id) {
) // Ready to build `Item` GObject
.property( Ok(ref scope) => Ok(Object::builder()
"subtitle", .property("value", profile_identity_gemini_id)
subtitle::new_for_profile_identity_gemini_id(&certificate, &scope), .property(
) "title",
.property( title::new_for_profile_identity_gemini_id(certificate),
"tooltip", )
tooltip::new_for_profile_identity_gemini_id(&certificate, &scope), .property(
) "subtitle",
.property( subtitle::new_for_profile_identity_gemini_id(certificate, scope),
"is_active", )
is_active::new_for_profile_identity_gemini_id( .property(
profile, "tooltip",
profile_identity_gemini_id, tooltip::new_for_profile_identity_gemini_id(certificate, scope),
auth_url, )
), .property(
) "is_active",
.build()) is_active::new_for_profile_identity_gemini_id(
} profile,
Err(e) => Err(Error::TlsCertificate(e)), profile_identity_gemini_id,
auth_url,
),
)
.build()),
Err(_) => todo!(),
},
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`
let mut scope = Vec::new(); fn scope(profile: Rc<Profile>, profile_identity_gemini_id: i64) -> Result<Vec<String>, Error> {
for auth in profile match profile.identity.gemini.auth.database.records_scope(None) {
.identity Ok(result) => {
.gemini let mut scope = Vec::new();
.auth for auth in result
.database .iter()
.records_scope(None) .filter(|this| this.profile_identity_gemini_id == profile_identity_gemini_id)
.unwrap() {
.iter() scope.push(auth.scope.clone())
.filter(|this| this.profile_identity_gemini_id == profile_identity_gemini_id) }
{ Ok(scope)
scope.push(auth.scope.clone()) }
Err(_) => todo!(),
} }
scope
} }