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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use crate::{gvk::GroupVersionKind, resource::Resource};
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub struct ApiResource {
pub group: String,
pub version: String,
pub api_version: String,
pub kind: String,
pub plural: String,
}
impl ApiResource {
pub fn erase<K: Resource>(dt: &K::DynamicType) -> Self {
ApiResource {
group: K::group(dt).to_string(),
version: K::version(dt).to_string(),
api_version: K::api_version(dt).to_string(),
kind: K::kind(dt).to_string(),
plural: K::plural(dt).to_string(),
}
}
pub fn from_gvk_with_plural(gvk: &GroupVersionKind, plural: &str) -> Self {
ApiResource {
api_version: gvk.api_version(),
group: gvk.group.clone(),
version: gvk.version.clone(),
kind: gvk.kind.clone(),
plural: plural.to_string(),
}
}
pub fn from_gvk(gvk: &GroupVersionKind) -> Self {
ApiResource::from_gvk_with_plural(gvk, &crate::resource::to_plural(&gvk.kind.to_ascii_lowercase()))
}
}
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum Scope {
Cluster,
Namespaced,
}
pub mod verbs {
pub const CREATE: &str = "create";
pub const GET: &str = "get";
pub const LIST: &str = "list";
pub const WATCH: &str = "watch";
pub const DELETE: &str = "delete";
pub const DELETE_COLLECTION: &str = "deletecollection";
pub const UPDATE: &str = "update";
pub const PATCH: &str = "patch";
}
#[derive(Debug, Clone)]
pub struct ApiCapabilities {
pub scope: Scope,
pub subresources: Vec<(ApiResource, ApiCapabilities)>,
pub operations: Vec<String>,
}
impl ApiCapabilities {
pub fn supports_operation(&self, operation: &str) -> bool {
self.operations.iter().any(|op| op == operation)
}
}