Skip to content

Commit

Permalink
fix: add default value for project name
Browse files Browse the repository at this point in the history
refactor: rename internal methods

fix: update function name everywhere
  • Loading branch information
alexng353 committed Feb 13, 2025
1 parent b26e1d8 commit 437a73c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/commands/auth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::{
sdk::get_api_url,
sdk::api_url,
utils::{auth::get_token, config::get_config},
};
use anyhow::bail;
Expand Down Expand Up @@ -34,7 +34,7 @@ pub async fn command(args: Args) -> anyhow::Result<()> {

println!("auth token:\n{}", auth_token.signature);

let url = format!("{}test-auth", get_api_url());
let url = format!("{}test-auth", api_url());

if args.debug {
dbg!(&url);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/add_user.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::{
sdk::{get_api_url, SDK},
sdk::{api_url, SDK},
utils::{
auth::get_token,
choice::Choice,
Expand Down Expand Up @@ -100,7 +100,7 @@ pub async fn command(args: Args) -> Result<()> {
let client = reqwest::Client::new();
let auth_token = get_token(&key.fingerprint, &uuid).await?;

let url = get_api_url().join("/variables/update-many")?;
let url = api_url().join("/variables/update-many")?;

let res = client
.post(url)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/remove_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reqwest::header;
use serde_json::json;

use crate::{
sdk::{get_api_url, SDK},
sdk::{api_url, SDK},
types::User,
utils::{
auth::get_token,
Expand Down Expand Up @@ -108,7 +108,7 @@ pub async fn command(args: Args) -> anyhow::Result<()> {
let client = reqwest::Client::new();
let auth_token = get_token(&key.fingerprint, &uuid).await?;

let url = get_api_url().join("/variables/update-many")?;
let url = api_url().join("/variables/update-many")?;

let res = client
.post(url)
Expand Down
34 changes: 17 additions & 17 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ pub struct SetEnvParams {
pub project_id: Option<String>,
}

pub fn get_api_url() -> Url {
pub fn api_url() -> Url {
fn try_get_url() -> Result<Url> {
let dev_mode = std::env::var("DEV_MODE").is_ok();
if dev_mode {
return Ok(Url::parse("http://localhost:3000")?);
}
let url = get_config()?
.sdk_url
.unwrap_or("https://api.env-cli.com".into());
.unwrap_or("https://api.envx.sh".into());
let url = Url::parse(&url)?;
Ok(url)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ impl SDK {
"public_key": public_key
});

let url = get_api_url().join("/user/new")?;
let url = api_url().join("/user/new")?;
let res = client.post(url).json(&body).send().await;

let res = match res {
Expand All @@ -85,7 +85,7 @@ impl SDK {
// GET /v2/project/:id
let client = reqwest::Client::new();

let url = get_api_url().join("v2/project/")?.join(project_id)?;
let url = api_url().join("v2/project/")?.join(project_id)?;

let project_info = client
.get(url)
Expand Down Expand Up @@ -139,7 +139,7 @@ impl SDK {
pub id: String,
}

let url = get_api_url().join("/variables/set-many")?;
let url = api_url().join("/variables/set-many")?;

let res = client
.post(url)
Expand Down Expand Up @@ -172,7 +172,7 @@ impl SDK {

let client = reqwest::Client::new();

let mut url = get_api_url();
let mut url = api_url();
url.set_path(&format!(
"/user/{}/variables",
key.uuid.context("No UUID for key, try `envx upload`")?
Expand Down Expand Up @@ -228,8 +228,8 @@ impl SDK {
// url : /project/:id/variables
let client = reqwest::Client::new();

let url = get_api_url()
.join(&format!("/project/{}/variables", project_id))?;
let url =
api_url().join(&format!("/project/{}/variables", project_id))?;

let encrypted = client
.get(url)
Expand Down Expand Up @@ -299,7 +299,7 @@ impl SDK {
pub public_key: String,
}

let url = get_api_url().join("user/")?.join(user_to_get)?;
let url = api_url().join("user/")?.join(user_to_get)?;

let user = client
.get(url)
Expand Down Expand Up @@ -328,7 +328,7 @@ impl SDK {
});

let url =
get_api_url().join(&format!("/project/{}/add-user", project_id))?;
api_url().join(&format!("/project/{}/add-user", project_id))?;

let res = client
.post(url.join(&format!("/project/{}/add-user", project_id))?)
Expand Down Expand Up @@ -361,8 +361,8 @@ impl SDK {
"users": users_to_remove
});

let url = get_api_url()
.join(&format!("/project/{}/remove-user", project_id))?;
let url =
api_url().join(&format!("/project/{}/remove-user", project_id))?;

let res = client
.post(url)
Expand Down Expand Up @@ -390,7 +390,7 @@ impl SDK {
// url: /project/:id
let client = reqwest::Client::new();

let url = get_api_url().join(&format!("/project/{}", project_id))?;
let url = api_url().join(&format!("/project/{}", project_id))?;

let res = client
.delete(url)
Expand All @@ -417,7 +417,7 @@ impl SDK {
// url: DELETE /variables/:id
let client = reqwest::Client::new();

let url = get_api_url().join("variables/")?.join(variable_id)?;
let url = api_url().join("variables/")?.join(variable_id)?;

client
.delete(url)
Expand All @@ -437,7 +437,7 @@ impl SDK {
// GET /v2/projects
let client = reqwest::Client::new();

let url = get_api_url().join("v2/projects")?;
let url = api_url().join("v2/projects")?;

let res = client
.get(url)
Expand Down Expand Up @@ -477,7 +477,7 @@ impl SDK {
});

let res = client
.post(get_api_url().join("v2/projects/new")?)
.post(api_url().join("v2/projects/new")?)
.header(
header::AUTHORIZATION,
Self::auth_header(partial_fingerprint).await?,
Expand All @@ -499,7 +499,7 @@ impl SDK {

let uuid = key.uuid.context("No UUID for key, try `envx upload`")?;

let url = get_api_url().join("user/")?.join(&uuid)?;
let url = api_url().join("user/")?.join(&uuid)?;

client
.delete(url)
Expand Down
11 changes: 7 additions & 4 deletions src/utils/choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ impl Choice {
.collect::<Vec<_>>();

all_projects.iter().for_each(|p| {
options.push(format!(
"{} - {} - {}",
p.project_id, p.project_name, "Remote"
));
let pname = if p.project_name.trim().is_empty() {
"<unnamed>"
} else {
&p.project_name
};
options
.push(format!("{} - {} - {}", p.project_id, pname, "Remote"));
});

let selected =
Expand Down

0 comments on commit 437a73c

Please sign in to comment.