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
|
# Listen address and port
|
||||||
PORT=5733
|
PORT=3344
|
||||||
|
IP="0.0.0.0"
|
||||||
|
|
||||||
ROUTER_URL=https://127.0.0.1:7650
|
# Router url and password
|
||||||
ROUTER_PASSWORD=itoopie
|
PASSWORD="itoopie"
|
||||||
|
ROUTER=https://localhost:7650/
|
|
@ -7,9 +7,9 @@ services:
|
||||||
context: .
|
context: .
|
||||||
container_name: i2pd-exporter
|
container_name: i2pd-exporter
|
||||||
environment:
|
environment:
|
||||||
- IP=${LISTEN_ADDRESS}
|
- IP=${IP}
|
||||||
- PORT=${PORT}
|
- PORT=${PORT}
|
||||||
- ROUTER=${ROUTER_URL}
|
- ROUTER=${ROUTER}
|
||||||
- PASSWORD=${ROUTER_PASSWORD}
|
- PASSWORD=${PASSWORD}
|
||||||
ports:
|
ports:
|
||||||
- "${PORT}:${PORT}"
|
- "${PORT}:${PORT}"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# I2PD exporter
|
# I2PD exporter
|
||||||
|
|
||||||
A basic prometheus exporter that exports miscellaneous data using the i2pcontrol protocol such as peers, data sent & received and so on...
|
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)
|
## How to use (Nix)
|
||||||
|
|
||||||
|
|
12
src/api.rs
12
src/api.rs
|
@ -1,4 +1,3 @@
|
||||||
use std::{default, f32::consts::E};
|
|
||||||
|
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -14,8 +13,8 @@ pub struct I2PControl {
|
||||||
|
|
||||||
#[builder(default = "false")]
|
#[builder(default = "false")]
|
||||||
authenticated: bool,
|
authenticated: bool,
|
||||||
#[builder(default = "0")]
|
|
||||||
token: i64,
|
token: String,
|
||||||
|
|
||||||
password: String,
|
password: String,
|
||||||
}
|
}
|
||||||
|
@ -59,15 +58,12 @@ impl I2PControl {
|
||||||
Err(_) => return Err(I2PControlError::InvalidResponse),
|
Err(_) => return Err(I2PControlError::InvalidResponse),
|
||||||
};
|
};
|
||||||
|
|
||||||
match data.result.pointer("/token") {
|
match data.result.pointer("/Token") {
|
||||||
None => return Err(I2PControlError::InvalidPassword),
|
None => return Err(I2PControlError::InvalidPassword),
|
||||||
Some(token) => match token.as_i64() {
|
|
||||||
Some(token) => {
|
Some(token) => {
|
||||||
self.authenticated = true;
|
self.authenticated = true;
|
||||||
self.token = token;
|
self.token = token.to_string();
|
||||||
}
|
}
|
||||||
None => return Err(I2PControlError::InvalidResponse),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
@ -37,16 +37,21 @@ async fn main() {
|
||||||
)
|
)
|
||||||
.endpoint(Url::parse(&c.router).unwrap())
|
.endpoint(Url::parse(&c.router).unwrap())
|
||||||
.password(c.password.into())
|
.password(c.password.into())
|
||||||
|
.token("".to_string())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
||||||
|
thread::sleep(Duration::from_secs(1));
|
||||||
match client.auth().await {
|
match client.auth().await {
|
||||||
Ok(_) => (),
|
Ok(_) => {
|
||||||
|
println!("Successfully authenticated");
|
||||||
|
break
|
||||||
|
},
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
println!("Failed to authenticate: {:?}", error)
|
println!("Failed to authenticate: {:?}... retrying in 1 seconds", error)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue