File tree Expand file tree Collapse file tree 4 files changed +23
-1
lines changed
agents/anda_assistant/src Expand file tree Collapse file tree 4 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ impl Agent<AgentCtx> for Assistant {
210210 "type" : "Person" ,
211211 "name" : caller. to_string( ) ,
212212 "attributes" : { } ,
213+ "metadata" : { } ,
213214 } )
214215 } ) ;
215216
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ name = "anda_engine_server"
33description = " A http server to serve multiple Anda engines."
44repository = " https://github.com/ldclabs/anda/tree/main/anda_engine_server"
55publish = true
6- version.workspace = true
6+ version = " 0.9.3 "
77edition.workspace = true
88keywords.workspace = true
99categories.workspace = true
Original file line number Diff line number Diff line change @@ -26,6 +26,20 @@ pub struct AppState {
2626 pub ( crate ) engines : Arc < BTreeMap < Principal , Engine > > ,
2727 pub ( crate ) default_engine : Principal ,
2828 pub ( crate ) start_time_ms : u64 ,
29+ pub ( crate ) api_key : Option < String > ,
30+ }
31+
32+ impl AppState {
33+ pub fn check_api_key ( & self , headers : & http:: HeaderMap ) -> Result < ( ) , String > {
34+ if let Some ( expected_key) = & self . api_key {
35+ match headers. get ( "x-api-key" ) {
36+ Some ( provided_key) if provided_key == expected_key => Ok ( ( ) ) ,
37+ _ => Err ( "missing or invalid x-api-key in headers" . to_string ( ) ) ,
38+ }
39+ } else {
40+ Ok ( ( ) )
41+ }
42+ }
2943}
3044
3145/// GET /.well-known/information
@@ -98,6 +112,10 @@ pub async fn anda_engine(
98112 Path ( id) : Path < String > ,
99113 ct : ContentWithSHA3 < RPCRequest > ,
100114) -> impl IntoResponse {
115+ if let Err ( err) = app. check_api_key ( & headers) {
116+ return ( StatusCode :: UNAUTHORIZED , err) . into_response ( ) ;
117+ }
118+
101119 let id = if & id == "default" {
102120 app. default_engine
103121 } else if let Ok ( id) = Principal :: from_text ( & id) {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ pub struct ServerBuilder {
2222 origin : String ,
2323 engines : BTreeMap < Principal , Engine > ,
2424 default_engine : Option < Principal > ,
25+ api_key : Option < String > ,
2526}
2627
2728impl Default for ServerBuilder {
@@ -42,6 +43,7 @@ impl ServerBuilder {
4243 origin : "https://localhost:8443" . to_string ( ) ,
4344 engines : BTreeMap :: new ( ) ,
4445 default_engine : None ,
46+ api_key : None ,
4547 }
4648 }
4749
@@ -98,6 +100,7 @@ impl ServerBuilder {
98100 engines : Arc :: new ( self . engines ) ,
99101 default_engine,
100102 start_time_ms : unix_ms ( ) ,
103+ api_key : self . api_key ,
101104 } ;
102105 let app = Router :: new ( )
103106 . route ( "/" , routing:: get ( get_information) )
You can’t perform that action at this time.
0 commit comments