Skip to content

Commit

Permalink
Fix token expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
syepes committed Jun 11, 2021
1 parent a747e86 commit ab86835
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang

## [Unreleased]

## 0.2.1 - 2021-06-11

- Fix auth token expiration

## 0.2.0 - 2021-06-07

- Compleate revamp and updated all dependencies
- Added State metrics for sds, sdc and device
- Complete revamp and updated all dependencies
- Added State metrics for sds, sdc and device (https://github.com/syepes/sio2prom/blob/master/src/sio/metrics.rs#L46)
- Removed file configuration (sio2prom.json), it's now all done with params or environment vars
- Removed log file (log4rs.toml), it's now Stdout and managed with -v
- New docker builds for linux/amd64, linux/arm/v7 and linux/arm64
- New docker builds for linux/amd64, linux/arm/v7 and linux/arm64 (https://hub.docker.com/r/syepes/sio2prom/tags)
- Tested with the last versions of PowerFlex (<=3.5)

## 0.1.3 - 2017-04-23
Expand Down
34 changes: 17 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sio2prom"
version = "0.2.0"
version = "0.2.1"
edition = "2018"
resolver = "2"
authors = ["Sebastian YEPES F <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
docker run -d --name sio2prom -h sio2prom -e IP=1.1.1.1 -e AUTH_USR=mon -e AUTH_PWD=mon -v $PWD/cfg:/app/cfg/ -p 8080:8080 syepes/sio2prom

# Metrics
curl -v -i https://localhost:8080/metrics
curl -v -i http://localhost:8080/metrics

## Usage (Built from src)

Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ async fn data_collector(app: ArgMatches) {
let mut collect_interval = tokio::time::interval(Duration::from_secs(interval));

let mut sio = sio::client::ClientInfo::new(app.value_of("ip"), app.value_of("auth_usr"), app.value_of("auth_pwd"));
sio.auth().await;

loop {
let metrics = sio.metrics().await;
Expand Down
12 changes: 8 additions & 4 deletions src/sio/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'a> ClientInfo<'a> {
token: RefCell::new(None) }
}

pub async fn auth(&mut self) {
async fn auth(&mut self) {
trace!("auth");
if let Ok(c) = reqwest::Client::builder().user_agent(env!("CARGO_PKG_NAME")).danger_accept_invalid_certs(true).timeout(Duration::from_secs(10)).connection_verbose(true).build() {
if !self.auth_usr.unwrap().is_empty() && !self.auth_pwd.unwrap().is_empty() {
Expand Down Expand Up @@ -93,7 +93,10 @@ impl<'a> ClientInfo<'a> {
_ => Err(anyhow!("Failed to parse json")),
}
},
StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => Err(anyhow!("Auth failed")),
StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => {
*self.token.borrow_mut() = None;
Err(anyhow!("Auth failed"))
},
_ => {
let msg = match r.json::<serde_json::Value>().await.unwrap() {
Value::Object(m) => m.get("message").unwrap().to_string(),
Expand Down Expand Up @@ -534,12 +537,13 @@ impl<'a> ClientInfo<'a> {

// pub fn metrics(&mut self) -> Option<Vec<Metric>> {
pub async fn metrics(&mut self) -> Option<Vec<super::metrics::Metric>> {
let inst = self.instances().await;
info!("Loaded instances: {:?}", &inst.as_ref().unwrap().keys().collect::<Vec<_>>());
self.auth().await;

let inst = self.instances().await;
if inst.is_err() {
return None;
}
info!("Loaded instances: {:?}", &inst.as_ref().unwrap().keys().collect::<Vec<_>>());

let rela = self.relations(inst.as_ref().unwrap());
if rela.is_err() {
Expand Down

0 comments on commit ab86835

Please sign in to comment.