-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from nodecross/update-network-json
Update network.json
- Loading branch information
Showing
6 changed files
with
162 additions
and
4 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
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,14 @@ | ||
import { post } from './sock.js' | ||
|
||
(async () => { | ||
const json = await post('/internal/network', { | ||
message: { | ||
"recipient_dids": ["123", "456"], | ||
"hub_endpoint": "https://hub.example.com", | ||
"heartbeat": 123, | ||
"trm": "true", | ||
} | ||
}) | ||
|
||
console.log(json) | ||
})() |
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,47 @@ | ||
use crate::network::Network; | ||
use actix_web::{web, HttpRequest, HttpResponse}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
// NOTE: POST /internal/version | ||
#[derive(Deserialize, Serialize)] | ||
pub struct MessageContainer { | ||
message: Value, | ||
} | ||
|
||
pub async fn handler( | ||
_req: HttpRequest, | ||
web::Json(json): web::Json<MessageContainer>, | ||
) -> actix_web::Result<HttpResponse> { | ||
let recipient_dids = match json.message["recipient_dids"].as_array() { | ||
Some(url) => url, | ||
None => return Ok(HttpResponse::BadRequest().json("recipient_dids is required")), | ||
}; | ||
let recipient_dids: Vec<String> = recipient_dids.iter().map(|v| v.to_string()).collect(); | ||
|
||
let hub_endpoint = match json.message["hub_endpoint"].as_str() { | ||
Some(p) => p, | ||
None => return Ok(HttpResponse::BadRequest().json("hub_endpoint is required")), | ||
}; | ||
let heartbeat: u64 = match json.message["heartbeat"].as_u64() { | ||
Some(h) => h, | ||
None => return Ok(HttpResponse::BadRequest().json("heartbeat is required")), | ||
}; | ||
let trm = match json.message["trm"].as_str() { | ||
Some(t) => t, | ||
None => return Ok(HttpResponse::BadRequest().json("trm is required")), | ||
}; | ||
let mut network_config = Network::new(); | ||
network_config.root.recipient_dids = Some(recipient_dids); | ||
network_config.root.hub_endpoint = Some(hub_endpoint.to_string()); | ||
network_config.root.heartbeat = Some(heartbeat); | ||
network_config.root.trm = Some(trm.to_string()); | ||
match network_config.save() { | ||
Ok(_) => {} | ||
Err(e) => { | ||
log::error!("{:?}", e); | ||
return Ok(HttpResponse::InternalServerError().json("Internal Server Error")); | ||
} | ||
}; | ||
Ok(HttpResponse::Ok().json("ok")) | ||
} |
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