Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check libsql url is in the right shape #1636

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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