mirror of
https://codeberg.org/icewind/prometheus-edge-trigger.git
synced 2026-06-03 10:14:12 +02:00
use secretfile
This commit is contained in:
parent
559773598b
commit
e01a0f76f5
3 changed files with 14 additions and 5 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -1170,6 +1170,7 @@ dependencies = [
|
||||||
"prometheus-edge-detector",
|
"prometheus-edge-detector",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rumqttc",
|
"rumqttc",
|
||||||
|
"secretfile",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
@ -1407,6 +1408,15 @@ dependencies = [
|
||||||
"untrusted",
|
"untrusted",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secretfile"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "746c54b939ab8d393b536765393c0bd7634fca94eed62321ec3e3559293f6c21"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework"
|
name = "security-framework"
|
||||||
version = "2.9.2"
|
version = "2.9.2"
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ thiserror = "1.0.57"
|
||||||
serde_json = "1.0.113"
|
serde_json = "1.0.113"
|
||||||
rumqttc = "0.23.0"
|
rumqttc = "0.23.0"
|
||||||
hostname = "0.3.1"
|
hostname = "0.3.1"
|
||||||
|
secretfile = "0.1.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::mdns::resolve_mdns;
|
use crate::mdns::resolve_mdns;
|
||||||
|
use secretfile::{load, SecretError};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fs::read_to_string;
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
@ -122,14 +122,12 @@ pub enum MqttPassword {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<RawMqttConfig> for MqttConfig {
|
impl TryFrom<RawMqttConfig> for MqttConfig {
|
||||||
type Error = std::io::Error;
|
type Error = SecretError;
|
||||||
|
|
||||||
fn try_from(value: RawMqttConfig) -> Result<Self, Self::Error> {
|
fn try_from(value: RawMqttConfig) -> Result<Self, Self::Error> {
|
||||||
let password = match value.password {
|
let password = match value.password {
|
||||||
Some(MqttPassword::Raw { password }) => Some(password),
|
Some(MqttPassword::Raw { password }) => Some(password),
|
||||||
Some(MqttPassword::File { password_file }) => {
|
Some(MqttPassword::File { password_file }) => Some(load(&password_file)?),
|
||||||
Some(read_to_string(password_file)?.trim().to_string())
|
|
||||||
}
|
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
Ok(MqttConfig {
|
Ok(MqttConfig {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue