-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use derive_getters::Dissolve; | ||
use serde::Deserialize; | ||
use std::env; | ||
use std::fs::read_to_string; | ||
use std::path; | ||
|
||
#[derive(Deserialize, Dissolve)] | ||
pub struct WyvernTokenData { | ||
pub access_token: String, | ||
pub refresh_token: String, | ||
pub user_id: String, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct WyvernConfig { | ||
pub token: WyvernTokenData, | ||
} | ||
|
||
fn get_config_path() -> Option<path::PathBuf> { | ||
let home_dir = env::var("HOME").unwrap(); | ||
let home_dir = path::Path::new(&home_dir); | ||
|
||
let config_path: path::PathBuf = env::var("XDG_CONFIG_HOME") | ||
.unwrap_or_else(|_e| home_dir.join(".config").to_str().unwrap().to_string()) | ||
.into(); | ||
|
||
let wyvern_config_path = config_path.join("wyvern/wyvern.toml"); | ||
|
||
if wyvern_config_path.exists() { | ||
Some(wyvern_config_path) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
pub fn load_tokens() -> WyvernConfig { | ||
let config_path = get_config_path().expect("Wyvern toml doesn't exist"); | ||
let data = read_to_string(config_path).expect("Failed to read wyvern.toml"); | ||
toml::from_str(&data).expect("Failed to parse wyvern config") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters