Skip to content

Commit 0c812d1

Browse files
committed
fix: tedge cert create-csr with profile uses the CN of profile's cert
Signed-off-by: Rina Fujino <rina.fujino.23@gmail.com>
1 parent db8bf7e commit 0c812d1

File tree

1 file changed

+22
-3
lines changed
  • crates/core/tedge/src/cli/certificate

1 file changed

+22
-3
lines changed

crates/core/tedge/src/cli/certificate/cli.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use crate::cli::common::CloudArg;
33
use camino::Utf8PathBuf;
44
use tedge_config::OptionalConfigError;
55
use tedge_config::ProfileName;
6+
use tedge_config::ReadError;
7+
use tedge_config::TEdgeConfig;
68

79
use super::create::CreateCertCmd;
810
use super::create_csr::CreateCsrCmd;
@@ -93,11 +95,14 @@ impl BuildCommand for TEdgeCertCli {
9395
cloud,
9496
} => {
9597
let cloud: Option<Cloud> = cloud.map(<_>::try_into).transpose()?;
98+
9699
// Use the current device id if no id is provided
97-
let id = match id {
98-
Some(id) => id,
99-
None => config.device.id()?.clone(),
100+
let id = if let Some(id) = id {
101+
id
102+
} else {
103+
get_device_id_from_config(&config, &cloud)?
100104
};
105+
101106
let cmd = CreateCsrCmd {
102107
id,
103108
key_path: config.device_key_path(cloud.as_ref())?.to_owned(),
@@ -186,3 +191,17 @@ pub enum UploadCertCli {
186191
profile: Option<ProfileName>,
187192
},
188193
}
194+
195+
fn get_device_id_from_config(
196+
config: &TEdgeConfig,
197+
cloud: &Option<Cloud>,
198+
) -> Result<String, ReadError> {
199+
let id = match cloud {
200+
None => config.device.id(),
201+
Some(Cloud::C8y(profile)) => config.c8y.try_get(profile.as_deref())?.device.id(),
202+
Some(Cloud::Azure(profile)) => config.az.try_get(profile.as_deref())?.device.id(),
203+
Some(Cloud::Aws(profile)) => config.aws.try_get(profile.as_deref())?.device.id(),
204+
}?
205+
.to_owned();
206+
Ok(id)
207+
}

0 commit comments

Comments
 (0)