-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsecret.rs
More file actions
45 lines (39 loc) · 1.35 KB
/
Copy pathsecret.rs
File metadata and controls
45 lines (39 loc) · 1.35 KB
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
use std::fmt::Display;
use k8s_openapi::api::core::v1::Secret;
use kube::runtime::reflector::ObjectRef;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// [`SecretReference`] represents a Kubernetes [`Secret`] reference.
///
/// In order to use this struct, the following two requirements must be met:
///
/// - Must only be used in cluster-scoped objects
/// - Namespaced objects must not be able to define cross-namespace secret
/// references
///
/// This struct is a redefinition of the one provided by k8s-openapi to make
/// name and namespace mandatory.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct SecretReference {
/// Namespace of the Secret being referred to.
pub namespace: String,
/// Name of the Secret being referred to.
pub name: String,
}
// Use ObjectRef for logging/errors
impl Display for SecretReference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
ObjectRef::<Secret>::from(self).fmt(f)
}
}
impl From<SecretReference> for ObjectRef<Secret> {
fn from(val: SecretReference) -> Self {
ObjectRef::<Secret>::from(&val)
}
}
impl From<&SecretReference> for ObjectRef<Secret> {
fn from(val: &SecretReference) -> Self {
ObjectRef::<Secret>::new(&val.name).within(&val.namespace)
}
}