Setup config
This commit is contained in:
1063
Cargo.lock
generated
1063
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -7,10 +7,10 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
http = "1.1.0"
|
||||
proxmox-client = { git = "https://github.com/proxmox/proxmox-rs", version = "0.3.1", features = ["hyper-client"] }
|
||||
proxmox-login = { git = "https://github.com/proxmox/proxmox-rs", version = "0.1.1" }
|
||||
proxmox-client = { git = "git://git.proxmox.com/git/proxmox.git", branch = "master", features = ["hyper-client"] }
|
||||
tokio = { version = "1.37.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
anyhow = "1.0.83"
|
||||
log = "0.4.21"
|
||||
config = "0.14.0"
|
||||
config = { version = "0.14.0", features = ["toml"] }
|
||||
pretty_env_logger = "0.5.0"
|
||||
serde = { version = "1.0.213", features = ["derive"] }
|
||||
|
18
src/main.rs
18
src/main.rs
@ -1,23 +1,29 @@
|
||||
use std::default;
|
||||
|
||||
use config::{Config, ConfigBuilder};
|
||||
use log::info;
|
||||
use proxmox_client::{AuthenticationKind, HttpApiClient, TlsOptions, Token};
|
||||
use crate::settings::Settings;
|
||||
|
||||
mod settings;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), anyhow::Error> {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let addr = "https://10.97.0.234:8006/";
|
||||
let url = addr.parse().unwrap();
|
||||
let config: Settings = Config::builder()
|
||||
.add_source("config.toml")
|
||||
.build()?.try_deserialize()?;
|
||||
|
||||
let client = proxmox_client::Client::with_options(
|
||||
url,
|
||||
config.server,
|
||||
TlsOptions::Insecure,
|
||||
Default::default())?;
|
||||
|
||||
client.set_authentication(AuthenticationKind::Token(Token {
|
||||
userid: "root@pam!test-dev".to_string(),
|
||||
userid: config.token_id.clone(),
|
||||
prefix: "PVEAPIToken".to_string(),
|
||||
value: "e2d8d39f-63ce-48f0-a025-b428d29a26e3".to_string(),
|
||||
value: config.secret.clone(),
|
||||
perl_compat: false,
|
||||
}));
|
||||
|
||||
let rsp = client.get("/api2/json/version").await?;
|
||||
|
9
src/settings.rs
Normal file
9
src/settings.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use http::Uri;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Settings {
|
||||
pub server: Uri,
|
||||
pub token_id: String,
|
||||
pub secret: String,
|
||||
}
|
Reference in New Issue
Block a user