Skip to content

Commit

Permalink
Merge pull request #1636 from fermyon/check-libsql-url
Browse files Browse the repository at this point in the history
Check libsql url is in the right shape
  • Loading branch information
itowlson authored Jul 10, 2023
2 parents 9cf1dad + eba7e24 commit 1540d13
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion crates/trigger/src/runtime_config/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,29 @@ pub struct LibsqlOpts {

impl LibsqlOpts {
fn build(&self) -> anyhow::Result<Arc<dyn Connection>> {
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 {
Expand Down

0 comments on commit 1540d13

Please sign in to comment.