@@ -17,18 +17,36 @@ mod outgoing_value;
17
17
18
18
pub ( crate ) use outgoing_value:: OutgoingValue ;
19
19
20
+ use crate :: DelegatingContainerManager ;
21
+
20
22
// TODO: I feel like the notions of "container" and "container manager" are muddled.
21
23
// This was kinda modelled on the KV StoreManager but I am not sure it has worked.
22
24
// A "container manager" actually manages only one container, making the `get` and
23
25
// `is_defined` functions seemingly redundant. More clarity and better definition
24
26
// is needed here, although the existing code does work!
25
-
27
+ //
28
+ // Part of the trouble is, I think, that the WIT has operations for "create container"
29
+ // etc. which implies a level above "container" but whose semantics are very poorly
30
+ // defined (the implication in the WIT is that a `blobstore` implementation backs
31
+ // onto exactly one provider, and if you need to deal with multiple providers then
32
+ // you need to do some double-import trickery, which does not seem right). Clarification
33
+ // sought via https://github.com/WebAssembly/wasi-blobstore/issues/27, so we may need
34
+ // to do some rework once the authors define it more fully.
35
+
36
+ /// Allows obtaining a container. The only interesting implementation is
37
+ /// [DelegatingContainerManager] (which is what [BlobStoreDispatch] uses);
38
+ /// other implementations currently manage only one container. (See comments.)
26
39
#[ async_trait]
27
40
pub trait ContainerManager : Sync + Send {
28
41
async fn get ( & self , name : & str ) -> Result < Arc < dyn Container > , Error > ;
29
42
fn is_defined ( & self , container_name : & str ) -> bool ;
30
43
}
31
44
45
+ /// A container. This represents the system or network resource defined by
46
+ /// a label mapping in the runtime config, e.g. a file system directory,
47
+ /// Azure blob storage account, or S3 bucket. This trait is implemented
48
+ /// by providers; it is the interface through which the [BlobStoreDispatch]
49
+ /// WASI host talks to the different implementations.
32
50
#[ async_trait]
33
51
pub trait Container : Sync + Send {
34
52
async fn exists ( & self ) -> anyhow:: Result < bool > ;
@@ -54,22 +72,27 @@ pub trait Container: Sync + Send {
54
72
async fn list_objects ( & self ) -> anyhow:: Result < Box < dyn ObjectNames > > ;
55
73
}
56
74
75
+ /// An interface implemented by providers when listing objects.
57
76
#[ async_trait]
58
77
pub trait ObjectNames : Send + Sync {
59
78
async fn read ( & mut self , len : u64 ) -> anyhow:: Result < ( Vec < String > , bool ) > ;
60
79
async fn skip ( & mut self , num : u64 ) -> anyhow:: Result < ( u64 , bool ) > ;
61
80
}
62
81
82
+ /// The content of a blob being read from a container. Called by the host to
83
+ /// handle WIT incoming-value methods, and implemented by providers.
84
+ /// providers
63
85
#[ async_trait]
64
86
pub trait IncomingData : Send + Sync {
65
87
async fn consume_sync ( & mut self ) -> anyhow:: Result < Vec < u8 > > ;
66
88
fn consume_async ( & mut self ) -> wasmtime_wasi:: pipe:: AsyncReadStream ;
67
89
async fn size ( & mut self ) -> anyhow:: Result < u64 > ;
68
90
}
69
91
92
+ /// Implements all the WIT host interfaces for wasi-blobstore.
70
93
pub struct BlobStoreDispatch < ' a > {
71
94
allowed_containers : & ' a HashSet < String > ,
72
- manager : & ' a dyn ContainerManager ,
95
+ manager : & ' a DelegatingContainerManager ,
73
96
wasi_resources : & ' a mut ResourceTable ,
74
97
containers : & ' a RwLock < Table < Arc < dyn Container > > > ,
75
98
incoming_values : & ' a RwLock < Table < Box < dyn IncomingData > > > ,
@@ -80,7 +103,7 @@ pub struct BlobStoreDispatch<'a> {
80
103
impl < ' a > BlobStoreDispatch < ' a > {
81
104
pub ( crate ) fn new (
82
105
allowed_containers : & ' a HashSet < String > ,
83
- manager : & ' a dyn ContainerManager ,
106
+ manager : & ' a DelegatingContainerManager ,
84
107
wasi_resources : & ' a mut ResourceTable ,
85
108
containers : & ' a RwLock < Table < Arc < dyn Container > > > ,
86
109
incoming_values : & ' a RwLock < Table < Box < dyn IncomingData > > > ,
@@ -131,7 +154,7 @@ impl bs::blobstore::Host for BlobStoreDispatch<'_> {
131
154
let rep = self . containers . write ( ) . await . push ( container) . unwrap ( ) ;
132
155
Ok ( Resource :: new_own ( rep) )
133
156
} else {
134
- Err ( "forbidden container" . to_owned ( ) )
157
+ Err ( format ! ( "Container {name:?} not defined or access denied" ) )
135
158
}
136
159
}
137
160
0 commit comments