-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.proto
345 lines (305 loc) · 9.75 KB
/
api.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
syntax = "proto3";
option go_package = "./modsurferpb";
import "google/protobuf/timestamp.proto";
// Used to type the arguments and return types from wasm elements such as import
// and export functions.
enum ValType {
I32 = 0;
I64 = 1;
F32 = 2;
F64 = 3;
V128 = 4;
FuncRef = 5;
ExternRef = 6;
}
// Contained by an import or export element within a wasm binary.
message Function {
repeated ValType params = 1;
repeated ValType results = 2;
string name = 3;
}
// A function and module namespace that is defined outside of the current
// module, and referenced & called by the current module.
message Import {
string module_name = 1;
Function func = 2;
}
// A function that is defined inside the current module, made available to
// outside modules / environments.
message Export { Function func = 1; }
// The language (or most similar match) used to produce a wasm module.
enum SourceLanguage {
Unknown = 0;
Rust = 1;
Go = 2;
C = 3;
Cpp = 4;
AssemblyScript = 5;
Swift = 6;
JavaScript = 7;
Haskell = 8;
Zig = 9;
}
// Details about a wasm module, either extracted directly from the binary, or
// inferred somehow.
message Module {
// ID for this module, generated by the database.
int64 id = 1;
// sha256 hash of the modules raw bytes
string hash = 3;
// function imports called by the module (see:
// <https://github.com/WebAssembly/design/blob/main/Modules.md#imports)>
repeated Import imports = 4;
// function exports provided by the module (see:
// <https://github.com/WebAssembly/design/blob/main/Modules.md#exports)>
repeated Export exports = 5;
// size in bytes of the module
uint64 size = 6;
// path or locator to the module
string location = 7;
// programming language used to produce this module
SourceLanguage source_language = 8;
// arbitrary metadata provided by the operator of this module
map<string, string> metadata = 9;
// timestamp when this module was loaded and stored
google.protobuf.Timestamp inserted_at = 10;
// the interned strings stored in the wasm binary (panic/abort messages, etc.)
repeated string strings = 11;
// the cyclomatic complexity
// (<https://en.wikipedia.org/wiki/Cyclomatic_complexity>) of the instructions
optional uint32 complexity = 13;
// the serialized graph in json format
optional bytes graph = 14;
// function hashes
map<string, string> function_hashes = 15;
}
// Details about a wasm module graph
message ModuleGraph {
// ID for this module, generated by the database.
int64 id = 1;
// the serialized graph in json format
bytes json_bytes = 2;
}
// An error message indicating a problem in the API.
message Error {
int32 code = 1;
string message = 2;
}
// Control/limit the way results are paginated when working with large
// responses.
message Pagination {
uint32 limit = 1;
uint32 offset = 2;
}
// Determine how to sort results from the API
message Sort {
Direction direction = 1;
Field field = 2;
}
// The direction, descending or ascending, of the sort operation.
enum Direction {
Desc = 0;
Asc = 1;
}
// The field within the Module schema that is used as the sorting dimension.
enum Field {
CreatedAt = 0;
Name = 1;
Size = 2;
Language = 3;
ImportsCount = 4;
ExportsCount = 5;
Sha256 = 6;
Complexity = 7;
}
// `PUT /api/v1/module:`
// Insert a module, extract data from binary. Return the module ID & hash.
message CreateModuleRequest {
bytes wasm = 1;
map<string, string> metadata = 2;
// a valid URL with a scheme prefix e.g. `s3://`, `file://`, `https://`
optional string location = 3;
}
// The message returned in response to a `CreateModuleRequest`.
message CreateModuleResponse {
int64 module_id = 1;
string hash = 2;
optional Error error = 3;
}
// `POST /api/v1/module:`
// Return a single module.
message GetModuleRequest { int64 module_id = 1; }
// The message returned in response to a `GetModuleRequest`.
message GetModuleResponse {
Module module = 1;
optional Error error = 2;
}
// `POST /api/v1/modules:`
// Return paginated list of all modules.
message ListModulesRequest {
Pagination pagination = 1;
Sort sort = 2;
}
// The message returned in response to a `ListModulesRequest`.
message ListModulesResponse {
repeated Module modules = 1;
Pagination pagination = 2;
// the full count of results in the database (not the count of this message's
// `modules`).
uint64 total = 3;
Sort sort = 4;
optional Error error = 5;
}
// `POST /api/v1/search:`
// Search for modules based on filter params provided (which should be any
// dimension of the module schema, or string search in any metadata value).
// Return a paginated list of matching modules.
message SearchModulesRequest {
// ID for this module, generated by the database.
optional int64 id = 1;
// original name of the binary module file
optional string hash = 3;
// function imports called by the module (see:
// <https://github.com/WebAssembly/design/blob/main/Modules.md#imports>)
repeated Import imports = 4;
// function exports provided by the module (see:
// <https://github.com/WebAssembly/design/blob/main/Modules.md#exports>)
repeated Export exports = 5;
// minimum size in bytes of the module
optional uint64 min_size = 6;
// maximum size in bytes of the module
optional uint64 max_size = 7;
// optional path or locator to the module (TODO: maybe this is better stored
// as metadata)
optional string location = 8;
// programming language used to produce this module
optional SourceLanguage source_language = 9;
// arbitrary metadata provided by the operator of this module
map<string, string> metadata = 10;
// timestamp when this module was loaded and stored
optional google.protobuf.Timestamp inserted_before = 11;
// timestamp when this module was loaded and stored
optional google.protobuf.Timestamp inserted_after = 12;
// the interned strings stored in the wasm binary (panic/abort messages, etc.)
repeated string strings = 13;
// match on any function name in an import or export.
optional string function_name = 14;
// match on the module name e.g. `env` or `wasi_snapshot_preview1`
optional string module_name = 15;
Pagination pagination = 16;
Sort sort = 17;
}
// The message returned in response to a `SearchModulesRequest`.
message SearchModulesResponse {
repeated Module modules = 1;
Pagination pagination = 2;
// the full count of results in the database (not the count of this message's
// `modules`).
uint64 total = 3;
Sort sort = 4;
optional Error error = 5;
}
// `DELETE /api/v1/module:`
// Remove a module from the database by its ID. Return the module IDs & hashes.
message DeleteModulesRequest { repeated int64 module_ids = 1; }
// The message returned in response to a `DeleteModulesRequest`.
message DeleteModulesResponse {
map<int64, string> module_id_hash = 1;
optional Error error = 2;
}
// Represents the expected outcome of an AuditModulesRequest. If PASS is provided, then
// the audit returns modules which conform to the checkfile. If FAIL is provided, then
// the audit returns modules which do not conform to the checkfile.
enum AuditOutcome {
PASS = 0;
FAIL = 1;
}
// `POST /api/v1/audit:`
// Return a list of modules which match the outcome requirements using the provided checkfile.
message AuditModulesRequest {
// the YAML checkfile (e.g. mod.yaml) bytes
bytes checkfile = 1;
AuditOutcome outcome = 2;
Pagination pagination = 3;
}
// The message returned in response to a `AuditModulesRequest`.
message AuditModulesResponse {
// each record contains the ID of the invalid Module which failed the audit, as well as the failure
// report produced by the validation check (encoded in JSON)
map<int64, bytes> invalid_module_report = 1;
Pagination pagination = 2;
// the full count of results in the database (not the count of this message's
// `modules`).
uint64 total = 3;
optional Error error = 4;
}
// `POST /api/v1/diff:`
// Return the diff of two modules
message DiffRequest {
int64 module1 = 1;
int64 module2 = 2;
bool color_terminal = 3;
bool with_context = 4;
}
// The message returned in response to `DiffRequest`, contains a text representation of the difference
// between the two specified modules.
message DiffResponse {
string diff = 1;
optional Error error = 2;
}
// `POST /api/v1/validate:`
// Return the failure report (if applicable) of a wasm module validation against a given checkfile.
message ValidateModuleRequest {
// the YAML checkfile (e.g. mod.yaml) bytes
bytes checkfile = 1;
// module_input is either an existing `module_id` that is known to the database, or the bytes of
// a raw wasm module. It is used to validate against the given checkfile.
oneof module_input {
bytes module = 2;
int64 module_id = 3;
}
}
// The failure report produced by the validation check (encoded in JSON).
message ValidateModuleResponse {
bytes invalid_module_report = 1;
optional Error error = 2;
}
// `POST /api/v1/module_graph:`
// Return a single module_graph.
message GetModuleGraphRequest { int64 module_id = 1; }
// The message returned in response to a `GetModuleGraphRequest`.
message GetModuleGraphResponse {
ModuleGraph module_graph = 1;
optional Error error = 2;
}
// PUT /api/v1/plugin:
message InstallPluginRequest {
string identifier = 1;
optional string name = 2;
string location = 3;
bytes wasm = 4;
// bytes config = 5;
}
message InstallPluginResponse {
string hash = 1;
optional Error error = 2;
}
// DELETE /api/v1/plugin:
message UninstallPluginRequest {
string identifier = 1;
}
message UninstallPluginResponse {
optional Error error = 1;
}
// POST /api/v1/plugin:
message CallPluginRequest {
string identifier = 1;
string function_name = 2;
bytes input = 3;
optional string hash = 4;
// bytes config = 5;
}
message CallPluginResponse {
bytes output = 1;
optional Error error = 2;
}