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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// @generated by tools/gen_management.py from management-registry.json and
// openapi.json. DO NOT EDIT -- your changes will be overwritten. Regenerate
// with `tools/gen_management.py`; CI verifies the committed output is current.
//! The `pgp_keys` management namespace (CONTRACT §27.1).
//!
//! OpenPGP keys used for audit signing and encrypted data export.
#![allow(clippy::too_many_arguments)]
use uuid::Uuid;
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::page::{Page, PageRequest, collect_pages};
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
/// The `pgp_keys` namespace handle.
///
/// OpenPGP keys used for audit signing and encrypted data export.
///
/// Acquiring one performs no I/O and allocates nothing meaningful (§27.2 rule
/// 1); it borrows the client and cannot outlive it.
#[derive(Clone, Copy)]
pub struct PgpKeys<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for PgpKeys<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PgpKeys")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> PgpKeys<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
/// `GET /api/v1/pgp-keys`
pub async fn list(&self, page: PageRequest) -> Result<Page<models::PgpKey>, AxiamError> {
let query = page.query();
let call = Call {
operation: "pgp_keys.list",
verb: Verb::Get,
path_template: "/api/v1/pgp-keys",
path: "/api/v1/pgp-keys".to_string(),
query: &query,
};
self.client
.management_send::<_, Page<models::PgpKey>>(call, None::<&()>)
.await
}
/// Walk `pgp_keys.list` to exhaustion, concatenating every page.
///
/// The auto-paging form §27.4 rule 4 requires. It stops on an empty page even
/// if `total` disagrees, so a misreporting server costs one wasted request
/// rather than an unbounded loop.
pub async fn list_all(&self, start: PageRequest) -> Result<Vec<models::PgpKey>, AxiamError> {
collect_pages(start, |p| self.list(p)).await
}
/// `POST /api/v1/pgp-keys`
/// **Returns secret material, once.** `private_key_armored` is returned by
/// this call and by no other; no later `get` will return it again. Discarding
/// the result destroys the credential (§27.5 rule 3).
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn generate(
&self,
body: &models::CreatePgpKeyRequest,
) -> Result<models::GeneratedPgpKey, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "pgp_keys.generate",
verb: Verb::Post,
path_template: "/api/v1/pgp-keys",
path: "/api/v1/pgp-keys".to_string(),
query: &query,
};
let wire: models::GeneratedPgpKeyWire =
self.client.management_send(call, Some(body)).await?;
Ok(models::GeneratedPgpKey::from(wire))
}
/// `GET /api/v1/pgp-keys/{id}`
pub async fn get(&self, id: Uuid) -> Result<models::PgpKey, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "pgp_keys.get",
verb: Verb::Get,
path_template: "/api/v1/pgp-keys/{id}",
path: format!("/api/v1/pgp-keys/{id}"),
query: &query,
};
self.client
.management_send::<_, models::PgpKey>(call, None::<&()>)
.await
}
/// `POST /api/v1/pgp-keys/{id}/revoke`
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn revoke(&self, id: Uuid) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "pgp_keys.revoke",
verb: Verb::Post,
path_template: "/api/v1/pgp-keys/{id}/revoke",
path: format!("/api/v1/pgp-keys/{id}/revoke"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
/// `POST /api/v1/pgp-keys/{id}/encrypt`
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn encrypt(
&self,
id: Uuid,
body: &models::EncryptRequest,
) -> Result<models::EncryptedExport, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "pgp_keys.encrypt",
verb: Verb::Post,
path_template: "/api/v1/pgp-keys/{id}/encrypt",
path: format!("/api/v1/pgp-keys/{id}/encrypt"),
query: &query,
};
self.client
.management_send::<_, models::EncryptedExport>(call, Some(body))
.await
}
/// `POST /api/v1/pgp-keys/sign-audit-batch`
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn sign_audit_batch(
&self,
body: &models::SignAuditBatchRequest,
) -> Result<models::SignedAuditBatch, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "pgp_keys.sign_audit_batch",
verb: Verb::Post,
path_template: "/api/v1/pgp-keys/sign-audit-batch",
path: "/api/v1/pgp-keys/sign-audit-batch".to_string(),
query: &query,
};
self.client
.management_send::<_, models::SignedAuditBatch>(call, Some(body))
.await
}
}