Skip to content

Commit 4eab3ba

Browse files
committed
factors: Fix toml key tracking
Signed-off-by: Lann Martin <[email protected]>
1 parent c58a6b8 commit 4eab3ba

File tree

6 files changed

+15
-21
lines changed
  • crates
    • factor-key-value/src/runtime_config
    • factor-llm/src
    • factor-outbound-networking/src/runtime_config
    • factor-sqlite/src/runtime_config
    • factor-variables/src/spin_cli
    • runtime-config/src

6 files changed

+15
-21
lines changed

crates/factor-key-value/src/runtime_config/spin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{DefaultLabelResolver, RuntimeConfig};
44
use anyhow::Context as _;
55
use serde::de::DeserializeOwned;
66
use serde::{Deserialize, Serialize};
7+
use spin_factors::runtime_config::toml::GetTomlValue;
78
use spin_key_value::StoreManager;
89
use std::{collections::HashMap, sync::Arc};
910

@@ -100,7 +101,7 @@ impl RuntimeConfigResolver {
100101
/// Resolves a toml table into a runtime config.
101102
pub fn resolve_from_toml(
102103
&self,
103-
table: Option<&toml::Table>,
104+
table: Option<&impl GetTomlValue>,
104105
) -> anyhow::Result<Option<RuntimeConfig>> {
105106
let Some(table) = table.and_then(|t| t.get("key_value_store")) else {
106107
return Ok(None);

crates/factor-llm/src/spin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::PathBuf;
22
use std::sync::Arc;
33

4+
use spin_factors::runtime_config::toml::GetTomlValue;
45
use spin_llm_remote_http::RemoteHttpLlmEngine;
56
use spin_world::async_trait;
67
use spin_world::v1::llm::{self as v1};
@@ -80,7 +81,7 @@ impl LlmEngine for RemoteHttpLlmEngine {
8081
}
8182

8283
pub fn runtime_config_from_toml(
83-
table: &toml::Table,
84+
table: &impl GetTomlValue,
8485
state_dir: Option<PathBuf>,
8586
use_gpu: bool,
8687
) -> anyhow::Result<Option<RuntimeConfig>> {

crates/factor-outbound-networking/src/runtime_config/spin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl SpinTlsRuntimeConfig {
3737
/// client_cert_file = "path/to/client.crt"
3838
/// client_private_key_file = "path/to/client.key"
3939
/// ```
40-
pub fn config_from_table<T: GetTomlValue>(
40+
pub fn config_from_table(
4141
&self,
42-
table: &T,
42+
table: &impl GetTomlValue,
4343
) -> anyhow::Result<Option<super::RuntimeConfig>> {
4444
let Some(tls_configs) = self.tls_configs_from_table(table)? else {
4545
return Ok(None);

crates/factor-sqlite/src/runtime_config/spin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ impl RuntimeConfigResolver {
4949
/// type = "$database-type"
5050
/// ... extra type specific configuration ...
5151
/// ```
52-
pub fn resolve_from_toml<T: GetTomlValue>(
52+
pub fn resolve_from_toml(
5353
&self,
54-
table: &T,
54+
table: &impl GetTomlValue,
5555
) -> anyhow::Result<Option<super::RuntimeConfig>> {
5656
let Some(table) = table.get("sqlite_database") else {
5757
return Ok(None);

crates/factor-variables/src/spin_cli/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ pub use vault::*;
1212

1313
use serde::Deserialize;
1414
use spin_expressions::Provider;
15-
use spin_factors::anyhow;
15+
use spin_factors::{anyhow, runtime_config::toml::GetTomlValue};
1616

1717
use crate::runtime_config::RuntimeConfig;
1818

1919
/// Resolves a runtime configuration for the variables factor from a TOML table.
20-
pub fn runtime_config_from_toml(table: &toml::Table) -> anyhow::Result<RuntimeConfig> {
20+
pub fn runtime_config_from_toml(table: &impl GetTomlValue) -> anyhow::Result<RuntimeConfig> {
2121
// Always include the environment variable provider.
2222
let mut providers = vec![Box::<EnvVariablesProvider>::default() as _];
2323
let Some(array) = table.get("variable_provider") else {

crates/runtime-config/src/lib.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ impl<'a> TomlResolver<'a> {
189189
}
190190
}
191191

192-
impl AsRef<toml::Table> for TomlResolver<'_> {
193-
fn as_ref(&self) -> &toml::Table {
194-
self.table.as_ref()
195-
}
196-
}
197-
198192
/// The TOML based runtime configuration source Spin CLI.
199193
pub struct TomlRuntimeConfigSource<'a, 'b> {
200194
toml: TomlResolver<'b>,
@@ -226,7 +220,7 @@ impl FactorRuntimeConfigSource<KeyValueFactor> for TomlRuntimeConfigSource<'_, '
226220
fn get_runtime_config(
227221
&mut self,
228222
) -> anyhow::Result<Option<spin_factor_key_value::RuntimeConfig>> {
229-
self.key_value.resolve_from_toml(Some(self.toml.as_ref()))
223+
self.key_value.resolve_from_toml(Some(&self.toml.table))
230224
}
231225
}
232226

@@ -238,17 +232,15 @@ impl FactorRuntimeConfigSource<OutboundNetworkingFactor> for TomlRuntimeConfigSo
238232
let Some(tls) = self.tls else {
239233
return Ok(None);
240234
};
241-
tls.config_from_table(self.toml.as_ref())
235+
tls.config_from_table(&self.toml.table)
242236
}
243237
}
244238

245239
impl FactorRuntimeConfigSource<VariablesFactor> for TomlRuntimeConfigSource<'_, '_> {
246240
fn get_runtime_config(
247241
&mut self,
248242
) -> anyhow::Result<Option<<VariablesFactor as spin_factors::Factor>::RuntimeConfig>> {
249-
Ok(Some(variables::runtime_config_from_toml(
250-
self.toml.as_ref(),
251-
)?))
243+
Ok(Some(variables::runtime_config_from_toml(&self.toml.table)?))
252244
}
253245
}
254246

@@ -266,7 +258,7 @@ impl FactorRuntimeConfigSource<OutboundMysqlFactor> for TomlRuntimeConfigSource<
266258

267259
impl FactorRuntimeConfigSource<LlmFactor> for TomlRuntimeConfigSource<'_, '_> {
268260
fn get_runtime_config(&mut self) -> anyhow::Result<Option<spin_factor_llm::RuntimeConfig>> {
269-
llm::runtime_config_from_toml(self.toml.as_ref(), self.toml.state_dir()?, self.use_gpu)
261+
llm::runtime_config_from_toml(&self.toml.table, self.toml.state_dir()?, self.use_gpu)
270262
}
271263
}
272264

@@ -296,7 +288,7 @@ impl FactorRuntimeConfigSource<OutboundMqttFactor> for TomlRuntimeConfigSource<'
296288

297289
impl FactorRuntimeConfigSource<SqliteFactor> for TomlRuntimeConfigSource<'_, '_> {
298290
fn get_runtime_config(&mut self) -> anyhow::Result<Option<spin_factor_sqlite::RuntimeConfig>> {
299-
self.sqlite.resolve_from_toml(self.toml.as_ref())
291+
self.sqlite.resolve_from_toml(&self.toml.table)
300292
}
301293
}
302294

0 commit comments

Comments
 (0)