[ENG-698] Stop leaking pk (#934)

stop leaking pk

Co-authored-by: Brendan Allan <brendonovich@outlook.com>
This commit is contained in:
Oscar Beaumont 2023-06-12 20:03:12 +02:00 committed by GitHub
parent 7148209343
commit 923a0ceee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 3 deletions

View file

@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use specta::Type;
use std::sync::Arc;
use crate::{node::NodeConfig, Node};
use crate::{node::SanitisedNodeConfig, Node};
use utils::{InvalidRequests, InvalidateOperationEvent};
@ -37,7 +37,7 @@ pub mod volumes;
#[derive(Serialize, Deserialize, Debug, Type)]
struct NodeState {
#[serde(flatten)]
config: NodeConfig,
config: SanitisedNodeConfig,
data_path: String,
}
@ -59,7 +59,7 @@ pub(crate) fn mount() -> Arc<Router> {
.procedure("nodeState", {
R.query(|ctx, _: ()| async move {
Ok(NodeState {
config: ctx.config.get().await,
config: ctx.config.get().await.into(),
// We are taking the assumption here that this value is only used on the frontend for display purposes
data_path: ctx
.config

View file

@ -31,6 +31,32 @@ pub struct NodeConfig {
pub p2p_img_url: Option<String>,
}
// A version of [NodeConfig] that is safe to share with the frontend
#[derive(Debug, Serialize, Deserialize, Clone, Type)]
pub struct SanitisedNodeConfig {
/// id is a unique identifier for the current node. Each node has a public identifier (this one) and is given a local id for each library (done within the library code).
pub id: Uuid,
/// name is the display name of the current node. This is set by the user and is shown in the UI. // TODO: Length validation so it can fit in DNS record
pub name: String,
// the port this node uses for peer to peer communication. By default a random free port will be chosen each time the application is started.
pub p2p_port: Option<u32>,
// TODO: These will probs be replaced by your Spacedrive account in the near future.
pub p2p_email: Option<String>,
pub p2p_img_url: Option<String>,
}
impl From<NodeConfig> for SanitisedNodeConfig {
fn from(value: NodeConfig) -> Self {
Self {
id: value.id,
name: value.name,
p2p_port: value.p2p_port,
p2p_email: value.p2p_email,
p2p_img_url: value.p2p_img_url,
}
}
}
#[async_trait::async_trait]
impl Migrate for NodeConfig {
const CURRENT_VERSION: u32 = 0;

View file

@ -228,6 +228,8 @@ export type RenameFileArgs = { location_id: number; file_name: string; new_file_
export type RuleKind = "AcceptFilesByGlob" | "RejectFilesByGlob" | "AcceptIfChildrenDirectoriesArePresent" | "RejectIfChildrenDirectoriesArePresent"
export type SanitisedNodeConfig = { id: string; name: string; p2p_port: number | null; p2p_email: string | null; p2p_img_url: string | null }
export type SearchData<T> = { cursor: number[] | null; items: T[] }
export type SetFavoriteArgs = { id: number; favorite: boolean }