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