Add more logging
This commit is contained in:
parent
921a2a5c83
commit
c63c26137d
|
@ -54,6 +54,7 @@ impl LldapConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_client(&self) -> Result<LldapClient> {
|
pub async fn build_client(&self) -> Result<LldapClient> {
|
||||||
|
debug!("Creating LLDAP client");
|
||||||
let timeout = Duration::from_secs(1);
|
let timeout = Duration::from_secs(1);
|
||||||
|
|
||||||
let client = reqwest::ClientBuilder::new().timeout(timeout).build()?;
|
let client = reqwest::ClientBuilder::new().timeout(timeout).build()?;
|
||||||
|
|
|
@ -13,7 +13,7 @@ use passwords::PasswordGenerator;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument, trace};
|
||||||
|
|
||||||
use crate::context::{Context, ControllerEvents};
|
use crate::context::{Context, ControllerEvents};
|
||||||
use crate::lldap;
|
use crate::lldap;
|
||||||
|
@ -110,6 +110,7 @@ impl ServiceUser {
|
||||||
let secrets = Api::<Secret>::namespaced(client.clone(), &namespace);
|
let secrets = Api::<Secret>::namespaced(client.clone(), &namespace);
|
||||||
|
|
||||||
// TODO: Potentially issue: someone modifies the secret and removes the pass
|
// TODO: Potentially issue: someone modifies the secret and removes the pass
|
||||||
|
trace!(name, "Get or create secret");
|
||||||
let mut created = false;
|
let mut created = false;
|
||||||
let mut secret = secrets
|
let mut secret = secrets
|
||||||
.entry(&secret_name)
|
.entry(&secret_name)
|
||||||
|
@ -124,6 +125,7 @@ impl ServiceUser {
|
||||||
new_secret(&username, oref)
|
new_secret(&username, oref)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
trace!(name, "Committing secret");
|
||||||
secret
|
secret
|
||||||
.commit(&PostParams {
|
.commit(&PostParams {
|
||||||
dry_run: false,
|
dry_run: false,
|
||||||
|
@ -133,6 +135,7 @@ impl ServiceUser {
|
||||||
let secret = secret;
|
let secret = secret;
|
||||||
|
|
||||||
if created {
|
if created {
|
||||||
|
trace!(name, "Sending secret creating notification");
|
||||||
// The reason this is here instead of inside the or_insert is that we
|
// The reason this is here instead of inside the or_insert is that we
|
||||||
// want to send the event _after_ it successfully committed.
|
// want to send the event _after_ it successfully committed.
|
||||||
// Also or_insert is not async!
|
// Also or_insert is not async!
|
||||||
|
@ -143,6 +146,7 @@ impl ServiceUser {
|
||||||
|
|
||||||
let lldap_client = ctx.lldap_config.build_client().await?;
|
let lldap_client = ctx.lldap_config.build_client().await?;
|
||||||
|
|
||||||
|
trace!(name, "Creating user if needed");
|
||||||
if lldap_client.list_users().await?.any(|id| id == username) {
|
if lldap_client.list_users().await?.any(|id| id == username) {
|
||||||
debug!(name, username, "User already exists");
|
debug!(name, username, "User already exists");
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,10 +156,12 @@ impl ServiceUser {
|
||||||
ctx.recorder.user_created(self.as_ref(), &username).await?;
|
ctx.recorder.user_created(self.as_ref(), &username).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace!(name, "Updating password");
|
||||||
let password = secret.get().data.as_ref().unwrap().get("password").unwrap();
|
let password = secret.get().data.as_ref().unwrap().get("password").unwrap();
|
||||||
let password = from_utf8(&password.0).unwrap();
|
let password = from_utf8(&password.0).unwrap();
|
||||||
lldap_client.update_password(&username, password).await?;
|
lldap_client.update_password(&username, password).await?;
|
||||||
|
|
||||||
|
trace!(name, "Updating status");
|
||||||
let service_users = Api::<ServiceUser>::namespaced(client.clone(), &namespace);
|
let service_users = Api::<ServiceUser>::namespaced(client.clone(), &namespace);
|
||||||
let status = json!({
|
let status = json!({
|
||||||
"status": ServiceUserStatus { secret_created: secret.get().meta().creation_timestamp.as_ref().map(|ts| ts.0) }
|
"status": ServiceUserStatus { secret_created: secret.get().meta().creation_timestamp.as_ref().map(|ts| ts.0) }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user