k8s_openapi_ext/ext/
subject.rs

1use super::*;
2
3pub trait SubjectExt: Sized {
4    fn with_kind(name: impl ToString, kind: impl ToString) -> Self;
5    fn user(name: impl ToString) -> Self {
6        Self::with_kind(name, "User")
7    }
8    fn group(name: impl ToString) -> Self {
9        Self::with_kind(name, "Group")
10    }
11    fn service_account(account: &corev1::ServiceAccount) -> Self {
12        let name = account.metadata().name.clone().unwrap_or_default();
13        Self::with_kind(name, corev1::ServiceAccount::KIND)
14    }
15
16    fn namespace(self, namespace: impl ToString) -> Self;
17}
18
19impl SubjectExt for rbacv1::Subject {
20    fn with_kind(name: impl ToString, kind: impl ToString) -> Self {
21        let kind = kind.to_string();
22        let name = name.to_string();
23        Self {
24            kind,
25            name,
26            // api_group: todo!(),
27            // namespace: todo!(),
28            ..default()
29        }
30    }
31
32    fn namespace(self, namespace: impl ToString) -> Self {
33        let namespace = Some(namespace.to_string());
34        Self { namespace, ..self }
35    }
36}