fix authentication

turns out i was wrong, it was my code that was at fault
Few months ago this was working but I guess the API changed...
This commit is contained in:
2005 2024-05-21 05:26:25 +02:00
parent a6c1c5353e
commit b01b6cf420
5 changed files with 25 additions and 23 deletions

View file

@ -1,5 +1,7 @@
LISTEN_ADDRES=0.0.0.0
PORT=5733
# Listen address and port
PORT=3344
IP="0.0.0.0"
ROUTER_URL=https://127.0.0.1:7650
ROUTER_PASSWORD=itoopie
# Router url and password
PASSWORD="itoopie"
ROUTER=https://localhost:7650/

View file

@ -7,9 +7,9 @@ services:
context: .
container_name: i2pd-exporter
environment:
- IP=${LISTEN_ADDRESS}
- IP=${IP}
- PORT=${PORT}
- ROUTER=${ROUTER_URL}
- PASSWORD=${ROUTER_PASSWORD}
- ROUTER=${ROUTER}
- PASSWORD=${PASSWORD}
ports:
- "${PORT}:${PORT}"

View file

@ -1,7 +1,6 @@
# I2PD exporter
A basic prometheus exporter that exports miscellaneous data using the i2pcontrol protocol such as peers, data sent & received and so on...
Right now there are some problems with using exporter as the options for i2pd in nixpkgs are wrong... Therefore upon starting the program will error out with `InvalidPassword`. But it works alright on other systems
## How to use (Nix)

View file

@ -1,4 +1,3 @@
use std::{default, f32::consts::E};
use derive_builder::Builder;
use serde::Deserialize;
@ -14,8 +13,8 @@ pub struct I2PControl {
#[builder(default = "false")]
authenticated: bool,
#[builder(default = "0")]
token: i64,
token: String,
password: String,
}
@ -59,15 +58,12 @@ impl I2PControl {
Err(_) => return Err(I2PControlError::InvalidResponse),
};
match data.result.pointer("/token") {
match data.result.pointer("/Token") {
None => return Err(I2PControlError::InvalidPassword),
Some(token) => match token.as_i64() {
Some(token) => {
self.authenticated = true;
self.token = token;
self.token = token.to_string();
}
None => return Err(I2PControlError::InvalidResponse),
},
}
return Ok(());

View file

@ -37,16 +37,21 @@ async fn main() {
)
.endpoint(Url::parse(&c.router).unwrap())
.password(c.password.into())
.token("".to_string())
.build()
.unwrap();
loop {
thread::sleep(Duration::from_secs(1));
match client.auth().await {
Ok(_) => (),
Ok(_) => {
println!("Successfully authenticated");
break
},
Err(error) => {
println!("Failed to authenticate: {:?}", error)
println!("Failed to authenticate: {:?}... retrying in 1 seconds", error)
}
};
}