feature/ruby-runner
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 | pub mod environment; |
| 3 | pub mod network; |
| 4 | |
| 5 | use anyhow::{anyhow, Result}; |
| 6 | use constants::{SMB_CLIENT_ID, SMB_CLIENT_SECRET}; |
| 7 | use environment::Environment; |
| 8 | use log::debug; |
| 9 | use std::path::{Path, PathBuf}; |
| 10 | use url_builder::URLBuilder; |
| 11 | |
| 12 | pub async fn get_smb_token(env: Environment) -> Result<String> { |
| 13 | if let Some(path) = smb_token_file_path(env) { |
| 14 | std::fs::read_to_string(path).map_err(|e| { |
| 15 | debug!("Error while reading token: {}", &e); |
| 16 | anyhow!("Error while reading token. Are you logged in?") |
| 17 | }) |
| 18 | } else { |
| 19 | Err(anyhow!("Failed to get home directory. Are you logged in?")) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | pub fn smb_token_file_path(env: Environment) -> Option<PathBuf> { |
| 24 | match home::home_dir() { |
| 25 | Some(home_path) => { |
| 26 | let token_path = [&env.smb_dir(), "/token"].join(""); |
| 27 | let token_file = home_path.join(Path::new(&token_path)); |
| 28 | if token_file.exists() && token_file.is_file() { |
| 29 | return Some(token_file); |
| 30 | } |
| 31 | None |
| 32 | } |
| 33 | None => { |
| 34 | debug!("Failed to get home directory."); |
| 35 | None |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | pub fn smb_base_url_builder(env: Environment) -> URLBuilder { |
| 41 | let mut url_builder = URLBuilder::new(); |
| 42 | url_builder |
| 43 | .set_protocol(&env.api_protocol()) |
| 44 | .set_host(&env.api_host()) |
| 45 | .add_param("client_id", SMB_CLIENT_ID) |
| 46 | .add_param("client_secret", SMB_CLIENT_SECRET); |
| 47 | url_builder |
| 48 | } |