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:
parent
a6c1c5353e
commit
b01b6cf420
10
.env.example
10
.env.example
|
@ -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/
|
|
@ -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}"
|
||||
|
|
|
@ -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
|
||||
A basic prometheus exporter that exports miscellaneous data using the i2pcontrol protocol such as peers, data sent & received and so on...
|
||||
|
||||
## How to use (Nix)
|
||||
|
||||
|
|
18
src/api.rs
18
src/api.rs
|
@ -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;
|
||||
}
|
||||
None => return Err(I2PControlError::InvalidResponse),
|
||||
},
|
||||
Some(token) => {
|
||||
self.authenticated = true;
|
||||
self.token = token.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -37,16 +37,21 @@ async fn main() {
|
|||
)
|
||||
.endpoint(Url::parse(&c.router).unwrap())
|
||||
.password(c.password.into())
|
||||
.token("".to_string())
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
||||
loop {
|
||||
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)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue