mirror of
https://github.com/logos-blockchain/logos-blockchain-pocs.git
synced 2026-05-02 15:43:11 +00:00
credentials
This commit is contained in:
parent
c1d14a1ef9
commit
dcf80d95b1
@ -2,34 +2,51 @@ use std::ops::Range;
|
|||||||
|
|
||||||
use executor_http_client::{BasicAuthCredentials, ExecutorHttpClient};
|
use executor_http_client::{BasicAuthCredentials, ExecutorHttpClient};
|
||||||
use nomos::CryptarchiaInfo;
|
use nomos::CryptarchiaInfo;
|
||||||
use reqwest::Url;
|
use reqwest::{RequestBuilder, Url};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tracing::{error, error_span, info};
|
use tracing::{error, info};
|
||||||
|
|
||||||
pub const CRYPTARCHIA_INFO: &str = "/cryptarchia/info";
|
pub const CRYPTARCHIA_INFO: &str = "/cryptarchia/info";
|
||||||
pub const STORAGE_BLOCK: &str = "/storage/block";
|
pub const STORAGE_BLOCK: &str = "/storage/block";
|
||||||
|
|
||||||
mod nomos;
|
mod nomos;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Credentials {
|
||||||
|
pub username: String,
|
||||||
|
pub password: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct NomosClient {
|
pub struct NomosClient {
|
||||||
base_url: Url,
|
base_url: Url,
|
||||||
reqwest_client: reqwest::Client,
|
reqwest_client: reqwest::Client,
|
||||||
|
basic_auth: Credentials,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NomosClient {
|
impl NomosClient {
|
||||||
pub fn new(base_url: Url) -> Self {
|
pub fn new(base_url: Url, basic_auth: Credentials) -> Self {
|
||||||
Self {
|
Self {
|
||||||
base_url,
|
base_url,
|
||||||
reqwest_client: reqwest::Client::new(),
|
reqwest_client: reqwest::Client::new(),
|
||||||
|
basic_auth,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_cryptarchia_info(
|
pub async fn get_cryptarchia_info(&self) -> Result<CryptarchiaInfo, reqwest::Error> {
|
||||||
&self,
|
let url = self.base_url.join(CRYPTARCHIA_INFO).expect("Invalid URL");
|
||||||
base_url: Url,
|
|
||||||
) -> Result<CryptarchiaInfo, reqwest::Error> {
|
let request = self.reqwest_client.get(url).basic_auth(
|
||||||
let url = base_url.join(CRYPTARCHIA_INFO).expect("Invalid URL");
|
self.basic_auth.username.clone(),
|
||||||
let response = self.reqwest_client.get(url).send().await?;
|
self.basic_auth.password.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
|
info!("Sending request with creds {:?}", self.basic_auth);
|
||||||
|
|
||||||
|
let response = request.send().await?;
|
||||||
|
if !response.status().is_success() {
|
||||||
|
error!("Failed to get cryptarchia info: {}", response.status());
|
||||||
|
}
|
||||||
|
|
||||||
let info = response.json::<CryptarchiaInfo>().await?;
|
let info = response.json::<CryptarchiaInfo>().await?;
|
||||||
Ok(info)
|
Ok(info)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use evm_lightnode::NomosClient;
|
use evm_lightnode::{Credentials, NomosClient};
|
||||||
|
use executor_http_client::BasicAuthCredentials;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use std::error;
|
use std::error;
|
||||||
@ -19,13 +20,22 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
|
|||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string());
|
let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string());
|
||||||
|
let user = std::env::var("NOMOS_USER").unwrap_or_default();
|
||||||
|
let password = std::env::var("NOMOS_PASSWORD").unwrap_or_default();
|
||||||
|
let basic_auth = Credentials {
|
||||||
|
username: user,
|
||||||
|
password: Some(password),
|
||||||
|
};
|
||||||
|
|
||||||
let filter =
|
let filter =
|
||||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&args.log_level));
|
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&args.log_level));
|
||||||
|
|
||||||
fmt::fmt().with_env_filter(filter).with_target(false).init();
|
fmt::fmt().with_env_filter(filter).with_target(false).init();
|
||||||
|
|
||||||
let consensus = NomosClient::new(Url::parse(&url).unwrap());
|
let consensus = NomosClient::new(Url::parse(&url).unwrap(), basic_auth);
|
||||||
|
|
||||||
|
let info = consensus.get_cryptarchia_info().await?;
|
||||||
|
println!("Cryptarchia Info: {:?}", info);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user