-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_utils.rs
More file actions
109 lines (101 loc) · 2.91 KB
/
Copy pathtest_utils.rs
File metadata and controls
109 lines (101 loc) · 2.91 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
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
// SPDX-FileCopyrightText: Jakob Naucke <jnaucke@redhat.com>
//
// SPDX-License-Identifier: MIT
use crate::trustee;
use compute_pcrs_lib::Pcr;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::OwnerReference;
use k8s_openapi::{
api::core::v1::{ConfigMap, Secret},
jiff::Timestamp,
};
use kube::api::ObjectMeta;
use std::collections::BTreeMap;
use trusted_cluster_operator_lib::reference_values::{ImagePcr, ImagePcrs, PCR_CONFIG_FILE};
use trusted_cluster_operator_lib::{Machine, MachineSpec};
pub fn dummy_pcrs() -> ImagePcrs {
ImagePcrs(BTreeMap::from([(
"cos".to_string(),
ImagePcr {
first_seen: Timestamp::now(),
pcrs: vec![
Pcr {
id: 0,
value: "pcr0_val".to_string(),
parts: vec![],
},
Pcr {
id: 1,
value: "pcr1_val".to_string(),
parts: vec![],
},
],
reference: "ref".to_string(),
},
)]))
}
pub fn dummy_trustee_map() -> ConfigMap {
ConfigMap {
data: Some(BTreeMap::from([(
trustee::REFERENCE_VALUES_FILE.to_string(),
"[]".to_string(),
)])),
..Default::default()
}
}
pub fn dummy_trustee_auth() -> Secret {
let key_pair =
trustee::generate_ed25519_key_pair().expect("Failed to generate ed25519 key pair");
let data = BTreeMap::from([
(
trustee::TRUSTEE_AUTH_PRIV_KEY.to_string(),
k8s_openapi::ByteString(key_pair.private_key_pem),
),
(
trustee::TRUSTEE_AUTH_PUB_KEY.to_string(),
k8s_openapi::ByteString(key_pair.public_key_pem),
),
]);
Secret {
data: Some(data),
..Default::default()
}
}
pub fn dummy_pcrs_map() -> ConfigMap {
let data = BTreeMap::from([(
PCR_CONFIG_FILE.to_string(),
serde_json::to_string(&dummy_pcrs()).unwrap(),
)]);
ConfigMap {
data: Some(data),
..Default::default()
}
}
pub fn dummy_machine(id: &str) -> Machine {
Machine {
metadata: ObjectMeta {
name: Some(id.to_string()),
..Default::default()
},
spec: MachineSpec { id: id.to_string() },
status: None,
}
}
pub fn dummy_ak_secret(name: &str) -> Secret {
Secret {
metadata: ObjectMeta {
name: Some(name.to_string()),
owner_references: Some(vec![OwnerReference {
kind: "AttestationKey".to_string(),
name: name.to_string(),
uid: "ak-uid".to_string(),
..Default::default()
}]),
..Default::default()
},
data: Some(BTreeMap::from([(
"public_key".to_string(),
k8s_openapi::ByteString(b"test-ak-public-key".to_vec()),
)])),
..Default::default()
}
}