Cleaned up events
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 9m7s
All checks were successful
Build and deploy / Build container and manifests (push) Successful in 9m7s
This commit is contained in:
parent
d21b53cf34
commit
9c37b2a2d1
|
@ -34,23 +34,19 @@ pub trait ControllerEvents {
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
async fn user_created<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_created<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
async fn group_created<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
async fn group_created<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
async fn user_deleted<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_deleted<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
async fn group_deleted<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
async fn group_deleted<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
|
||||||
|
|
||||||
async fn user_not_found<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync;
|
T: Resource<DynamicType = ()> + Sync;
|
||||||
|
|
||||||
|
@ -87,16 +83,16 @@ impl ControllerEvents for Recorder {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn user_created<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_created<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
T: Resource<DynamicType = ()> + Sync,
|
||||||
{
|
{
|
||||||
self.publish(
|
self.publish(
|
||||||
&Event {
|
&Event {
|
||||||
type_: EventType::Normal,
|
type_: EventType::Normal,
|
||||||
reason: "UserCreated".into(),
|
reason: "Created".into(),
|
||||||
note: Some(format!("Created user '{username}'")),
|
note: Some("Created user".into()),
|
||||||
action: "UserCreated".into(),
|
action: "Created".into(),
|
||||||
secondary: None,
|
secondary: None,
|
||||||
},
|
},
|
||||||
&obj.object_ref(&()),
|
&obj.object_ref(&()),
|
||||||
|
@ -104,16 +100,16 @@ impl ControllerEvents for Recorder {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn group_created<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
async fn group_created<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
T: Resource<DynamicType = ()> + Sync,
|
||||||
{
|
{
|
||||||
self.publish(
|
self.publish(
|
||||||
&Event {
|
&Event {
|
||||||
type_: EventType::Normal,
|
type_: EventType::Normal,
|
||||||
reason: "GroupCreated".into(),
|
reason: "Created".into(),
|
||||||
note: Some(format!("Created group '{name}'")),
|
note: Some("Created group".into()),
|
||||||
action: "GroupCreated".into(),
|
action: "Created".into(),
|
||||||
secondary: None,
|
secondary: None,
|
||||||
},
|
},
|
||||||
&obj.object_ref(&()),
|
&obj.object_ref(&()),
|
||||||
|
@ -121,16 +117,16 @@ impl ControllerEvents for Recorder {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn user_deleted<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
async fn user_deleted<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
T: Resource<DynamicType = ()> + Sync,
|
||||||
{
|
{
|
||||||
self.publish(
|
self.publish(
|
||||||
&Event {
|
&Event {
|
||||||
type_: EventType::Normal,
|
type_: EventType::Normal,
|
||||||
reason: "UserDeleted".into(),
|
reason: "Deleted".into(),
|
||||||
note: Some(format!("Deleted user '{username}'")),
|
note: Some("Deleted user".into()),
|
||||||
action: "UserDeleted".into(),
|
action: "Deleted".into(),
|
||||||
secondary: None,
|
secondary: None,
|
||||||
},
|
},
|
||||||
&obj.object_ref(&()),
|
&obj.object_ref(&()),
|
||||||
|
@ -138,33 +134,16 @@ impl ControllerEvents for Recorder {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn group_deleted<T>(&self, obj: &T, name: &str) -> Result<(), Self::Error>
|
async fn group_deleted<T>(&self, obj: &T) -> Result<(), Self::Error>
|
||||||
where
|
where
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
T: Resource<DynamicType = ()> + Sync,
|
||||||
{
|
{
|
||||||
self.publish(
|
self.publish(
|
||||||
&Event {
|
&Event {
|
||||||
type_: EventType::Normal,
|
type_: EventType::Normal,
|
||||||
reason: "GroupDeleted".into(),
|
reason: "Deleted".into(),
|
||||||
note: Some(format!("Deleted group '{name}'")),
|
note: Some("Deleted group".into()),
|
||||||
action: "GroupDeleted".into(),
|
action: "Deleted".into(),
|
||||||
secondary: None,
|
|
||||||
},
|
|
||||||
&obj.object_ref(&()),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn user_not_found<T>(&self, obj: &T, username: &str) -> Result<(), Self::Error>
|
|
||||||
where
|
|
||||||
T: Resource<DynamicType = ()> + Sync,
|
|
||||||
{
|
|
||||||
self.publish(
|
|
||||||
&Event {
|
|
||||||
type_: EventType::Warning,
|
|
||||||
reason: "UserNotFound".into(),
|
|
||||||
note: Some(format!("User '{username}' not found")),
|
|
||||||
action: "UserNotFound".into(),
|
|
||||||
secondary: None,
|
secondary: None,
|
||||||
},
|
},
|
||||||
&obj.object_ref(&()),
|
&obj.object_ref(&()),
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl Reconcile for Group {
|
||||||
|
|
||||||
lldap_client.create_group(&name).await?;
|
lldap_client.create_group(&name).await?;
|
||||||
|
|
||||||
ctx.recorder.group_created(self.as_ref(), &name).await?;
|
ctx.recorder.group_created(self.as_ref()).await?;
|
||||||
} else {
|
} else {
|
||||||
trace!("Group already exists");
|
trace!("Group already exists");
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ impl Reconcile for Group {
|
||||||
|
|
||||||
lldap_client.delete_group(group.id).await?;
|
lldap_client.delete_group(group.id).await?;
|
||||||
|
|
||||||
ctx.recorder.group_deleted(self.as_ref(), &name).await?;
|
ctx.recorder.group_deleted(self.as_ref()).await?;
|
||||||
} else {
|
} else {
|
||||||
trace!(name, "Group does not exist")
|
trace!(name, "Group does not exist")
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ impl Reconcile for ServiceUser {
|
||||||
debug!(name, username, "Creating new user");
|
debug!(name, username, "Creating new user");
|
||||||
|
|
||||||
let user = lldap_client.create_user(&username).await?;
|
let user = lldap_client.create_user(&username).await?;
|
||||||
ctx.recorder.user_created(self.as_ref(), &username).await?;
|
ctx.recorder.user_created(self.as_ref()).await?;
|
||||||
|
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
@ -208,14 +208,11 @@ impl Reconcile for ServiceUser {
|
||||||
Err(lldap::Error::GraphQl(err))
|
Err(lldap::Error::GraphQl(err))
|
||||||
if err.message == format!("Entity not found: `No such user: '{username}'`") =>
|
if err.message == format!("Entity not found: `No such user: '{username}'`") =>
|
||||||
{
|
{
|
||||||
ctx.recorder
|
|
||||||
.user_not_found(self.as_ref(), &username)
|
|
||||||
.await?;
|
|
||||||
warn!(name, username, "User not found");
|
warn!(name, username, "User not found");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
ctx.recorder.user_deleted(self.as_ref(), &username).await?;
|
ctx.recorder.user_deleted(self.as_ref()).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
|
|
|
@ -11,11 +11,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tracing::{debug, trace, warn};
|
use tracing::{debug, trace, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{context::ControllerEvents, lldap, resources::Error};
|
||||||
context::ControllerEvents,
|
|
||||||
lldap,
|
|
||||||
resources::{Error, user_attribute},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::Reconcile;
|
use super::Reconcile;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user