feature/apps
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | pub mod constants; |
| 2 | |
| 3 | use anyhow::{anyhow, Result}; |
| 4 | use log::debug; |
| 5 | use smbpndk_model::Config; |
| 6 | |
| 7 | pub async fn get_token() -> Result<String> { |
| 8 | if let Some(mut path) = dirs::home_dir() { |
| 9 | path.push(".smb/token"); |
| 10 | std::fs::read_to_string(path).map_err(|e| { |
| 11 | debug!("Error while reading token: {}", &e); |
| 12 | anyhow!("Error while reading token. Are you logged in?") |
| 13 | }) |
| 14 | } else { |
| 15 | Err(anyhow!("Failed to get home directory.")) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | pub async fn get_config() -> Result<Config> { |
| 20 | match dirs::home_dir() { |
| 21 | Some(mut path) => { |
| 22 | path.push(".smb/config"); |
| 23 | let config = std::fs::read_to_string(path)?; |
| 24 | let config: Config = serde_json::from_str(&config)?; |
| 25 | Ok(config) |
| 26 | } |
| 27 | None => Err(anyhow!("Failed to get home directory.")), |
| 28 | } |
| 29 | } |