From 3ee9bb1c9c4608fa94313696030e48a2b8947ae2 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Fri, 7 Jul 2023 18:19:47 +0200 Subject: [PATCH 1/2] Check libsql url is in the right shape Signed-off-by: Ryan Levick --- crates/trigger/src/runtime_config/sqlite.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/trigger/src/runtime_config/sqlite.rs b/crates/trigger/src/runtime_config/sqlite.rs index 5ce9df39ad..d8803cbdc6 100644 --- a/crates/trigger/src/runtime_config/sqlite.rs +++ b/crates/trigger/src/runtime_config/sqlite.rs @@ -132,12 +132,29 @@ pub struct LibsqlOpts { impl LibsqlOpts { fn build(&self) -> anyhow::Result> { - let client = spin_sqlite_libsql::LibsqlClient::create(&self.url, self.token.clone()) + let url = &check_url(&self.url).with_context(|| { + format!( + "unexpected libsql url '{}' in runtime config file ", + self.url + ) + })?; + let client = spin_sqlite_libsql::LibsqlClient::create(url, self.token.clone()) .context("failed to create SQLite client")?; Ok(Arc::new(client)) } } +// Checks an incoming url is in the shape we expect +fn check_url(url: &str) -> anyhow::Result<&str> { + if url.starts_with("https://") || url.starts_with("http://") { + Ok(url) + } else { + Err(anyhow::anyhow!( + "url does not start with 'https://' or 'http://'. Spin currently only supports talking to libsql databases over http(s)" + )) + } +} + pub struct SqlitePersistenceMessageHook; impl TriggerHooks for SqlitePersistenceMessageHook { From eba7e24aec4affdcaeefc39d9ee65d5b91d2604e Mon Sep 17 00:00:00 2001 From: itowlson Date: Tue, 11 Jul 2023 09:42:09 +1200 Subject: [PATCH 2/2] Capitalisation in libSQL URL error messages Signed-off-by: itowlson --- crates/trigger/src/runtime_config/sqlite.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/trigger/src/runtime_config/sqlite.rs b/crates/trigger/src/runtime_config/sqlite.rs index d8803cbdc6..6cab60cc8c 100644 --- a/crates/trigger/src/runtime_config/sqlite.rs +++ b/crates/trigger/src/runtime_config/sqlite.rs @@ -134,7 +134,7 @@ impl LibsqlOpts { fn build(&self) -> anyhow::Result> { let url = &check_url(&self.url).with_context(|| { format!( - "unexpected libsql url '{}' in runtime config file ", + "unexpected libSQL URL '{}' in runtime config file ", self.url ) })?; @@ -150,7 +150,7 @@ fn check_url(url: &str) -> anyhow::Result<&str> { Ok(url) } else { Err(anyhow::anyhow!( - "url does not start with 'https://' or 'http://'. Spin currently only supports talking to libsql databases over http(s)" + "URL does not start with 'https://' or 'http://'. Spin currently only supports talking to libSQL databases over HTTP(S)" )) } }