diff --git a/src/commands/config.rs b/src/commands/config.rs index d1581bcce..c37c4339f 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -1,10 +1,10 @@ use std::fs; use std::path::Path; -use crate::user::settings::Settings; +use crate::user::settings::GlobalSettings; pub fn global_config(email: &str, api_key: &str) -> Result<(), failure::Error> { - let s = Settings { + let s = GlobalSettings { email: email.to_string(), api_key: api_key.to_string(), }; diff --git a/src/commands/publish/mod.rs b/src/commands/publish/mod.rs index 349dd637e..ac20a1582 100644 --- a/src/commands/publish/mod.rs +++ b/src/commands/publish/mod.rs @@ -36,8 +36,8 @@ fn single_script(zone_id: &str, user: &User) -> Result<(), failure::Error> { client .put(&worker_addr) - .header("X-Auth-Key", settings.api_key) - .header("X-Auth-Email", settings.email) + .header("X-Auth-Key", settings.global.api_key) + .header("X-Auth-Email", settings.global.email) .multipart(build_form()?) .send()?; @@ -56,8 +56,8 @@ fn multi_script(zone_id: &str, user: &User, name: &str) -> Result<(), failure::E client .put(&worker_addr) - .header("X-Auth-Key", settings.api_key) - .header("X-Auth-Email", settings.email) + .header("X-Auth-Key", settings.global.api_key) + .header("X-Auth-Email", settings.global.email) .multipart(build_form()?) .send()?; diff --git a/src/user/account.rs b/src/user/account.rs index d17045a8d..ba626be31 100644 --- a/src/user/account.rs +++ b/src/user/account.rs @@ -50,8 +50,8 @@ fn account_data(settings: Settings) -> Result { let mut res = client .get(user_addr) - .header("X-Auth-Key", settings.api_key) - .header("X-Auth-Email", settings.email) + .header("X-Auth-Key", settings.global.api_key) + .header("X-Auth-Email", settings.global.email) .header(CONTENT_TYPE, "application/json") .send()?; @@ -69,8 +69,8 @@ fn script_status(settings: Settings, account_data: &AccountData) -> Result, + pub routes: Option>, +} + +#[derive(Clone, Serialize)] +pub struct Settings { + pub global: GlobalSettings, + pub project: ProjectSettings, +} + impl Settings { pub fn new() -> Result { - let mut s = Config::new(); + let global = get_global_config()?; + let project = get_project_config()?; - let config_path = dirs::home_dir() - .expect("oops no home dir") - .join(".wrangler/config/default"); - let config_str = config_path - .to_str() - .expect("config path should be a string"); - s.merge(File::with_name(config_str))?; + Ok(Settings { global, project }) + } +} - // Eg.. `CF_ACCOUNT_AUTH_KEY=farts` would set the `account_auth_key` key - s.merge(Environment::with_prefix("CF"))?; +fn get_global_config() -> Result { + let mut s = Config::new(); - Ok(s.try_into()?) - } + let config_path = dirs::home_dir() + .expect("oops no home dir") + .join(".wrangler/config/default"); + let config_str = config_path + .to_str() + .expect("global config path should be a string"); + s.merge(File::with_name(config_str))?; + + // Eg.. `CF_ACCOUNT_AUTH_KEY=farts` would set the `account_auth_key` key + s.merge(Environment::with_prefix("CF"))?; + + Ok(s.try_into()?) +} + +fn get_project_config() -> Result { + let mut s = Config::new(); + + let config_path = Path::new("./wrangler.toml"); + let config_str = config_path + .to_str() + .expect("project config path should be a string"); + s.merge(File::with_name(config_str))?; + + // Eg.. `CF_ACCOUNT_AUTH_KEY=farts` would set the `account_auth_key` key + s.merge(Environment::with_prefix("CF"))?; + + Ok(s.try_into()?) }