Skip to content

Commit 7b81ad0

Browse files
committed
refactor: Namespace VFS structs with Node
1 parent 4a3d8e5 commit 7b81ad0

File tree

6 files changed

+102
-84
lines changed

6 files changed

+102
-84
lines changed

common/src/api/def.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//! Each endpoint should be documented with:
1212
//! - 1) HTTP method e.g. `GET`
1313
//! - 2) Endpoint e.g. `/v1/file`
14-
//! - 3) Data used to make the request e.g. `FileId`
15-
//! - 4) The return type e.g. `Option<File>`
14+
//! - 3) Data used to make the request e.g. `NodeFileId`
15+
//! - 4) The return type e.g. `Option<NodeFile>`
1616
//!
1717
//! The methods below should resemble the data actually sent across the wire.
1818
@@ -27,7 +27,7 @@ use crate::api::provision::{
2727
SealedSeedId,
2828
};
2929
use crate::api::runner::UserPorts;
30-
use crate::api::vfs::{Directory, File, FileId};
30+
use crate::api::vfs::{NodeDirectory, NodeFile, NodeFileId};
3131
use crate::api::UserPk;
3232
use crate::enclave::Measurement;
3333

@@ -63,31 +63,37 @@ pub trait NodeBackendApi {
6363
data: NodeInstanceSeed,
6464
) -> Result<NodeInstanceSeed, BackendApiError>;
6565

66-
/// GET /v1/file [`File`] -> [`Option<File>`]
66+
/// GET /v1/file [`NodeFileId`] -> [`Option<NodeFile>`]
6767
async fn get_file(
6868
&self,
69-
file_id: &FileId,
70-
) -> Result<Option<File>, BackendApiError>;
69+
file_id: &NodeFileId,
70+
) -> Result<Option<NodeFile>, BackendApiError>;
7171

72-
/// POST /v1/file [`File`] -> [`File`]
73-
async fn create_file(&self, file: &File) -> Result<File, BackendApiError>;
72+
/// POST /v1/file [`NodeFile`] -> [`NodeFile`]
73+
async fn create_file(
74+
&self,
75+
file: &NodeFile,
76+
) -> Result<NodeFile, BackendApiError>;
7477

75-
/// PUT /v1/file [`File`] -> [`File`]
76-
async fn upsert_file(&self, file: &File) -> Result<File, BackendApiError>;
78+
/// PUT /v1/file [`NodeFile`] -> [`NodeFile`]
79+
async fn upsert_file(
80+
&self,
81+
file: &NodeFile,
82+
) -> Result<NodeFile, BackendApiError>;
7783

78-
/// DELETE /v1/file [`FileId`] -> "OK"
84+
/// DELETE /v1/file [`NodeFileId`] -> "OK"
7985
///
8086
/// Returns "OK" only if exactly one row was deleted.
8187
async fn delete_file(
8288
&self,
83-
file_id: &FileId,
89+
file_id: &NodeFileId,
8490
) -> Result<String, BackendApiError>;
8591

86-
/// GET /v1/directory [`Directory`] -> [`Vec<File>`]
92+
/// GET /v1/directory [`NodeDirectory`] -> [`Vec<NodeFile>`]
8793
async fn get_directory(
8894
&self,
89-
dir: &Directory,
90-
) -> Result<Vec<File>, BackendApiError>;
95+
dir: &NodeDirectory,
96+
) -> Result<Vec<NodeFile>, BackendApiError>;
9197
}
9298

9399
/// Defines the api that the runner exposes to the node.

common/src/api/vfs.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,38 @@ use crate::enclave::Measurement;
55

66
/// Uniquely identifies a directory in the node's virtual file system.
77
#[derive(Clone, Hash, Eq, PartialEq, Deserialize, Serialize)]
8-
pub struct Directory {
8+
pub struct NodeDirectory {
99
pub node_pk: PublicKey,
1010
pub measurement: Measurement,
1111
pub dirname: String,
1212
}
1313

1414
/// Uniquely identifies a file in the node's virtual file system.
1515
#[derive(Clone, Deserialize, Serialize)]
16-
pub struct FileId {
16+
pub struct NodeFileId {
1717
// Flattened because serde_qs doesn't play well with nested structs
1818
#[serde(flatten)]
19-
pub dir: Directory,
19+
pub dir: NodeDirectory,
2020
pub filename: String,
2121
}
2222

2323
#[derive(Clone, Serialize, Deserialize)]
24-
pub struct File {
24+
pub struct NodeFile {
2525
// Flattened because serde_qs doesn't play well with nested structs
2626
#[serde(flatten)]
27-
pub id: FileId,
27+
pub id: NodeFileId,
2828
pub data: Vec<u8>,
2929
}
3030

31-
impl FileId {
31+
impl NodeFileId {
3232
pub fn new(
3333
node_pk: PublicKey,
3434
measurement: Measurement,
3535
dirname: String,
3636
filename: String,
3737
) -> Self {
3838
Self {
39-
dir: Directory {
39+
dir: NodeDirectory {
4040
node_pk,
4141
measurement,
4242
dirname,
@@ -46,7 +46,7 @@ impl FileId {
4646
}
4747
}
4848

49-
impl File {
49+
impl NodeFile {
5050
pub fn new(
5151
node_pk: PublicKey,
5252
measurement: Measurement,
@@ -55,8 +55,8 @@ impl File {
5555
data: Vec<u8>,
5656
) -> Self {
5757
Self {
58-
id: FileId {
59-
dir: Directory {
58+
id: NodeFileId {
59+
dir: NodeDirectory {
6060
node_pk,
6161
measurement,
6262
dirname,

node/src/api/client.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use common::api::provision::{
1111
use common::api::qs::{GetByUserPk, GetByUserPkAndMeasurement};
1212
use common::api::rest::{RestClient, DELETE, GET, POST, PUT};
1313
use common::api::runner::UserPorts;
14-
use common::api::vfs::{Directory, File, FileId};
14+
use common::api::vfs::{NodeDirectory, NodeFile, NodeFileId};
1515
use common::api::UserPk;
1616
use common::enclave::Measurement;
1717

@@ -60,9 +60,9 @@ impl LexeApiClient {
6060
impl ApiClient for LexeApiClient {
6161
async fn create_file_with_retries(
6262
&self,
63-
data: &File,
63+
data: &NodeFile,
6464
retries: usize,
65-
) -> Result<File, BackendApiError> {
65+
) -> Result<NodeFile, BackendApiError> {
6666
let url = self.build_url(Backend, V1, "/file");
6767
self.rest
6868
.request_with_retries(POST, url, &data, retries, None)
@@ -71,9 +71,9 @@ impl ApiClient for LexeApiClient {
7171

7272
async fn upsert_file_with_retries(
7373
&self,
74-
data: &File,
74+
data: &NodeFile,
7575
retries: usize,
76-
) -> Result<File, BackendApiError> {
76+
) -> Result<NodeFile, BackendApiError> {
7777
let url = self.build_url(Backend, V1, "/file");
7878
self.rest
7979
.request_with_retries(PUT, url, &data, retries, None)
@@ -124,18 +124,24 @@ impl NodeBackendApi for LexeApiClient {
124124

125125
async fn get_file(
126126
&self,
127-
data: &FileId,
128-
) -> Result<Option<File>, BackendApiError> {
127+
data: &NodeFileId,
128+
) -> Result<Option<NodeFile>, BackendApiError> {
129129
let url = self.build_url(Backend, V1, "/file");
130130
self.rest.request(GET, url, &data).await
131131
}
132132

133-
async fn create_file(&self, data: &File) -> Result<File, BackendApiError> {
133+
async fn create_file(
134+
&self,
135+
data: &NodeFile,
136+
) -> Result<NodeFile, BackendApiError> {
134137
let url = self.build_url(Backend, V1, "/file");
135138
self.rest.request(POST, url, &data).await
136139
}
137140

138-
async fn upsert_file(&self, data: &File) -> Result<File, BackendApiError> {
141+
async fn upsert_file(
142+
&self,
143+
data: &NodeFile,
144+
) -> Result<NodeFile, BackendApiError> {
139145
let url = self.build_url(Backend, V1, "/file");
140146
self.rest.request(PUT, url, &data).await
141147
}
@@ -145,16 +151,16 @@ impl NodeBackendApi for LexeApiClient {
145151
#[allow(dead_code)]
146152
async fn delete_file(
147153
&self,
148-
data: &FileId,
154+
data: &NodeFileId,
149155
) -> Result<String, BackendApiError> {
150156
let url = self.build_url(Backend, V1, "/file");
151157
self.rest.request(DELETE, url, &data).await
152158
}
153159

154160
async fn get_directory(
155161
&self,
156-
data: &Directory,
157-
) -> Result<Vec<File>, BackendApiError> {
162+
data: &NodeDirectory,
163+
) -> Result<Vec<NodeFile>, BackendApiError> {
158164
let url = self.build_url(Backend, V1, "/directory");
159165
self.rest.request(GET, url, &data).await
160166
}

0 commit comments

Comments
 (0)