Skip to content

Commit

Permalink
Correct parsing of organization credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Westwooo committed Aug 22, 2024
1 parent ca530c0 commit 4a550e8
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,17 @@ impl ShellConfig {
}

for value in config.capella_orgs_mut() {
let identifier = value.identifier().to_owned();
let config_credentials = value.credentials_mut();

for cred in &standalone.capella_orgs {
if config_credentials.secret_key.is_empty() && !cred.secret_key.is_empty() {
config_credentials.secret_key = cred.secret_key.clone()
}
if config_credentials.access_key.is_empty() && !cred.access_key.is_empty() {
config_credentials.access_key = cred.access_key.clone()
if cred.identifier() == identifier {
if config_credentials.secret_key.is_empty() && !cred.secret_key.is_empty() {
config_credentials.secret_key = cred.secret_key.clone()
}
if config_credentials.access_key.is_empty() && !cred.access_key.is_empty() {
config_credentials.access_key = cred.access_key.clone()
}
}
}
}
Expand Down Expand Up @@ -232,7 +235,7 @@ fn try_credentials_from_path(mut path: PathBuf) -> Option<StandaloneCredentialsC
pub struct CapellaOrganizationConfig {
identifier: String,
#[serde(flatten)]
credentials: CapellaOrganizationCredentials,
credentials: OrganizationCredentials,
#[serde(default)]
#[serde(
rename(deserialize = "management-timeout", serialize = "management-timeout"),
Expand All @@ -253,7 +256,7 @@ impl CapellaOrganizationConfig {
) -> Self {
Self {
identifier,
credentials: CapellaOrganizationCredentials {
credentials: OrganizationCredentials {
access_key,
secret_key,
},
Expand All @@ -277,7 +280,7 @@ impl CapellaOrganizationConfig {
self.default_project.as_ref().cloned()
}

pub fn credentials_mut(&mut self) -> &mut CapellaOrganizationCredentials {
pub fn credentials_mut(&mut self) -> &mut OrganizationCredentials {
&mut self.credentials
}
}
Expand Down Expand Up @@ -529,7 +532,7 @@ impl From<(String, &RemoteCluster)> for ClusterConfig {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CapellaOrganizationCredentials {
pub struct OrganizationCredentials {
#[serde(default)]
#[serde(rename(deserialize = "access-key", serialize = "access-key"))]
access_key: String,
Expand All @@ -538,7 +541,7 @@ pub struct CapellaOrganizationCredentials {
secret_key: String,
}

impl CapellaOrganizationCredentials {}
impl OrganizationCredentials {}

#[derive(Debug, Deserialize, Serialize)]
pub struct ClusterCredentials {
Expand Down Expand Up @@ -687,7 +690,7 @@ pub struct StandaloneCredentialsConfig {
clusters: Vec<StandaloneClusterCredentials>,

#[serde(alias = "capella-organization", default)]
capella_orgs: Vec<CapellaOrganizationCredentials>,
capella_orgs: Vec<StandaloneOrganizationCredentials>,

#[serde(alias = "llm", default)]
llms: Vec<LLMCredentials>,
Expand Down Expand Up @@ -719,6 +722,23 @@ impl Default for StandaloneCredentialsConfig {
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StandaloneOrganizationCredentials {
identifier: String,
#[serde(default)]
#[serde(rename(deserialize = "access-key", serialize = "access-key"))]
access_key: String,
#[serde(default)]
#[serde(rename(deserialize = "secret-key", serialize = "secret-key"))]
secret_key: String,
}

impl StandaloneOrganizationCredentials {
fn identifier(&self) -> String {
self.identifier.clone()
}
}

#[derive(Debug, Deserialize)]
pub struct StandaloneClusterCredentials {
identifier: String,
Expand Down

0 comments on commit 4a550e8

Please sign in to comment.