feat: follow XDG spec on linux/mac and use windows known folders for config and logs (#1153)
This commit is contained in:
@@ -58,7 +58,7 @@ ctor = "0.2.7"
|
||||
paste = "1.0"
|
||||
serde_yaml = "0.9.34"
|
||||
once_cell = "1.20.2"
|
||||
dirs = "6.0.0"
|
||||
etcetera = "0.8.0"
|
||||
rand = "0.8.5"
|
||||
|
||||
# For Bedrock provider
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use etcetera::{choose_app_strategy, AppStrategy, AppStrategyArgs};
|
||||
use keyring::Entry;
|
||||
use once_cell::sync::OnceCell;
|
||||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
@@ -7,6 +8,12 @@ use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use thiserror::Error;
|
||||
|
||||
pub static APP_STRATEGY: Lazy<AppStrategyArgs> = Lazy::new(|| AppStrategyArgs {
|
||||
top_level_domain: "Block".to_string(),
|
||||
author: "Block".to_string(),
|
||||
app_name: "goose".to_string(),
|
||||
});
|
||||
|
||||
const KEYRING_SERVICE: &str = "goose";
|
||||
const KEYRING_USERNAME: &str = "secrets";
|
||||
|
||||
@@ -99,10 +106,13 @@ static GLOBAL_CONFIG: OnceCell<Config> = OnceCell::new();
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
let config_dir = dirs::home_dir()
|
||||
// choose_app_strategy().config_dir()
|
||||
// - macOS/Linux: ~/.config/goose/
|
||||
// - Windows: ~\AppData\Roaming\Block\goose\config\
|
||||
let config_dir = choose_app_strategy(APP_STRATEGY.clone())
|
||||
.expect("goose requires a home dir")
|
||||
.join(".config")
|
||||
.join("goose");
|
||||
.config_dir();
|
||||
|
||||
std::fs::create_dir_all(&config_dir).expect("Failed to create config directory");
|
||||
|
||||
let config_path = config_dir.join("config.yaml");
|
||||
|
||||
@@ -2,5 +2,5 @@ mod base;
|
||||
mod extensions;
|
||||
|
||||
pub use crate::agents::ExtensionConfig;
|
||||
pub use base::{Config, ConfigError};
|
||||
pub use base::{Config, ConfigError, APP_STRATEGY};
|
||||
pub use extensions::{ExtensionEntry, ExtensionManager};
|
||||
|
||||
@@ -2,6 +2,7 @@ use anyhow::Result;
|
||||
use axum::{extract::Query, response::Html, routing::get, Router};
|
||||
use base64::Engine;
|
||||
use chrono::{DateTime, Utc};
|
||||
use etcetera::{choose_app_strategy, AppStrategy};
|
||||
use lazy_static::lazy_static;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
@@ -31,13 +32,12 @@ struct TokenCache {
|
||||
}
|
||||
|
||||
fn get_base_path() -> PathBuf {
|
||||
const BASE_PATH: &str = ".config/goose/databricks/oauth";
|
||||
let home_dir = if cfg!(windows) {
|
||||
std::env::var("USERPROFILE").expect("USERPROFILE environment variable not set")
|
||||
} else {
|
||||
std::env::var("HOME").expect("HOME environment variable not set")
|
||||
};
|
||||
PathBuf::from(home_dir).join(BASE_PATH)
|
||||
// choose_app_strategy().config_dir()
|
||||
// - macOS/Linux: ~/.config/goose/databricks/oauth
|
||||
// - Windows: ~\AppData\Roaming\Block\goose\config\databricks\oauth\
|
||||
choose_app_strategy(crate::config::APP_STRATEGY.clone())
|
||||
.expect("goose requires a home dir")
|
||||
.in_config_dir("databricks/oauth")
|
||||
}
|
||||
|
||||
impl TokenCache {
|
||||
|
||||
Reference in New Issue
Block a user