-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlib.rs
73 lines (67 loc) · 1.85 KB
/
lib.rs
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
// Copyright 2022 Oxide Computer Company
use base64::{engine, Engine};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use uuid::Uuid;
#[allow(clippy::large_enum_variant)]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum VolumeConstructionRequest {
Volume {
id: Uuid,
block_size: u64,
sub_volumes: Vec<VolumeConstructionRequest>,
read_only_parent: Option<Box<VolumeConstructionRequest>>,
},
Url {
id: Uuid,
block_size: u64,
url: String,
},
Region {
block_size: u64,
blocks_per_extent: u64,
extent_count: u32,
opts: CrucibleOpts,
gen: u64,
},
File {
id: Uuid,
block_size: u64,
path: String,
},
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq,
)]
pub struct CrucibleOpts {
pub id: Uuid,
pub target: Vec<SocketAddr>,
pub lossy: bool,
pub flush_timeout: Option<f32>,
pub key: Option<String>,
pub cert_pem: Option<String>,
pub key_pem: Option<String>,
pub root_cert_pem: Option<String>,
pub control: Option<SocketAddr>,
pub read_only: bool,
}
impl CrucibleOpts {
pub fn key_bytes(&self) -> Option<Vec<u8>> {
if let Some(key) = &self.key {
// For xts, key size must be 32 bytes
let decoded_key = engine::general_purpose::STANDARD
.decode(key)
.expect("could not base64 decode key!");
if decoded_key.len() != 32 {
panic!("Key length must be 32 bytes!");
}
Some(decoded_key)
} else {
None
}
}
}