Skip to content

Commit

Permalink
feat(rust): import repositories GPG keys
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Dec 13, 2024
1 parent 5ee9f09 commit f73b699
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/agama-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gethostname = "0.4.3"
tokio-util = "0.7.12"
serde_yaml = "0.9.34"
zypp-agama = { path = "../zypp-c-api/rust/zypp-agama" }
glob = "0.3.1"

[[bin]]
name = "agama-dbus-server"
Expand Down
19 changes: 19 additions & 0 deletions rust/agama-server/src/software_ng/backend/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::{
use super::{client::SoftwareServiceClient, SoftwareServiceError};

const TARGET_DIR: &str = "/run/agama/software_ng_zypp";
const GPG_KEYS: &str = "/usr/lib/rpm/gnupg/keys/gpg-*";

#[derive(Debug)]
pub enum SoftwareAction {
Expand Down Expand Up @@ -202,12 +203,30 @@ impl SoftwareServiceServer {
if target_dir.exists() {
_ = std::fs::remove_dir_all(target_dir);
}

std::fs::create_dir_all(target_dir).map_err(SoftwareServiceError::TargetCreationFailed)?;

zypp_agama::init_target(TARGET_DIR, |text, step, total| {
tracing::info!("Initializing target: {} ({}/{})", text, step, total);
})
.map_err(SoftwareServiceError::TargetInitFailed)?;

self.import_gpg_keys();
Ok(())
}

fn import_gpg_keys(&self) {
for file in glob::glob(GPG_KEYS).unwrap() {
match file {
Ok(file) => {
if let Err(e) = zypp_agama::import_gpg_key(&file.to_string_lossy()) {
tracing::error!("Failed to import GPG key: {}", e);
}
}
Err(e) => {
tracing::error!("Could not read GPG key file: {}", e);
}
}
}
}
}

0 comments on commit f73b699

Please sign in to comment.