-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(backend): Refactor backend and some other code, no functional c…
…hange
- Loading branch information
1 parent
ff41844
commit 9efc6e4
Showing
10 changed files
with
354 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use ic_management_types::Network; | ||
use std::str::FromStr; | ||
use url::Url; | ||
|
||
pub fn target_network() -> Network { | ||
Network::from_str(&std::env::var("NETWORK").expect("Missing NETWORK environment variable")) | ||
.expect("Invalid network") | ||
} | ||
|
||
pub fn nns_url() -> String { | ||
std::env::var("NNS_URL").expect("NNS_URL environment variable not provided") | ||
} | ||
|
||
pub fn nns_nodes_urls() -> Vec<Url> { | ||
vec![Url::parse(&nns_url()).expect("Cannot parse NNS_URL environment variable as a valid URL")] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use gitlab::{api::AsyncQuery, AsyncGitlab}; | ||
use hyper::StatusCode; | ||
use ic_management_types::{FactsDBGuest, Guest}; | ||
use log::warn; | ||
|
||
pub async fn query_guests(gitlab_client: AsyncGitlab, network: String) -> anyhow::Result<Vec<Guest>> { | ||
::gitlab::api::raw( | ||
::gitlab::api::projects::repository::files::FileRaw::builder() | ||
.ref_("refs/heads/main") | ||
.project("dfinity-lab/core/release") | ||
.file_path(format!("factsdb/data/{}_guests.csv", network)) | ||
.build() | ||
.expect("failed to build API endpoint"), | ||
) | ||
.query_async(&gitlab_client) | ||
.await | ||
.map(|r| { | ||
csv::Reader::from_reader(r.as_slice()) | ||
.deserialize() | ||
.map(|r| { | ||
let fdbg: FactsDBGuest = r.expect("record failed to parse"); | ||
Guest::from(fdbg) | ||
}) | ||
.collect::<Vec<_>>() | ||
}) | ||
.or_else(|e| match e { | ||
::gitlab::api::ApiError::Gitlab { msg } if msg.starts_with(&StatusCode::NOT_FOUND.as_u16().to_string()) => { | ||
warn!("No factsdb guests file found for network {network}: {msg}"); | ||
Ok(vec![]) | ||
} | ||
_ => Err(anyhow::anyhow!(e)), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
pub mod config; | ||
pub mod factsdb; | ||
pub mod gitlab; | ||
pub mod health; | ||
pub mod prometheus; | ||
pub mod proposal; | ||
pub mod public_dashboard; | ||
pub mod registry; | ||
pub mod release; | ||
pub mod subnets; |
Oops, something went wrong.