mirror of
https://github.com/mozilla-services/syncstorage-rs.git
synced 2026-05-05 12:16:21 +02:00
feat: add an extra sanity check of the db url
via Url::parse
This commit is contained in:
parent
ec1b73a630
commit
f58b3bc9b7
@ -15,7 +15,7 @@ use googleapis_raw::spanner::v1::{
|
||||
};
|
||||
use grpcio::{CallOption, ChannelBuilder, ChannelCredentials, EnvBuilder, MetadataBuilder};
|
||||
use log::{info, trace, warn};
|
||||
use url::Url;
|
||||
use url::{Host, Url};
|
||||
|
||||
const SPANNER_ADDRESS: &str = "spanner.googleapis.com:443";
|
||||
|
||||
@ -96,17 +96,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
env_logger::try_init()?;
|
||||
|
||||
const DB_ENV: &str = "SYNC_DATABASE_URL";
|
||||
const INVALID_DB_ENV: String = format!("Invalid {}", DB_ENV);
|
||||
let db_url = env::var(DB_ENV).map_err(|_| format!("Invalid or undefined {}", DB_ENV))?;
|
||||
let url = Url::parse(&db_url).map_err(|e| format!("Invalid {}: {}", DB_ENV, e))?;
|
||||
eprintln!("url: {}, host: {:?}, path: {:?}", url.to_string(), url.host(), url.path());
|
||||
if url.scheme() != "spanner" {
|
||||
if url.scheme() != "spanner" || url.host() != Some(Host::Domain("projects")) {
|
||||
return Err(format!("Invalid {}", DB_ENV).into());
|
||||
}
|
||||
|
||||
let database = db_url["spanner://".len()..].to_owned();
|
||||
let database2 = url.host().ok_or_else(|| format!("Invalid {}", DB_ENV))?.to_string() + url.path();
|
||||
info!("For {} {}", database, database2);
|
||||
info!("For {}", database);
|
||||
|
||||
// Set up the gRPC environment.
|
||||
let env = Arc::new(EnvBuilder::new().build());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user