Skip to content

Commit bcf5dee

Browse files
committed
create allocator from json functionality
1 parent e41e5bb commit bcf5dee

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

fplus-http-server/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use env_logger;
66
use log::info;
77
use fplus_database;
88

9+
use crate::router::allocator;
10+
911
pub(crate) mod router;
1012

1113
#[tokio::main]
@@ -47,6 +49,7 @@ async fn main() -> std::io::Result<()> {
4749
.service(router::allocator::create_or_update)
4850
.service(router::allocator::allocator)
4951
.service(router::allocator::delete)
52+
.service(router::allocator::create_from_json)
5053
})
5154
.bind(("0.0.0.0", 8080))?
5255
.run()

fplus-http-server/src/router/allocator.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use actix_web::{get, post, put, delete, web, HttpResponse, Responder};
22
use fplus_database::database;
3-
use fplus_lib::core::{allocator::{extract_owner_repo, process_allocator_file}, Allocator, AllocatorUpdateInfo, ChangedAllocator};
3+
use fplus_lib::core::{allocator::process_allocator_file, Allocator, AllocatorUpdateInfo, ChangedAllocator};
44

55
/**
66
* Get all allocators
@@ -29,18 +29,10 @@ pub async fn allocators() -> impl Responder {
2929
* @return HttpResponse - The result of the operation
3030
*/
3131
#[post("/allocator/create")]
32-
pub async fn notify_changed_json(file: web::Json<ChangedAllocator>) -> actix_web::Result<impl Responder> {
32+
pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::Result<impl Responder> {
3333
let file_name = &file.file_changed;
34-
35-
let (extracted_owner, extracted_repo) = match extract_owner_repo(file_name) {
36-
Ok((owner, repo)) => (owner, repo.trim_end_matches(".json")),
37-
Err(_) => return Ok(HttpResponse::BadRequest().body(format!("Invalid file name format: {}", file_name))),
38-
};
3934

40-
let branch = "main";
41-
let path = format!("active/{}/{}.json", extracted_owner, extracted_repo);
42-
43-
match process_allocator_file(extracted_owner, extracted_repo, branch, &path).await {
35+
match process_allocator_file(file_name).await {
4436
Ok(model) => {
4537
if model.multisig_address.is_empty() {
4638
return Ok(HttpResponse::BadRequest().body("Missing or invalid multisig_address"));
@@ -50,10 +42,10 @@ pub async fn notify_changed_json(file: web::Json<ChangedAllocator>) -> actix_web
5042
} else {
5143
Some(model.verifiers.join(", ")) // Join verifiers in a string if exists
5244
};
53-
45+
5446
match database::create_or_update_allocator(
55-
extracted_owner.to_string(),
56-
extracted_repo.to_string(),
47+
model.organization,
48+
model.slug,
5749
Some(model.installation_id as i64),
5850
Some(model.multisig_address),
5951
verifiers_gh_handles,

fplus-lib/src/core/allocator/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ use self::file::AllocatorModel;
66

77
pub mod file;
88

9-
pub async fn process_allocator_file(owner: &str, repo: &str, branch: &str, path: &str) -> Result<AllocatorModel, LDNError> {
9+
pub async fn process_allocator_file(file_name: &str) -> Result<AllocatorModel, LDNError> {
10+
let owner = "fidlabs";
11+
let repo = "Allocator-Governance-Staging";
12+
let branch = "main";
13+
let path = file_name.to_string();
14+
1015
let gh = GithubWrapper::new(owner.to_string(), repo.to_string());
1116

12-
let content_items = gh.get_file(path, branch).await.map_err(|e| LDNError::Load(e.to_string()))?;
17+
let content_items = gh.get_file(&path, branch).await.map_err(|e| LDNError::Load(e.to_string()))?;
1318
let model = content_items_to_allocator_model(content_items).map_err(|e| LDNError::Load(e.to_string()))?;
1419

1520
Ok(model)
@@ -26,12 +31,4 @@ fn content_items_to_allocator_model(file: ContentItems) -> Result<AllocatorModel
2631
.ok_or(LDNError::Load("Failed to parse allocator model".to_string()))?;
2732

2833
Ok(allocator_model)
29-
}
30-
31-
pub fn extract_owner_repo(file_name: &str) -> Result<(&str, &str), &'static str> {
32-
let parts: Vec<&str> = file_name.splitn(2, '_').collect();
33-
if parts.len() != 2 {
34-
return Err("Invalid file name format");
35-
}
36-
Ok((parts[0], parts[1]))
3734
}

fplus-lib/src/core/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub struct Allocator {
103103
}
104104
#[derive(Deserialize)]
105105
pub struct ChangedAllocator {
106-
pub file_changed: String,
106+
pub file_changed: String
107107
}
108108

109109
#[derive(Deserialize)]

fplus-lib/src/external_services/github.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ struct Author {
8888

8989
impl GithubWrapper {
9090
pub fn new(owner: String, repo: String) -> Self {
91-
let app_id = get_env_var_or_default("GITHUB_APP_ID", "826129")
91+
let app_id = get_env_var_or_default("GITHUB_APP_ID", "373258")
9292
.parse::<u64>()
9393
.unwrap_or_else(|_| {
9494
log::error!("Failed to parse GITHUB_APP_ID, using default");
9595
826129
9696
});
97-
let installation_id = get_env_var_or_default("GITHUB_INSTALLATION_ID", "47207972")
97+
let installation_id = get_env_var_or_default("GITHUB_INSTALLATION_ID", "40514592")
9898
.parse::<u64>()
9999
.unwrap_or_else(|_| {
100100
log::error!("Failed to parse GITHUB_INSTALLATION_ID, using default");

0 commit comments

Comments
 (0)