Skip to content

Commit

Permalink
move partial_variable -> variable
Browse files Browse the repository at this point in the history
  • Loading branch information
alexng353 committed Sep 3, 2024
1 parent a674b20 commit 74c3c2e
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/commands/project/add_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use crate::{
auth::get_token,
choice::Choice,
config::get_config,
partial_variable::{EncryptedVariable, ToKVPair},
prompt::prompt_text,
rpgp::encrypt_multi,
variable::{EncryptedVariable, ToKVPair},
},
};
use pgp::{Deserializable, SignedPublicKey};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project/remove_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use crate::{
auth::get_token,
choice::Choice,
config::get_config,
partial_variable::{EncryptedVariable, ToKVPair},
prompt::prompt_multi_options,
rpgp::encrypt_multi,
variable::{EncryptedVariable, ToKVPair},
},
};

Expand Down
3 changes: 1 addition & 2 deletions src/commands/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use super::*;
use crate::{
sdk::SDK,
utils::{
btreemap::ToBTreeMap, choice::Choice, config::get_config,
partial_variable::ToKVPair, table::Table,
btreemap::ToBTreeMap, choice::Choice, config::get_config, table::Table, variable::ToKVPair
},
};
/// Get all environment variables for the current configured directory
Expand Down
4 changes: 2 additions & 2 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
auth::get_token,
config::get_config,
kvpair::KVPair,
partial_variable::{DecryptedVariable, EncryptedVariable, ToKVPair},
rpgp::{decrypt_full_many, encrypt_multi},
variable::{DecryptedVariable, EncryptedVariable, ToKVPair},
},
};
use anyhow::bail;
Expand All @@ -16,7 +16,7 @@ use reqwest::header;
use serde::{Deserialize, Serialize};
use serde_json::json;
use url::Url;
use utils::partial_variable::DeDupe;
use utils::variable::DeDupe;

#[derive(Serialize, Deserialize, Debug)]
pub struct SetEnvParams {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod config;
pub mod key;
pub mod keyring;
pub mod kvpair;
pub mod partial_variable;
pub mod variable;
pub mod prompt;
pub mod rpgp;
pub mod settings;
Expand Down
5 changes: 0 additions & 5 deletions src/utils/partial_variable.rs → src/utils/variable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};

use super::kvpair::KVPair;
Expand Down Expand Up @@ -26,20 +25,16 @@ use std::{collections::HashMap, fmt::Display};

impl DeDupe for Vec<DecryptedVariable> {
fn dedupe(&self) -> Self {
// Sort the vector based on the `created_at` timestamp in descending order
let mut sorted_vec = self.clone();
sorted_vec.sort_by(|a, b| b.created_at.cmp(&a.created_at));

// HashMap to track encountered keys
let mut seen: HashMap<String, DecryptedVariable> = HashMap::new();

// Iterate and populate the HashMap
for variable in sorted_vec {
let key = variable.value.key.clone();
seen.entry(key).or_insert(variable);
}

// Collect the deduplicated variables into a new Vec
seen.into_values().collect()
}
}
Expand Down

0 comments on commit 74c3c2e

Please sign in to comment.