1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use super::*;

pub trait ClusterRoleExt: super::ResourceBuilder {
    fn new(name: impl ToString) -> Self;

    fn aggregation_rule(self, selectors: impl IntoIterator<Item = metav1::LabelSelector>) -> Self;

    fn rules(self, rules: impl IntoIterator<Item = rbacv1::PolicyRule>) -> Self;
}

impl ClusterRoleExt for rbacv1::ClusterRole {
    fn new(name: impl ToString) -> Self {
        let metadata = metadata(name);
        Self {
            metadata,
            // aggregation_rule: todo!(),
            // rules: todo!(),
            ..default()
        }
    }

    fn aggregation_rule(self, selectors: impl IntoIterator<Item = metav1::LabelSelector>) -> Self {
        let cluster_role_selectors = Some(selectors.into_iter().collect());
        let aggregation_rule = Some(rbacv1::AggregationRule {
            cluster_role_selectors,
        });
        Self {
            aggregation_rule,
            ..self
        }
    }

    fn rules(self, rules: impl IntoIterator<Item = rbacv1::PolicyRule>) -> Self {
        let rules = Some(rules.into_iter().collect());
        Self { rules, ..self }
    }
}