@@ -12,6 +12,7 @@ use opa_wasm::{
1212 wasmtime:: { Config , Engine , Module , OptLevel , Store } ,
1313 Runtime ,
1414} ;
15+ use serde:: Serialize ;
1516use thiserror:: Error ;
1617use tokio:: io:: { AsyncRead , AsyncReadExt } ;
1718
@@ -69,18 +70,42 @@ impl Entrypoints {
6970 }
7071}
7172
73+ #[ derive( Serialize , Debug ) ]
74+ pub struct Data {
75+ server_name : String ,
76+
77+ #[ serde( flatten) ]
78+ rest : Option < serde_json:: Value > ,
79+ }
80+
81+ impl Data {
82+ #[ must_use]
83+ pub fn new ( server_name : String ) -> Self {
84+ Self {
85+ server_name,
86+ rest : None ,
87+ }
88+ }
89+
90+ #[ must_use]
91+ pub fn with_rest ( mut self , rest : serde_json:: Value ) -> Self {
92+ self . rest = Some ( rest) ;
93+ self
94+ }
95+ }
96+
7297pub struct PolicyFactory {
7398 engine : Engine ,
7499 module : Module ,
75- data : serde_json :: Value ,
100+ data : Data ,
76101 entrypoints : Entrypoints ,
77102}
78103
79104impl PolicyFactory {
80105 #[ tracing:: instrument( name = "policy.load" , skip( source) , err) ]
81106 pub async fn load (
82107 mut source : impl AsyncRead + std:: marker:: Unpin ,
83- data : serde_json :: Value ,
108+ data : Data ,
84109 entrypoints : Entrypoints ,
85110 ) -> Result < Self , LoadError > {
86111 let mut config = Config :: default ( ) ;
@@ -364,10 +389,10 @@ mod tests {
364389
365390 #[ tokio:: test]
366391 async fn test_register ( ) {
367- let data = serde_json:: json!( {
392+ let data = Data :: new ( "example.com" . to_owned ( ) ) . with_rest ( serde_json:: json!( {
368393 "allowed_domains" : [ "element.io" , "*.element.io" ] ,
369394 "banned_domains" : [ "staging.element.io" ] ,
370- } ) ;
395+ } ) ) ;
371396
372397 #[ allow( clippy:: disallowed_types) ]
373398 let path = std:: path:: Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
0 commit comments