1 //! Tools and utilities
3 //! This is a collection of small and useful tools.
6 use anyhow
::{bail, Error}
;
8 use proxmox_http
::{client::SimpleHttp, client::SimpleHttpOptions, ProxyConfig}
;
15 mod shared_rate_limiter
;
16 pub use shared_rate_limiter
::SharedRateLimiter
;
22 pub mod parallel_handler
;
24 pub fn assert_if_modified(digest1
: &str, digest2
: &str) -> Result
<(), Error
> {
25 if digest1
!= digest2
{
26 bail
!("detected modified configuration - file changed by other user? Try again.");
31 /// Detect modified configuration files
33 /// This function fails with a reasonable error message if checksums do not match.
34 pub fn detect_modified_configuration_file(
37 ) -> Result
<(), Error
> {
38 if digest1
!= digest2
{
39 bail
!("detected modified configuration - file changed by other user? Try again.");
44 /// An easy way to convert types to Any
46 /// Mostly useful to downcast trait objects (see RpcEnvironment).
48 fn as_any(&self) -> &dyn Any
;
51 impl<T
: Any
> AsAny
for T
{
52 fn as_any(&self) -> &dyn Any
{
57 /// The default 2 hours are far too long for PBS
58 pub const PROXMOX_BACKUP_TCP_KEEPALIVE_TIME
: u32 = 120;
59 pub const DEFAULT_USER_AGENT_STRING
: &str = "proxmox-backup-client/1.0";
61 /// Returns a new instance of `SimpleHttp` configured for PBS usage.
62 pub fn pbs_simple_http(proxy_config
: Option
<ProxyConfig
>) -> SimpleHttp
{
63 let options
= SimpleHttpOptions
{
65 user_agent
: Some(DEFAULT_USER_AGENT_STRING
.to_string()),
66 tcp_keepalive
: Some(PROXMOX_BACKUP_TCP_KEEPALIVE_TIME
),
69 SimpleHttp
::with_options(options
)
72 pub fn setup_safe_path_env() {
73 std
::env
::set_var("PATH", "/sbin:/bin:/usr/sbin:/usr/bin");
74 // Make %ENV safer - as suggested by https://perldoc.perl.org/perlsec.html
75 for name
in &["IFS", "CDPATH", "ENV", "BASH_ENV"] {
76 std
::env
::remove_var(name
);