statehub_k8s_helper/ext/
subject.rs

1//
2// Copyright (c) 2021 RepliXio Ltd. All rights reserved.
3// Use is subject to license terms.
4//
5
6use super::*;
7
8pub trait SubjectExt: Sized {
9    fn with_kind(name: impl ToString, kind: impl ToString) -> Self;
10    fn user(name: impl ToString) -> Self {
11        Self::with_kind(name, "User")
12    }
13    fn group(name: impl ToString) -> Self {
14        Self::with_kind(name, "Group")
15    }
16    fn service_account(name: impl ToString) -> Self {
17        Self::with_kind(name, "ServiceAccount")
18    }
19    #[must_use]
20    fn namespace(self, namespace: impl ToString) -> Self;
21}
22
23impl SubjectExt for rbacv1::Subject {
24    fn with_kind(name: impl ToString, kind: impl ToString) -> Self {
25        let kind = kind.to_string();
26        let name = name.to_string();
27        Self {
28            kind,
29            name,
30            // api_group: todo!(),
31            // namespace: todo!(),
32            ..Self::default()
33        }
34    }
35
36    fn namespace(self, namespace: impl ToString) -> Self {
37        let namespace = Some(namespace.to_string());
38        Self { namespace, ..self }
39    }
40}