Skip to content

Commit

Permalink
Merge pull request #62 from filecoin-project/logging-and-envs
Browse files Browse the repository at this point in the history
Version 1.0.4
  • Loading branch information
kokal33 authored Nov 14, 2023
2 parents 380e42d + dc8ec98 commit c859cfd
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ jobs:
"8080": "HTTP"
},
"environment": {
"MONGODB_URL": "${{secrets.MONGODB_URL}}",
"GH_PRIVATE_KEY": "${{secrets.GH_PRIVATE_KEY}}",
"GITHUB_OWNER": "${{secrets.GH_OWNER}}",
"GITHUB_REPO": "${{secrets.GH_REPO}}",
"GITHUB_APP_ID": "${{secrets.GH_APP_ID}}",
"GITHUB_INSTALLATION_ID": "${{secrets.GH_INSTALLATION_ID}}"
"RUST_LOG": "debug"
}
}
}' > containers.json
Expand Down
4 changes: 2 additions & 2 deletions fplus-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fplus-cli"
authors = ["jbesraa", "kokal33", "clriesco"]
version = "1.0.3"
version = "1.0.4"
edition = "2021"
description = "FPlus cli tool to validate different states of an application"
license = "MIT OR Apache-2.0"
Expand All @@ -13,4 +13,4 @@ readme = "README.md"
[dependencies]
actix-web = "4.4.0"
clap = { version = "4.4.6", features = ["derive"] }
fplus-lib = "1.0.3"
fplus-lib = "1.0.4"
5 changes: 3 additions & 2 deletions fplus-http-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fplus-http-server"
authors = ["jbesraa", "kokal33", "clriesco"]
version = "1.0.3"
version = "1.0.4"
description = "FPlus main http module"
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -20,8 +20,9 @@ actix-cors = "0.6.4"
reqwest = { version = "0.11.18", features = ["json"] }
futures = "0.3.28"
dotenv = "0.15.0"
fplus-lib = "1.0.3"
fplus-lib = "1.0.4"
anyhow = "1.0.75"
async-trait = "0.1.73"
uuidv4 = "1.0.0"
log = "0.4.20"

6 changes: 6 additions & 0 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
use std::env;

use actix_web::middleware::Logger;
use actix_web::{App, HttpServer};
use env_logger;
use log::info;

pub(crate) mod router;

#[tokio::main]
async fn main() -> std::io::Result<()> {
dotenv::dotenv().ok();
let log_level = env::var("RUST_LOG").unwrap_or_else(|_| "debug".to_string());
env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug"));
info!("Logger initialized at log level: {}", log_level);

HttpServer::new(move || {
let cors = actix_cors::Cors::default()
.allow_any_origin()
Expand Down
3 changes: 2 additions & 1 deletion fplus-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fplus-lib"
authors = ["jbesraa", "kokal33", "clriesco"]
version = "1.0.3"
version = "1.0.4"
edition = "2021"
description = "FPlus library/helper files"
license = "MIT OR Apache-2.0"
Expand All @@ -28,3 +28,4 @@ futures = "0.3.28"
tokio = { version = "1.32.0", features = ["rt", "macros"] }
uuidv4 = "1.0.0"
rayon = "1.8.0"
log = "0.4.20"
11 changes: 11 additions & 0 deletions fplus-lib/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use log::warn;

pub fn get_env_var_or_default(key: &str, default: &str) -> String {
match std::env::var(key) {
Ok(val) => val,
Err(_) => {
warn!("{} not set, using default value: {}", key, default);
default.to_string()
}
}
}
50 changes: 23 additions & 27 deletions fplus-lib/src/external_services/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use octocrab::{AuthState, Error as OctocrabError, Octocrab, OctocrabBuilder, Pag
use serde::{Deserialize, Serialize};
use std::sync::Arc;

use crate::config::get_env_var_or_default;

const GITHUB_API_URL: &str = "https://api.github.com";

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -70,35 +72,29 @@ pub struct GithubWrapper {

impl GithubWrapper {
pub fn new() -> Self {
dotenv::dotenv().ok();
let owner = std::env::var("GITHUB_OWNER").unwrap_or("filecoin-project".to_string());
let repo =
std::env::var("GITHUB_REPO").unwrap_or("filplus-tooling-backend-test".to_string());
let app_id = std::env::var("GITHUB_APP_ID")
.unwrap_or("373258".to_string())
let owner = get_env_var_or_default("GITHUB_OWNER", "filecoin-project");
let repo = get_env_var_or_default("GITHUB_REPO", "filplus-tooling-backend-test");
let app_id = get_env_var_or_default("GITHUB_APP_ID", "373258")
.parse::<u64>()
.unwrap_or(373258);
let installation_id = std::env::var("GITHUB_INSTALLATION_ID")
.unwrap_or("40514592".to_string())
.unwrap_or_else(|_| {
log::error!("Failed to parse GITHUB_APP_ID, using default");
373258
});
let installation_id = get_env_var_or_default("GITHUB_INSTALLATION_ID", "40514592")
.parse::<u64>()
.unwrap_or(40514592);
let gh_private_key = match std::env::var("GH_PRIVATE_KEY") {
Ok(g) => g,
Err(_) => {
println!("GH_PRIVATE_KEY not found in .env file, attempting to read from gh-private-key.pem");
match std::fs::read_to_string("gh-private-key.pem") {
Ok(file_content) => file_content,
Err(e) => {
println!("Failed to read gh-private-key.pem. Error: {:?}", e);
std::process::exit(1);
}
}
}
};
println!("owner: {}", &owner);
println!("repo: {}", &repo);
println!("app_id: {}", &app_id);
println!("installation_id: {}", &installation_id);
.unwrap_or_else(|_| {
log::error!("Failed to parse GITHUB_INSTALLATION_ID, using default");
40514592
});

let gh_private_key = std::env::var("GH_PRIVATE_KEY").unwrap_or_else(|_| {
log::warn!("GH_PRIVATE_KEY not found in .env file, attempting to read from gh-private-key.pem");
std::fs::read_to_string("gh-private-key.pem").unwrap_or_else(|e| {
log::error!("Failed to read gh-private-key.pem. Error: {:?}", e);
std::process::exit(1);
})
});

let connector = HttpsConnectorBuilder::new()
.with_native_roots() // enabled the `rustls-native-certs` feature in hyper-rustls
.https_only()
Expand Down
1 change: 1 addition & 0 deletions fplus-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod core;
pub mod error;
pub mod external_services;
pub mod parsers;
pub mod config;

0 comments on commit c859cfd

Please sign in to comment.