service-account or person validity show returns for non-existing identity (#2258)

Fixes #2152
This commit is contained in:
James Hodgkinson 2023-10-27 14:00:37 +10:00 committed by GitHub
parent 208d7c9932
commit 18b4b7549f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 54 deletions

View file

@ -352,30 +352,29 @@ impl PersonOpt {
AccountValidity::Show(ano) => { AccountValidity::Show(ano) => {
let client = ano.copt.to_client(OpType::Read).await; let client = ano.copt.to_client(OpType::Read).await;
let entry = match client
.idm_person_account_get(ano.aopts.account_id.as_str())
.await
{
Err(err) => {
error!(
"No account {} found, or other error occurred: {:?}",
ano.aopts.account_id.as_str(),
err
);
return;
}
Ok(val) => match val {
Some(val) => val,
None => {
error!("No account {} found!", ano.aopts.account_id.as_str());
return;
}
},
};
println!("user: {}", ano.aopts.account_id.as_str()); println!("user: {}", ano.aopts.account_id.as_str());
let ex = match client if let Some(t) = entry.attrs.get(ATTR_ACCOUNT_VALID_FROM) {
.idm_person_account_get_attr(
ano.aopts.account_id.as_str(),
ATTR_ACCOUNT_EXPIRE,
)
.await
{
Ok(v) => v,
Err(e) => return handle_client_error(e, &ano.copt.output_mode),
};
let vf = match client
.idm_person_account_get_attr(
ano.aopts.account_id.as_str(),
ATTR_ACCOUNT_VALID_FROM,
)
.await
{
Ok(v) => v,
Err(e) => return handle_client_error(e, &ano.copt.output_mode),
};
if let Some(t) = vf {
// Convert the time to local timezone. // Convert the time to local timezone.
let t = OffsetDateTime::parse(&t[0], &Rfc3339) let t = OffsetDateTime::parse(&t[0], &Rfc3339)
.map(|odt| { .map(|odt| {
@ -393,7 +392,7 @@ impl PersonOpt {
println!("valid after: any time"); println!("valid after: any time");
} }
if let Some(t) = ex { if let Some(t) = entry.attrs.get(ATTR_ACCOUNT_EXPIRE) {
let t = OffsetDateTime::parse(&t[0], &Rfc3339) let t = OffsetDateTime::parse(&t[0], &Rfc3339)
.map(|odt| { .map(|odt| {
odt.to_offset( odt.to_offset(

View file

@ -365,36 +365,29 @@ impl ServiceAccountOpt {
AccountValidity::Show(ano) => { AccountValidity::Show(ano) => {
let client = ano.copt.to_client(OpType::Read).await; let client = ano.copt.to_client(OpType::Read).await;
let entry = match client
.idm_service_account_get(ano.aopts.account_id.as_str())
.await
{
Err(err) => {
error!(
"No account {} found, or other error occurred: {:?}",
ano.aopts.account_id.as_str(),
err
);
return;
}
Ok(val) => match val {
Some(val) => val,
None => {
error!("No account {} found!", ano.aopts.account_id.as_str());
return;
}
},
};
println!("user: {}", ano.aopts.account_id.as_str()); println!("user: {}", ano.aopts.account_id.as_str());
let ex = match client if let Some(t) = entry.attrs.get(ATTR_ACCOUNT_VALID_FROM) {
.idm_service_account_get_attr(
ano.aopts.account_id.as_str(),
ATTR_ACCOUNT_EXPIRE,
)
.await
{
Ok(v) => v,
Err(e) => {
error!("Error -> {:?}", e);
return;
}
};
let vf = match client
.idm_service_account_get_attr(
ano.aopts.account_id.as_str(),
ATTR_ACCOUNT_VALID_FROM,
)
.await
{
Ok(v) => v,
Err(e) => {
error!("Error -> {:?}", e);
return;
}
};
if let Some(t) = vf {
// Convert the time to local timezone. // Convert the time to local timezone.
let t = OffsetDateTime::parse(&t[0], &Rfc3339) let t = OffsetDateTime::parse(&t[0], &Rfc3339)
.map(|odt| { .map(|odt| {
@ -412,7 +405,7 @@ impl ServiceAccountOpt {
println!("valid after: any time"); println!("valid after: any time");
} }
if let Some(t) = ex { if let Some(t) = entry.attrs.get(ATTR_ACCOUNT_EXPIRE) {
let t = OffsetDateTime::parse(&t[0], &Rfc3339) let t = OffsetDateTime::parse(&t[0], &Rfc3339)
.map(|odt| { .map(|odt| {
odt.to_offset( odt.to_offset(