]> git.proxmox.com Git - proxmox.git/blob - src/directory.rs
755ea8c0d33b75e87e79ec79683034786583f995
[proxmox.git] / src / directory.rs
1 //! ACME Directory information.
2
3 use serde::{Deserialize, Serialize};
4
5 /// An ACME Directory. This contains the base URL and the directory data as received via a `GET`
6 /// request to the URL.
7 pub struct Directory {
8 /// The main entry point URL to the ACME directory.
9 pub url: String,
10
11 /// The json structure received via a `GET` request to the directory URL. This contains the
12 /// URLs for various API entry points.
13 pub data: DirectoryData,
14 }
15
16 /// The ACME Directory object structure.
17 ///
18 /// The data in here is typically not relevant to the user of this crate.
19 #[derive(Deserialize, Serialize)]
20 #[serde(rename_all = "camelCase")]
21 pub struct DirectoryData {
22 /// The entry point to create a new account.
23 pub new_account: String,
24
25 /// The entry point to retrieve a new nonce, should be used with a `HEAD` request.
26 pub new_nonce: String,
27
28 /// URL to post new orders to.
29 pub new_order: String,
30
31 /// URL to use for certificate revocation.
32 pub revoke_cert: String,
33
34 /// Account key rollover URL.
35 pub key_change: String,
36
37 /// Metadata object, for additional information which aren't directly part of the API
38 /// itself, such as the terms of service.
39 #[serde(skip_serializing_if = "Option::is_none")]
40 pub meta: Option<Meta>,
41 }
42
43 /// The directory's "meta" object.
44 #[derive(Clone, Debug, Deserialize, Serialize)]
45 #[serde(rename_all = "camelCase")]
46 pub struct Meta {
47 /// The terms of service. This is typically in the form of an URL.
48 #[serde(skip_serializing_if = "Option::is_none")]
49 pub terms_of_service: Option<String>,
50 }
51
52 impl Directory {
53 /// Create a `Directory` given the parsed `DirectoryData` of a `GET` request to the directory
54 /// URL.
55 pub fn from_parts(url: String, data: DirectoryData) -> Self {
56 Self { url, data }
57 }
58
59 /// Get the ToS URL.
60 pub fn terms_of_service_url(&self) -> Option<&str> {
61 match &self.data.meta {
62 Some(meta) => meta.terms_of_service.as_deref(),
63 None => None,
64 }
65 }
66
67 /// Get the "newNonce" URL. Use `HEAD` requests on this to get a new nonce.
68 pub fn new_nonce_url(&self) -> &str {
69 &self.data.new_nonce
70 }
71
72 pub(crate) fn new_account_url(&self) -> &str {
73 &self.data.new_account
74 }
75
76 pub(crate) fn new_order_url(&self) -> &str {
77 &self.data.new_order
78 }
79
80 /// Access to the in the Acme spec defined metadata structure.
81 /// Currently only contains the ToS URL already exposed via the `terms_of_service_url()`
82 /// method.
83 pub fn meta(&self) -> Option<&Meta> {
84 self.data.meta.as_ref()
85 }
86 }