@@ -12,6 +12,7 @@ use axum::{
1212 Json , Router ,
1313} ;
1414use bytes:: Bytes ;
15+ use clap:: Parser ;
1516use serde:: { Deserialize , Serialize } ;
1617use task_maker_dag:: { ExecutionDAG , ExecutionStatus , File } ;
1718use task_maker_lang:: { LanguageManager , SourceFile } ;
@@ -20,15 +21,47 @@ use tokio::net::TcpListener;
2021use tower_http:: trace:: TraceLayer ;
2122
2223use crate :: sandbox:: ToolsSandboxRunner ;
23- use crate :: tools:: opt:: EvalServerOpt ;
2424
25- #[ derive( Debug , Serialize , Deserialize , Clone ) ]
26- struct TokenList {
27- tokens : Vec < String > ,
25+ #[ derive( Parser , Debug , Clone ) ]
26+ pub struct EvalServerOpt {
27+ /// Address to bind the server on
28+ #[ clap( long, default_value = "127.0.0.1:3000" ) ]
29+ pub addr : String ,
30+
31+ /// Require authentication for the API endpoints.
32+ /// If true, the server will expect an "X-OII-AUTH" header with a token for each request.
33+ ///
34+ /// The token is meaningless and is only used to prevent unauthorized access. You can set it to
35+ /// any value you want.
36+ #[ clap( long) ]
37+ pub require_header : bool ,
38+
39+ /// List of allowed languages (names). If empty, all languages are allowed.
40+ #[ clap( long) ]
41+ pub allowed_languages : Vec < String > ,
42+
43+ /// Maximum CPU time limit (seconds)
44+ #[ clap( long, default_value = "10.0" ) ]
45+ pub max_time_limit : f64 ,
46+
47+ /// Maximum memory limit (MB)
48+ #[ clap( long, default_value = "512" ) ]
49+ pub max_memory_limit : u64 ,
50+
51+ /// Compilation CPU time limit (seconds)
52+ #[ clap( long, default_value = "60.0" ) ]
53+ pub compilation_time_limit : f64 ,
54+
55+ /// Compilation memory limit (MB)
56+ #[ clap( long, default_value = "1024" ) ]
57+ pub compilation_memory_limit : u64 ,
58+
59+ #[ clap( flatten, next_help_heading = Some ( "STORAGE" ) ) ]
60+ pub storage : crate :: StorageOpt ,
2861}
2962
3063struct AppState {
31- tokens : Option < HashSet < String > > ,
64+ require_header : bool ,
3265 allowed_languages : HashSet < String > ,
3366 opt : EvalServerOpt ,
3467}
@@ -106,18 +139,9 @@ struct LanguageInfo {
106139
107140#[ tokio:: main]
108141pub async fn main_eval_server ( opt : EvalServerOpt ) -> Result < ( ) , Error > {
109- let tokens = if let Some ( path) = & opt. tokens_file {
110- let content = std:: fs:: read_to_string ( path) . context ( "Failed to read tokens file" ) ?;
111- let list: TokenList =
112- serde_json:: from_str ( & content) . context ( "Failed to parse tokens file" ) ?;
113- Some ( list. tokens . into_iter ( ) . collect :: < HashSet < _ > > ( ) )
114- } else {
115- None
116- } ;
117-
118142 let allowed_languages = opt. allowed_languages . iter ( ) . cloned ( ) . collect ( ) ;
119143 let state = Arc :: new ( AppState {
120- tokens ,
144+ require_header : opt . require_header ,
121145 allowed_languages,
122146 opt,
123147 } ) ;
@@ -145,15 +169,14 @@ async fn auth_middleware(
145169 mut req : Request ,
146170 next : Next ,
147171) -> Result < Response , StatusCode > {
148- if let Some ( tokens ) = & state. tokens {
172+ if state. require_header {
149173 let auth_header = req
150174 . headers ( )
151- . get ( "Authorization" )
152- . and_then ( |h| h. to_str ( ) . ok ( ) )
153- . and_then ( |s| s. strip_prefix ( "Bearer " ) ) ;
175+ . get ( "X-OII-AUTH" )
176+ . and_then ( |h| h. to_str ( ) . ok ( ) ) ;
154177
155178 match auth_header {
156- Some ( token) if tokens . contains ( token ) => {
179+ Some ( token) => {
157180 // Token is valid, continue to the next handler
158181 let token_str = token. to_string ( ) ;
159182 req. extensions_mut ( ) . insert ( token_str) ;
0 commit comments