Skip to content

Commit

Permalink
fix: remove deprecated get_config function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexng353 committed Feb 20, 2025
1 parent c01e6a7 commit d0bc0e3
Show file tree
Hide file tree
Showing 36 changed files with 81 additions and 93 deletions.
4 changes: 2 additions & 2 deletions src/commands/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::{
sdk::api_url,
utils::{auth::get_token, config::get_config},
utils::{auth::get_token, config::Config},
};
use anyhow::bail;
use reqwest::header;
Expand All @@ -19,7 +19,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> anyhow::Result<()> {
let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(args.key)?;

let client = reqwest::Client::new();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/set/keyring_expiry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::config::get_config;
use crate::utils::config::Config;

use super::*;

Expand All @@ -18,7 +18,7 @@ pub async fn command(args: Args) -> Result<()> {
} else {
println!("Setting keyring expiry to {} days", args.days);
}
let mut config = get_config()?;
let mut config = Config::get()?;
let mut settings = config.get_settings()?;

if args.days == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/set/primary_key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::utils::{config::get_config, prompt::prompt_select};
use crate::utils::{config::Config, prompt::prompt_select};

/// Set the primary key in the global config
#[derive(Parser)]
Expand All @@ -10,7 +10,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let mut config = get_config()?;
let mut config = Config::get()?;

let fingerprint = match args.key {
Some(k) => k,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/set/unsafe_password.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::utils::{
config::{get_config, get_config_path},
config::{get_config_path, Config},
prompt::{prompt_confirm, prompt_password},
};

Expand All @@ -19,7 +19,7 @@ pub async fn command(args: Args) -> Result<()> {
println!("This command is VERY insecure. It will store your password in PLAIN TEXT in the config file.");
prompt_confirm("Are you sure you want to continue?")?;

let mut config = get_config()?;
let mut config = Config::get()?;

let password = match args.password {
Some(k) => k,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::utils::{config::get_config, rpgp::decrypt_full};
use crate::utils::{config::Config, rpgp::decrypt_full};
use anyhow::{Context, Result};

/// Decrypt a string using GPG
Expand All @@ -9,7 +9,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config().context("Failed to get config")?;
let config = Config::get().context("Failed to get config")?;

let decrypted = decrypt_full(args.message, &config)?;

Expand Down
4 changes: 2 additions & 2 deletions src/commands/delete/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
use crate::{
sdk::SDK,
utils::{
config::Config,
key::Key,
prompt::{prompt_confirm, prompt_multi_options},
},
Expand All @@ -24,8 +25,7 @@ pub struct Args {
// TODO: fix configuration race condition while deleting multiple keys

pub async fn command(args: Args) -> Result<()> {
let mut config =
crate::utils::config::get_config().context("Failed to get config")?;
let mut config = Config::get().context("Failed to get config")?;
let kl_arc = std::sync::Arc::new(&config.keys);
let primary_key = &config.primary_key;

Expand Down
4 changes: 2 additions & 2 deletions src/commands/delete/project.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
sdk::SDK,
utils::{choice::Choice, config::get_config},
utils::{choice::Choice, config::Config},
};

use super::*;
Expand All @@ -16,7 +16,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let mut config = get_config()?;
let mut config = Config::get()?;
let key = config.get_key_or_default(args.key)?;

let project_id =
Expand Down
4 changes: 2 additions & 2 deletions src/commands/encrypt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;

use crate::utils::{
config::get_config,
config::Config,
rpgp::{encrypt, get_vault_location},
};

Expand All @@ -18,7 +18,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config().context("Failed to get config")?;
let config = Config::get().context("Failed to get config")?;

let primary_key = config.primary_key.clone();

Expand Down
6 changes: 2 additions & 4 deletions src/commands/export.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::*;
use crate::utils::{
config::get_config, key::VecKeyTrait, prompt::prompt_options,
};
use crate::utils::{config::Config, key::VecKeyTrait, prompt::prompt_options};

/// Export a public or secret key
#[derive(Parser)]
Expand All @@ -16,7 +14,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config().context("Failed to get config")?;
let config = Config::get().context("Failed to get config")?;

let keys: Vec<&str> = config.keys.all_fingerprints();

Expand Down
2 changes: 1 addition & 1 deletion src/commands/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn email_validator(email: &str) -> anyhow::Result<(), anyhow::Error> {
}

pub async fn command(args: Args) -> Result<()> {
let mut config = config::get_config().context("Failed to get config")?;
let mut config = config::Config::get().context("Failed to get config")?;
let settings = config.get_settings()?;

let name = args
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::utils::btreemap::ToBTreeMap;
use crate::utils::config::get_config;
use crate::utils::config::Config;
use crate::utils::table::Table;
use anyhow::Context;
use anyhow::Result;
Expand All @@ -16,7 +16,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;

if args.json {
let json = serde_json::to_string_pretty(&config)
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get/keys.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::utils::config::get_config;
use crate::utils::config::Config;

/// List all keys in the config
#[derive(Parser)]
Expand All @@ -10,7 +10,7 @@ pub struct Args {
}

pub async fn command(_args: Args) -> Result<()> {
let config = get_config().context("Failed to get config")?;
let config = Config::get().context("Failed to get config")?;

println!("Keys:");
for key in config.keys.iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::utils::config::get_config;
use crate::utils::config::Config;
use crate::{sdk::SDK, utils::choice::Choice};

/// Get all environment variables for a project
Expand All @@ -20,7 +20,7 @@ pub struct Args {

// TODO: Pretty print project info (in a table?)
pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(args.key)?;
let project_id =
Choice::try_project(args.project_id, &key.fingerprint).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get/projects.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{sdk::SDK, utils::config::get_config};
use crate::{sdk::SDK, utils::config::Config};

use super::*;

Expand All @@ -9,7 +9,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(None)?;

let local_projects = config.projects.clone();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/keyring/clear.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{
config::get_config, keyring::clear_password, prompt::prompt_select,
config::Config, keyring::clear_password, prompt::prompt_select,
};

use super::*;
Expand All @@ -15,7 +15,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;

let fingerprint = match args.key {
Some(key) => config.get_key(&key)?.fingerprint,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/keyring/view.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{
config::get_config,
config::Config,
keyring::get_password,
prompt::{prompt_confirm_with_default, prompt_select},
};
Expand All @@ -21,7 +21,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;

let fingerprint = match args.key {
Some(key) => config.get_key(&key)?.fingerprint,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/link.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::utils::choice::Choice;
use crate::utils::config::get_config;
use crate::utils::config::Config;

/// Get all environment variables for a project
#[derive(Parser)]
Expand All @@ -19,7 +19,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let mut config = get_config()?;
let mut config = Config::get()?;

let projects = &config.projects;
let cwd = std::env::current_dir()?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/new/project.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::utils::prompt::prompt_text;
use crate::{sdk::SDK, utils::config::get_config};
use crate::{sdk::SDK, utils::config::Config};

/// Create a new project
#[derive(Parser)]
Expand All @@ -18,7 +18,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(args.key)?;

// check if nn flag is set
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/add_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
utils::{
auth::get_token,
choice::Choice,
config::get_config,
config::Config,
prompt::prompt_text,
rpgp::encrypt_multi,
variable::{EncryptedVariable, ToKVPair},
Expand Down Expand Up @@ -39,7 +39,7 @@ pub async fn command(args: Args) -> Result<()> {
};
let user_id = user_id.trim().to_string();

let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(args.key)?;

let uuid = key
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/list_users.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::types::PartialUser;
use crate::utils::config::get_config;
use crate::utils::config::Config;
use crate::{sdk::SDK, utils::choice::Choice};

/// Get all environment variables for a project
Expand All @@ -25,7 +25,7 @@ pub struct Args {

// TODO: Pretty print project info (in a table?)
pub async fn command(args: Args) -> Result<()> {
let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(args.key)?;
let project_id =
Choice::try_project(args.project_id, &key.fingerprint).await?;
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 @@ -13,7 +13,7 @@ use crate::{
utils::{
auth::get_token,
choice::Choice,
config::get_config,
config::Config,
prompt::prompt_multi_options,
rpgp::encrypt_multi,
variable::{EncryptedVariable, ToKVPair},
Expand All @@ -37,7 +37,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> anyhow::Result<()> {
let config = get_config()?;
let config = Config::get()?;
let key = config.get_key_or_default(args.key)?;

let uuid = key
Expand Down
4 changes: 2 additions & 2 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::utils::choice::Choice;
use crate::utils::{choice::Choice, config::Config};
use anyhow::bail;
use std::collections::BTreeMap;

Expand All @@ -19,7 +19,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = crate::utils::config::get_config()?;
let config = Config::get()?;
let key = match args.key {
Some(k) => k.to_owned(),
None => config.primary_key.clone(),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
sdk::SDK,
utils::{
choice::Choice,
config::get_config,
config::Config,
kvpair::KVPair,
// partial_variable::ToParsed,
prompt::prompt_confirm,
Expand Down Expand Up @@ -39,7 +39,7 @@ pub async fn command(args: Args) -> Result<()> {
);
}

let config = get_config()?;
let config = Config::get()?;
let key = match &args.key {
Some(k) => k,
None => &config.primary_key,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/shell.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::choice::Choice;
use crate::utils::config::Config;

use super::*;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -40,7 +41,7 @@ pub struct Args {
}

pub async fn command(args: Args) -> Result<()> {
let config = crate::utils::config::get_config()?;
let config = Config::get()?;
let key = match args.key {
Some(k) => k.to_owned(),
None => config.primary_key.clone(),
Expand Down
Loading

0 comments on commit d0bc0e3

Please sign in to comment.