Skip to content

Commit d24fd83

Browse files
Merge pull request #100 from theseus-rs/add-archive-features
feat!: add feature flags to enable zonky
2 parents 0e317fb + 36c1bf3 commit d24fd83

File tree

23 files changed

+155
-284
lines changed

23 files changed

+155
-284
lines changed

Cargo.lock

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/zonky/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ version.workspace = true
77

88
[dependencies]
99
postgresql_archive = { path = "../../postgresql_archive" }
10-
postgresql_embedded = { path = "../../postgresql_embedded" }
10+
postgresql_embedded = { path = "../../postgresql_embedded", default-features = false, features = ["zonky"] }
1111
tokio = { workspace = true, features = ["full"] }

postgresql_archive/Cargo.toml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,33 @@ version.workspace = true
1212
[dependencies]
1313
anyhow = { workspace = true }
1414
async-trait = { workspace = true }
15-
blake2 = { workspace = true }
16-
flate2 = { workspace = true }
15+
flate2 = { workspace = true, optional = true }
1716
hex = { workspace = true }
1817
http = { workspace = true }
1918
human_bytes = { workspace = true, default-features = false }
2019
lazy_static = { workspace = true }
21-
md-5 = { workspace = true }
20+
md-5 = { workspace = true, optional = true }
2221
num-format = { workspace = true }
23-
quick-xml = { workspace = true, features = ["serialize"] }
22+
quick-xml = { workspace = true, features = ["serialize"], optional = true }
2423
regex = { workspace = true }
2524
reqwest = { workspace = true, default-features = false, features = ["json"] }
2625
reqwest-middleware = { workspace = true }
2726
reqwest-retry = { workspace = true }
2827
reqwest-tracing = { workspace = true }
2928
semver = { workspace = true }
3029
serde = { workspace = true, features = ["derive"] }
31-
serde_json = { workspace = true }
32-
sha1 = { workspace = true }
33-
sha2 = { workspace = true }
34-
sha3 = { workspace = true }
35-
tar = { workspace = true }
36-
target-triple = { workspace = true }
30+
serde_json = { workspace = true, optional = true }
31+
sha1 = { workspace = true, optional = true }
32+
sha2 = { workspace = true, optional = true }
33+
tar = { workspace = true, optional = true }
34+
target-triple = { workspace = true, optional = true }
3735
tempfile = { workspace = true }
3836
thiserror = { workspace = true }
3937
tokio = { workspace = true, features = ["full"], optional = true }
4038
tracing = { workspace = true, features = ["log"] }
4139
url = { workspace = true }
42-
xz2 = { workspace = true }
43-
zip = { workspace = true }
40+
xz2 = { workspace = true, optional = true }
41+
zip = { workspace = true, optional = true }
4442

4543
[dev-dependencies]
4644
criterion = { workspace = true }
@@ -49,10 +47,39 @@ test-log = { workspace = true }
4947
tokio = { workspace = true }
5048

5149
[features]
52-
default = ["rustls-tls"]
50+
default = [
51+
"rustls-tls",
52+
"theseus",
53+
]
5354
blocking = ["dep:tokio"]
55+
github = [
56+
"dep:serde_json",
57+
]
58+
maven = [
59+
"dep:quick-xml",
60+
"md5",
61+
"sha1",
62+
"sha2",
63+
]
64+
md5 = ["dep:md-5"]
5465
native-tls = ["reqwest/native-tls"]
5566
rustls-tls = ["reqwest/rustls-tls-native-roots"]
67+
sha1 = ["dep:sha1"]
68+
sha2 = ["dep:sha2"]
69+
theseus = [
70+
"dep:flate2",
71+
"dep:tar",
72+
"dep:target-triple",
73+
"github",
74+
"sha2",
75+
]
76+
zonky = [
77+
"dep:flate2",
78+
"dep:tar",
79+
"dep:xz2",
80+
"dep:zip",
81+
"maven",
82+
]
5683

5784
[package.metadata.docs.rs]
5885
features = ["blocking"]

postgresql_archive/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ The following features are available:
5555
| `native-tls` | Enables native-tls support | No |
5656
| `rustls-tls` | Enables rustls-tls support | Yes |
5757

58+
### Configurations
59+
60+
| Name | Description | Default? |
61+
|-----------|-------------------------------------|----------|
62+
| `theseus` | Enables theseus PostgreSQL binaries | Yes |
63+
| `zonky` | Enables zonky PostgreSQL binaries | No |
64+
65+
### Hashers
66+
67+
| Name | Description | Default? |
68+
|--------|----------------------|----------|
69+
| `md5` | Enables md5 hashers | No |
70+
| `sha1` | Enables sha1 hashers | No |
71+
| `sha2` | Enables sha2 hashers | Yes¹ |
72+
73+
¹ enabled by the `theseus` feature flag.
74+
75+
### Repositories
76+
77+
| Name | Description | Default? |
78+
|----------|---------------------------|----------|
79+
| `github` | Enables github repository | Yes¹ |
80+
| `maven` | Enables maven repository | No |
81+
82+
¹ enabled by the `theseus` feature flag.
83+
5884
## Supported platforms
5985

6086
`postgresql_archive` provides implementations for the following:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#[cfg(feature = "theseus")]
12
pub mod theseus;
3+
#[cfg(feature = "zonky")]
24
pub mod zonky;

postgresql_archive/src/extractor/registry.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::configuration::{theseus, zonky};
1+
#[cfg(feature = "theseus")]
2+
use crate::configuration::theseus;
3+
#[cfg(feature = "zonky")]
4+
use crate::configuration::zonky;
25
use crate::Error::{PoisonedLock, UnsupportedExtractor};
36
use crate::Result;
47
use lazy_static::lazy_static;
@@ -63,7 +66,9 @@ impl Default for RepositoryRegistry {
6366
/// Creates a new repository registry with the default repositories registered.
6467
fn default() -> Self {
6568
let mut registry = Self::new();
69+
#[cfg(feature = "theseus")]
6670
registry.register(|url| Ok(url.starts_with(theseus::URL)), theseus::extract);
71+
#[cfg(feature = "zonky")]
6772
registry.register(|url| Ok(url.starts_with(zonky::URL)), zonky::extract);
6873
registry
6974
}
@@ -113,6 +118,7 @@ mod tests {
113118
}
114119

115120
#[test]
121+
#[cfg(feature = "theseus")]
116122
fn test_get_theseus_postgresql_binaries() {
117123
assert!(get(theseus::URL).is_ok());
118124
}

postgresql_archive/src/hasher/blake2b_512.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

postgresql_archive/src/hasher/blake2s_256.rs

Lines changed: 0 additions & 29 deletions
This file was deleted.

postgresql_archive/src/hasher/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
pub mod blake2b_512;
2-
pub mod blake2s_256;
1+
#[cfg(feature = "md5")]
32
pub mod md5;
43
pub mod registry;
4+
#[cfg(feature = "sha1")]
55
pub mod sha1;
6+
#[cfg(feature = "sha2")]
67
pub mod sha2_256;
8+
#[cfg(feature = "sha2")]
79
pub mod sha2_512;
8-
pub mod sha3_256;
9-
pub mod sha3_512;

postgresql_archive/src/hasher/registry.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
#[cfg(feature = "theseus")]
12
use crate::configuration::theseus;
2-
use crate::hasher::{md5, sha1, sha2_256, sha2_512};
3+
#[cfg(feature = "md5")]
4+
use crate::hasher::md5;
5+
#[cfg(feature = "sha1")]
6+
use crate::hasher::sha1;
7+
#[cfg(feature = "sha2")]
8+
use crate::hasher::{sha2_256, sha2_512};
9+
#[cfg(feature = "maven")]
310
use crate::repository::maven;
411
use crate::Error::{PoisonedLock, UnsupportedHasher};
512
use crate::Result;
@@ -67,23 +74,28 @@ impl Default for HasherRegistry {
6774
/// Creates a new hasher registry with the default hashers registered.
6875
fn default() -> Self {
6976
let mut registry = Self::new();
77+
#[cfg(feature = "theseus")]
7078
registry.register(
7179
|url, extension| Ok(url.starts_with(theseus::URL) && extension == "sha256"),
7280
sha2_256::hash,
7381
);
7482
// Register the Maven hashers: https://maven.apache.org/resolver/about-checksums.html#implemented-checksum-algorithms
83+
#[cfg(feature = "maven")]
7584
registry.register(
7685
|url, extension| Ok(url.starts_with(maven::URL) && extension == "md5"),
7786
md5::hash,
7887
);
88+
#[cfg(feature = "maven")]
7989
registry.register(
8090
|url, extension| Ok(url.starts_with(maven::URL) && extension == "sha1"),
8191
sha1::hash,
8292
);
93+
#[cfg(feature = "maven")]
8394
registry.register(
8495
|url, extension| Ok(url.starts_with(maven::URL) && extension == "sha256"),
8596
sha2_256::hash,
8697
);
98+
#[cfg(feature = "maven")]
8799
registry.register(
88100
|url, extension| Ok(url.starts_with(maven::URL) && extension == "sha512"),
89101
sha2_512::hash,
@@ -148,6 +160,7 @@ mod tests {
148160
}
149161

150162
#[test]
163+
#[cfg(feature = "theseus")]
151164
fn test_get_invalid_extension_error() {
152165
let error = get(theseus::URL, "foo").unwrap_err();
153166
assert_eq!(
@@ -157,12 +170,14 @@ mod tests {
157170
}
158171

159172
#[test]
173+
#[cfg(feature = "theseus")]
160174
fn test_get_theseus_postgresql_binaries() {
161175
assert!(get(theseus::URL, "sha256").is_ok());
162176
}
163177

164178
#[test]
165-
fn test_get_zonkyio_postgresql_binaries() {
179+
#[cfg(feature = "maven")]
180+
fn test_get_zonky_postgresql_binaries() {
166181
assert!(get(maven::URL, "sha512").is_ok());
167182
}
168183
}

0 commit comments

Comments
 (0)