@@ -15,6 +15,8 @@ use serde::Deserialize;
15
15
use spin_common:: ui:: quoted_path;
16
16
use spin_sqlite:: Connection ;
17
17
18
+ use crate :: TriggerHooks ;
19
+
18
20
use self :: {
19
21
key_value:: { KeyValueStore , KeyValueStoreOpts } ,
20
22
llm:: LlmComputeOpts ,
@@ -259,6 +261,77 @@ fn resolve_config_path(path: &Path, config_opts: &RuntimeConfigOpts) -> Result<P
259
261
Ok ( base_path. join ( path) )
260
262
}
261
263
264
+ pub ( crate ) struct SummariseRuntimeConfigHook {
265
+ runtime_config_file : Option < PathBuf > ,
266
+ }
267
+
268
+ impl SummariseRuntimeConfigHook {
269
+ pub ( crate ) fn new ( runtime_config_file : & Option < PathBuf > ) -> Self {
270
+ Self {
271
+ runtime_config_file : runtime_config_file. clone ( ) ,
272
+ }
273
+ }
274
+ }
275
+
276
+ impl TriggerHooks for SummariseRuntimeConfigHook {
277
+ fn app_loaded (
278
+ & mut self ,
279
+ _app : & spin_app:: App ,
280
+ runtime_config : & RuntimeConfig ,
281
+ _resolver : & Arc < spin_expressions:: PreparedResolver > ,
282
+ ) -> anyhow:: Result < ( ) > {
283
+ if let Some ( path) = & self . runtime_config_file {
284
+ let mut opts = vec ! [ ] ;
285
+ for opt in runtime_config. opts_layers ( ) {
286
+ for ( id, opt) in & opt. key_value_stores {
287
+ opts. push ( Self :: summarise_kv ( id, opt) ) ;
288
+ }
289
+ for ( id, opt) in & opt. sqlite_databases {
290
+ opts. push ( Self :: summarise_sqlite ( id, opt) ) ;
291
+ }
292
+ for opt in & opt. llm_compute {
293
+ opts. push ( Self :: summarise_llm ( opt) ) ;
294
+ }
295
+ }
296
+ if !opts. is_empty ( ) {
297
+ let opts_text = opts. join ( ", " ) ;
298
+ println ! (
299
+ "Using {opts_text} runtime config from {}" ,
300
+ quoted_path( path)
301
+ ) ;
302
+ }
303
+ }
304
+ Ok ( ( ) )
305
+ }
306
+ }
307
+
308
+ impl SummariseRuntimeConfigHook {
309
+ fn summarise_kv ( id : & str , opt : & KeyValueStoreOpts ) -> String {
310
+ let source = match opt {
311
+ KeyValueStoreOpts :: Spin ( _) => "spin" ,
312
+ KeyValueStoreOpts :: Redis ( _) => "redis" ,
313
+ KeyValueStoreOpts :: AzureCosmos ( _) => "cosmos" ,
314
+ } ;
315
+ format ! ( "[key_value_store.{id}: {}]" , source)
316
+ }
317
+
318
+ fn summarise_sqlite ( id : & str , opt : & SqliteDatabaseOpts ) -> String {
319
+ let source = match opt {
320
+ SqliteDatabaseOpts :: Spin ( _) => "spin" ,
321
+ SqliteDatabaseOpts :: Libsql ( _) => "libsql" ,
322
+ } ;
323
+ format ! ( "[sqlite_database.{id}: {}]" , source)
324
+ }
325
+
326
+ fn summarise_llm ( opt : & LlmComputeOpts ) -> String {
327
+ let source = match opt {
328
+ LlmComputeOpts :: Spin => "spin" ,
329
+ LlmComputeOpts :: RemoteHttp ( _) => "remote-http" ,
330
+ } ;
331
+ format ! ( "[llm_compute: {}]" , source)
332
+ }
333
+ }
334
+
262
335
#[ cfg( test) ]
263
336
mod tests {
264
337
use std:: io:: Write ;
0 commit comments