mirror of
https://git.proxmox.com/git/proxmox-perl-rs
synced 2025-07-27 09:50:49 +00:00
perl-rs: use proxmox-apt-api-types
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
83427e9204
commit
9eda29d688
@ -1,34 +1,12 @@
|
||||
#[perlmod::package(name = "Proxmox::RS::APT::Repositories")]
|
||||
pub mod export {
|
||||
use std::convert::TryInto;
|
||||
|
||||
use anyhow::{bail, Error};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use proxmox_apt::repositories::{
|
||||
APTRepositoryFile, APTRepositoryFileError, APTRepositoryHandle, APTRepositoryInfo,
|
||||
APTStandardRepository,
|
||||
};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
/// Result for the repositories() function
|
||||
pub struct RepositoriesResult {
|
||||
/// Successfully parsed files.
|
||||
pub files: Vec<APTRepositoryFile>,
|
||||
|
||||
/// Errors for files that could not be parsed or read.
|
||||
pub errors: Vec<APTRepositoryFileError>,
|
||||
|
||||
/// Common digest for successfully parsed files.
|
||||
pub digest: String,
|
||||
|
||||
/// Additional information/warnings about repositories.
|
||||
pub infos: Vec<APTRepositoryInfo>,
|
||||
|
||||
/// Standard repositories and their configuration status.
|
||||
pub standard_repos: Vec<APTStandardRepository>,
|
||||
}
|
||||
use proxmox_apt::repositories::{APTRepositoryFileImpl, APTRepositoryImpl};
|
||||
use proxmox_apt_api_types::{APTRepositoriesResult, APTRepositoryFile, APTRepositoryHandle};
|
||||
use proxmox_config_digest::ConfigDigest;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
@ -40,9 +18,8 @@ pub mod export {
|
||||
|
||||
/// Get information about configured repositories and standard repositories for `product`.
|
||||
#[export]
|
||||
pub fn repositories(product: &str) -> Result<RepositoriesResult, Error> {
|
||||
pub fn repositories(product: &str) -> Result<APTRepositoriesResult, Error> {
|
||||
let (files, errors, digest) = proxmox_apt::repositories::repositories()?;
|
||||
let digest = hex::encode(&digest);
|
||||
|
||||
let suite = proxmox_apt::repositories::get_current_release_codename()?;
|
||||
|
||||
@ -50,7 +27,7 @@ pub mod export {
|
||||
let standard_repos =
|
||||
proxmox_apt::repositories::standard_repositories(&files, product, suite);
|
||||
|
||||
Ok(RepositoriesResult {
|
||||
Ok(APTRepositoriesResult {
|
||||
files,
|
||||
errors,
|
||||
digest,
|
||||
@ -64,18 +41,17 @@ pub mod export {
|
||||
///
|
||||
/// The `digest` parameter asserts that the configuration has not been modified.
|
||||
#[export]
|
||||
pub fn add_repository(handle: &str, product: &str, digest: Option<&str>) -> Result<(), Error> {
|
||||
pub fn add_repository(
|
||||
handle: &str,
|
||||
product: &str,
|
||||
digest: Option<ConfigDigest>,
|
||||
) -> Result<(), Error> {
|
||||
let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?;
|
||||
|
||||
let handle: APTRepositoryHandle = handle.try_into()?;
|
||||
let handle: APTRepositoryHandle = handle.parse()?;
|
||||
let suite = proxmox_apt::repositories::get_current_release_codename()?;
|
||||
|
||||
if let Some(digest) = digest {
|
||||
let expected_digest = hex::decode(digest)?;
|
||||
if expected_digest != current_digest {
|
||||
bail!("detected modified configuration - file changed by other user? Try again.");
|
||||
}
|
||||
}
|
||||
current_digest.detect_modification(digest.as_ref())?;
|
||||
|
||||
// check if it's already configured first
|
||||
for file in files.iter_mut() {
|
||||
@ -133,16 +109,11 @@ pub mod export {
|
||||
path: &str,
|
||||
index: usize,
|
||||
options: ChangeProperties,
|
||||
digest: Option<&str>,
|
||||
digest: Option<ConfigDigest>,
|
||||
) -> Result<(), Error> {
|
||||
let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?;
|
||||
|
||||
if let Some(digest) = digest {
|
||||
let expected_digest = hex::decode(digest)?;
|
||||
if expected_digest != current_digest {
|
||||
bail!("detected modified configuration - file changed by other user? Try again.");
|
||||
}
|
||||
}
|
||||
current_digest.detect_modification(digest.as_ref())?;
|
||||
|
||||
if let Some(error) = errors.iter().find(|error| error.path == path) {
|
||||
bail!("unable to parse file {} - {}", error.path, error.error);
|
||||
|
@ -8,14 +8,10 @@ edition = "2021"
|
||||
license = "AGPL-3"
|
||||
repository = "https://git.proxmox.com/?p=proxmox.git"
|
||||
|
||||
exclude = [
|
||||
"build",
|
||||
"debian",
|
||||
"PMG",
|
||||
]
|
||||
exclude = ["build", "debian", "PMG"]
|
||||
|
||||
[lib]
|
||||
crate-type = [ "cdylib" ]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
@ -30,10 +26,12 @@ serde_bytes = "0.11"
|
||||
serde_json = "1.0"
|
||||
url = "2"
|
||||
|
||||
perlmod = { version = "0.13.4", features = [ "exporter" ] }
|
||||
perlmod = { version = "0.13.4", features = ["exporter"] }
|
||||
|
||||
proxmox-acme = { version = "0.5", features = ["client", "api-types"] }
|
||||
proxmox-apt = "0.10"
|
||||
proxmox-apt = "0.11"
|
||||
proxmox-apt-api-types = "1.0"
|
||||
proxmox-config-digest = "0.1"
|
||||
proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] }
|
||||
proxmox-http-error = "0.1.0"
|
||||
proxmox-notify = "0.4"
|
||||
|
@ -1,12 +1,14 @@
|
||||
#[perlmod::package(name = "PMG::RS::APT::Repositories")]
|
||||
mod export {
|
||||
use anyhow::Error;
|
||||
use proxmox_apt_api_types::APTRepositoriesResult;
|
||||
use proxmox_config_digest::ConfigDigest;
|
||||
|
||||
use crate::common::apt::repositories::export as common;
|
||||
|
||||
/// Get information about configured and standard repositories.
|
||||
#[export]
|
||||
pub fn repositories() -> Result<common::RepositoriesResult, Error> {
|
||||
pub fn repositories() -> Result<APTRepositoriesResult, Error> {
|
||||
common::repositories("pmg")
|
||||
}
|
||||
|
||||
@ -15,7 +17,7 @@ mod export {
|
||||
///
|
||||
/// The `digest` parameter asserts that the configuration has not been modified.
|
||||
#[export]
|
||||
pub fn add_repository(handle: &str, digest: Option<&str>) -> Result<(), Error> {
|
||||
pub fn add_repository(handle: &str, digest: Option<ConfigDigest>) -> Result<(), Error> {
|
||||
common::add_repository(handle, "pmg", digest)
|
||||
}
|
||||
|
||||
@ -27,7 +29,7 @@ mod export {
|
||||
path: &str,
|
||||
index: usize,
|
||||
options: common::ChangeProperties,
|
||||
digest: Option<&str>,
|
||||
digest: Option<ConfigDigest>,
|
||||
) -> Result<(), Error> {
|
||||
common::change_repository(path, index, options, digest)
|
||||
}
|
||||
|
@ -8,12 +8,10 @@ edition = "2021"
|
||||
license = "AGPL-3"
|
||||
repository = "https://git.proxmox.com/?p=proxmox.git"
|
||||
|
||||
exclude = [
|
||||
"debian",
|
||||
]
|
||||
exclude = ["debian"]
|
||||
|
||||
[lib]
|
||||
crate-type = [ "cdylib" ]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
@ -31,9 +29,11 @@ serde_bytes = "0.11"
|
||||
serde_json = "1.0"
|
||||
url = "2"
|
||||
|
||||
perlmod = { version = "0.13", features = [ "exporter" ] }
|
||||
perlmod = { version = "0.13", features = ["exporter"] }
|
||||
|
||||
proxmox-apt = "0.10.6"
|
||||
proxmox-apt = "0.11"
|
||||
proxmox-apt-api-types = "1.0"
|
||||
proxmox-config-digest = "0.1"
|
||||
proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] }
|
||||
proxmox-http-error = "0.1.0"
|
||||
proxmox-notify = { version = "0.4", features = ["pve-context"] }
|
||||
|
@ -2,11 +2,14 @@
|
||||
mod export {
|
||||
use anyhow::Error;
|
||||
|
||||
use proxmox_apt_api_types::APTRepositoriesResult;
|
||||
use proxmox_config_digest::ConfigDigest;
|
||||
|
||||
use crate::common::apt::repositories::export as common;
|
||||
|
||||
/// Get information about configured and standard repositories.
|
||||
#[export]
|
||||
pub fn repositories() -> Result<common::RepositoriesResult, Error> {
|
||||
pub fn repositories() -> Result<APTRepositoriesResult, Error> {
|
||||
common::repositories("pve")
|
||||
}
|
||||
|
||||
@ -15,7 +18,7 @@ mod export {
|
||||
///
|
||||
/// The `digest` parameter asserts that the configuration has not been modified.
|
||||
#[export]
|
||||
pub fn add_repository(handle: &str, digest: Option<&str>) -> Result<(), Error> {
|
||||
pub fn add_repository(handle: &str, digest: Option<ConfigDigest>) -> Result<(), Error> {
|
||||
common::add_repository(handle, "pve", digest)
|
||||
}
|
||||
|
||||
@ -27,7 +30,7 @@ mod export {
|
||||
path: &str,
|
||||
index: usize,
|
||||
options: common::ChangeProperties,
|
||||
digest: Option<&str>,
|
||||
digest: Option<ConfigDigest>,
|
||||
) -> Result<(), Error> {
|
||||
common::change_repository(path, index, options, digest)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user