Skip to content

Commit 4a550e8

Browse files
committed
Correct parsing of organization credentials
1 parent ca530c0 commit 4a550e8

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/config.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ impl ShellConfig {
8989
}
9090

9191
for value in config.capella_orgs_mut() {
92+
let identifier = value.identifier().to_owned();
9293
let config_credentials = value.credentials_mut();
9394

9495
for cred in &standalone.capella_orgs {
95-
if config_credentials.secret_key.is_empty() && !cred.secret_key.is_empty() {
96-
config_credentials.secret_key = cred.secret_key.clone()
97-
}
98-
if config_credentials.access_key.is_empty() && !cred.access_key.is_empty() {
99-
config_credentials.access_key = cred.access_key.clone()
96+
if cred.identifier() == identifier {
97+
if config_credentials.secret_key.is_empty() && !cred.secret_key.is_empty() {
98+
config_credentials.secret_key = cred.secret_key.clone()
99+
}
100+
if config_credentials.access_key.is_empty() && !cred.access_key.is_empty() {
101+
config_credentials.access_key = cred.access_key.clone()
102+
}
100103
}
101104
}
102105
}
@@ -232,7 +235,7 @@ fn try_credentials_from_path(mut path: PathBuf) -> Option<StandaloneCredentialsC
232235
pub struct CapellaOrganizationConfig {
233236
identifier: String,
234237
#[serde(flatten)]
235-
credentials: CapellaOrganizationCredentials,
238+
credentials: OrganizationCredentials,
236239
#[serde(default)]
237240
#[serde(
238241
rename(deserialize = "management-timeout", serialize = "management-timeout"),
@@ -253,7 +256,7 @@ impl CapellaOrganizationConfig {
253256
) -> Self {
254257
Self {
255258
identifier,
256-
credentials: CapellaOrganizationCredentials {
259+
credentials: OrganizationCredentials {
257260
access_key,
258261
secret_key,
259262
},
@@ -277,7 +280,7 @@ impl CapellaOrganizationConfig {
277280
self.default_project.as_ref().cloned()
278281
}
279282

280-
pub fn credentials_mut(&mut self) -> &mut CapellaOrganizationCredentials {
283+
pub fn credentials_mut(&mut self) -> &mut OrganizationCredentials {
281284
&mut self.credentials
282285
}
283286
}
@@ -529,7 +532,7 @@ impl From<(String, &RemoteCluster)> for ClusterConfig {
529532
}
530533

531534
#[derive(Clone, Debug, Deserialize, Serialize)]
532-
pub struct CapellaOrganizationCredentials {
535+
pub struct OrganizationCredentials {
533536
#[serde(default)]
534537
#[serde(rename(deserialize = "access-key", serialize = "access-key"))]
535538
access_key: String,
@@ -538,7 +541,7 @@ pub struct CapellaOrganizationCredentials {
538541
secret_key: String,
539542
}
540543

541-
impl CapellaOrganizationCredentials {}
544+
impl OrganizationCredentials {}
542545

543546
#[derive(Debug, Deserialize, Serialize)]
544547
pub struct ClusterCredentials {
@@ -687,7 +690,7 @@ pub struct StandaloneCredentialsConfig {
687690
clusters: Vec<StandaloneClusterCredentials>,
688691

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

692695
#[serde(alias = "llm", default)]
693696
llms: Vec<LLMCredentials>,
@@ -719,6 +722,23 @@ impl Default for StandaloneCredentialsConfig {
719722
}
720723
}
721724

725+
#[derive(Clone, Debug, Deserialize, Serialize)]
726+
pub struct StandaloneOrganizationCredentials {
727+
identifier: String,
728+
#[serde(default)]
729+
#[serde(rename(deserialize = "access-key", serialize = "access-key"))]
730+
access_key: String,
731+
#[serde(default)]
732+
#[serde(rename(deserialize = "secret-key", serialize = "secret-key"))]
733+
secret_key: String,
734+
}
735+
736+
impl StandaloneOrganizationCredentials {
737+
fn identifier(&self) -> String {
738+
self.identifier.clone()
739+
}
740+
}
741+
722742
#[derive(Debug, Deserialize)]
723743
pub struct StandaloneClusterCredentials {
724744
identifier: String,

0 commit comments

Comments
 (0)