Skip to content

Commit 467beeb

Browse files
committed
repo variables to .env
serialization for the allocatorModel
1 parent 3a119d2 commit 467beeb

File tree

4 files changed

+28
-54
lines changed

4 files changed

+28
-54
lines changed

fplus-http-server/src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ use actix_web::{App, HttpServer};
55
use env_logger;
66
use log::info;
77
use fplus_database;
8-
9-
use crate::router::allocator;
10-
118
pub(crate) mod router;
129

1310
#[tokio::main]
@@ -46,7 +43,6 @@ async fn main() -> std::io::Result<()> {
4643
.service(router::blockchain::verified_clients)
4744
.service(router::verifier::verifiers)
4845
.service(router::allocator::allocators)
49-
.service(router::allocator::create_or_update)
5046
.service(router::allocator::allocator)
5147
.service(router::allocator::delete)
5248
.service(router::allocator::create_from_json)

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

Lines changed: 9 additions & 42 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::process_allocator_file, Allocator, AllocatorUpdateInfo, ChangedAllocator};
3+
use fplus_lib::core::{allocator::process_allocator_file, AllocatorUpdateInfo, ChangedAllocator};
44

55
/**
66
* Get all allocators
@@ -31,24 +31,24 @@ pub async fn allocators() -> impl Responder {
3131
#[post("/allocator/create")]
3232
pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::Result<impl Responder> {
3333
let file_name = &file.file_changed;
34-
log::info!("File name: {}", file_name);
34+
log::info!("Starting allocator creation on: {}", file_name);
3535

3636
match process_allocator_file(file_name).await {
3737
Ok(model) => {
38-
if model.address.is_empty() {
38+
if model.multisig_address.is_empty() {
3939
return Ok(HttpResponse::BadRequest().body("Missing or invalid multisig_address"));
4040
}
41-
let verifiers_gh_handles = if model.application.github_handles.is_empty() {
41+
let verifiers_gh_handles = if model.application.verifiers_gh_handles.is_empty() {
4242
None
4343
} else {
44-
Some(model.application.github_handles.join(", ")) // Join verifiers in a string if exists
44+
Some(model.application.verifiers_gh_handles.join(", ")) // Join verifiers in a string if exists
4545
};
4646

4747
match database::create_or_update_allocator(
48-
model.organization,
49-
model.slug,
50-
Some(model.common_ui_install_id as i64),
51-
Some(model.address),
48+
model.owner,
49+
model.repo,
50+
Some(model.installation_id as i64),
51+
Some(model.multisig_address),
5252
verifiers_gh_handles,
5353
).await {
5454
Ok(allocator_model) => Ok(HttpResponse::Ok().json(allocator_model)),
@@ -60,39 +60,6 @@ pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::R
6060
}
6161

6262

63-
64-
65-
66-
67-
68-
/**
69-
* Create a new allocator
70-
*
71-
* # Arguments
72-
* @param info: web::Json<Allocator> - The allocator information
73-
*
74-
* # Returns
75-
* @return HttpResponse - The result of the operation
76-
*/
77-
#[post("/allocator")]
78-
pub async fn create_or_update(info: web::Json<Allocator>) -> impl Responder {
79-
match database::create_or_update_allocator(
80-
info.owner.clone(),
81-
info.repo.clone(),
82-
info.installation_id,
83-
info.multisig_address.clone(),
84-
info.verifiers_gh_handles.clone(),
85-
).await {
86-
Ok(allocator_model) => HttpResponse::Ok().json(allocator_model),
87-
Err(e) => {
88-
if e.to_string().contains("Allocator already exists") {
89-
return HttpResponse::BadRequest().body(e.to_string());
90-
}
91-
return HttpResponse::InternalServerError().body(e.to_string());
92-
}
93-
}
94-
}
95-
9663
/**
9764
* Update an allocator
9865
*

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ use serde::{Serialize, Deserialize};
22

33
#[derive(Serialize, Deserialize, Debug)]
44
pub struct AllocatorModel {
5-
pub slug: String,
6-
pub organization: String,
7-
pub address: String,
5+
#[serde(rename = "slug")]
6+
pub repo: String,
7+
#[serde(rename = "organization")]
8+
pub owner: String,
9+
#[serde(rename = "address")]
10+
pub multisig_address: String,
811
pub application: Application,
9-
pub common_ui_install_id: u64,
12+
#[serde(rename = "common_ui_install_id")]
13+
pub installation_id: u64,
1014
}
1115

1216
#[derive(Serialize, Deserialize, Debug)]
1317
pub struct Application {
14-
pub github_handles: Vec<String>
18+
#[serde(rename = "github_handles")]
19+
pub verifiers_gh_handles: Vec<String>
1520
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ use self::file::AllocatorModel;
77
pub mod file;
88

99
pub async fn process_allocator_file(file_name: &str) -> Result<AllocatorModel, LDNError> {
10-
let owner = "fidlabs";
11-
let repo = "Allocator-Governance-Staging";
10+
11+
let owner = std::env::var("ALLOCATOR_GOVERNANCE_OWNER").unwrap_or_else(|_| {
12+
log::warn!("ALLOCATOR_GOVERNANCE_OWNER not found in .env file");
13+
"Allocator-Governance-Staging".to_string()
14+
});
15+
let repo = std::env::var("ALLOCATOR_GOVERNANCE_REPO").unwrap_or_else(|_| {
16+
log::warn!("ALLOCATOR_GOVERNANCE_REPO not found in .env file");
17+
"fidlabs".to_string()
18+
});
1219
let branch = "main";
1320
let path = file_name.to_string();
1421

1522
let gh = GithubWrapper::new(owner.to_string(), repo.to_string());
16-
log::info!("Github is initialized");
1723
let content_items = gh.get_file(&path, branch).await.map_err(|e| LDNError::Load(e.to_string()))?;
1824
let model = content_items_to_allocator_model(content_items).map_err(|e| LDNError::Load(e.to_string()))?;
1925

0 commit comments

Comments
 (0)