Skip to content

Commit

Permalink
feat!: add feature flags to enable zonky
Browse files Browse the repository at this point in the history
  • Loading branch information
brianheineman committed Jul 3, 2024
1 parent 0e317fb commit 36c1bf3
Show file tree
Hide file tree
Showing 23 changed files with 155 additions and 284 deletions.
30 changes: 0 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/zonky/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ version.workspace = true

[dependencies]
postgresql_archive = { path = "../../postgresql_archive" }
postgresql_embedded = { path = "../../postgresql_embedded" }
postgresql_embedded = { path = "../../postgresql_embedded", default-features = false, features = ["zonky"] }
tokio = { workspace = true, features = ["full"] }
53 changes: 40 additions & 13 deletions postgresql_archive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,33 @@ version.workspace = true
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
blake2 = { workspace = true }
flate2 = { workspace = true }
flate2 = { workspace = true, optional = true }
hex = { workspace = true }
http = { workspace = true }
human_bytes = { workspace = true, default-features = false }
lazy_static = { workspace = true }
md-5 = { workspace = true }
md-5 = { workspace = true, optional = true }
num-format = { workspace = true }
quick-xml = { workspace = true, features = ["serialize"] }
quick-xml = { workspace = true, features = ["serialize"], optional = true }
regex = { workspace = true }
reqwest = { workspace = true, default-features = false, features = ["json"] }
reqwest-middleware = { workspace = true }
reqwest-retry = { workspace = true }
reqwest-tracing = { workspace = true }
semver = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sha1 = { workspace = true }
sha2 = { workspace = true }
sha3 = { workspace = true }
tar = { workspace = true }
target-triple = { workspace = true }
serde_json = { workspace = true, optional = true }
sha1 = { workspace = true, optional = true }
sha2 = { workspace = true, optional = true }
tar = { workspace = true, optional = true }
target-triple = { workspace = true, optional = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"], optional = true }
tracing = { workspace = true, features = ["log"] }
url = { workspace = true }
xz2 = { workspace = true }
zip = { workspace = true }
xz2 = { workspace = true, optional = true }
zip = { workspace = true, optional = true }

[dev-dependencies]
criterion = { workspace = true }
Expand All @@ -49,10 +47,39 @@ test-log = { workspace = true }
tokio = { workspace = true }

[features]
default = ["rustls-tls"]
default = [
"rustls-tls",
"theseus",
]
blocking = ["dep:tokio"]
github = [
"dep:serde_json",
]
maven = [
"dep:quick-xml",
"md5",
"sha1",
"sha2",
]
md5 = ["dep:md-5"]
native-tls = ["reqwest/native-tls"]
rustls-tls = ["reqwest/rustls-tls-native-roots"]
sha1 = ["dep:sha1"]
sha2 = ["dep:sha2"]
theseus = [
"dep:flate2",
"dep:tar",
"dep:target-triple",
"github",
"sha2",
]
zonky = [
"dep:flate2",
"dep:tar",
"dep:xz2",
"dep:zip",
"maven",
]

[package.metadata.docs.rs]
features = ["blocking"]
Expand Down
26 changes: 26 additions & 0 deletions postgresql_archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ The following features are available:
| `native-tls` | Enables native-tls support | No |
| `rustls-tls` | Enables rustls-tls support | Yes |

### Configurations

| Name | Description | Default? |
|-----------|-------------------------------------|----------|
| `theseus` | Enables theseus PostgreSQL binaries | Yes |
| `zonky` | Enables zonky PostgreSQL binaries | No |

### Hashers

| Name | Description | Default? |
|--------|----------------------|----------|
| `md5` | Enables md5 hashers | No |
| `sha1` | Enables sha1 hashers | No |
| `sha2` | Enables sha2 hashers | Yes¹ |

¹ enabled by the `theseus` feature flag.

### Repositories

| Name | Description | Default? |
|----------|---------------------------|----------|
| `github` | Enables github repository | Yes¹ |
| `maven` | Enables maven repository | No |

¹ enabled by the `theseus` feature flag.

## Supported platforms

`postgresql_archive` provides implementations for the following:
Expand Down
2 changes: 2 additions & 0 deletions postgresql_archive/src/configuration/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(feature = "theseus")]
pub mod theseus;
#[cfg(feature = "zonky")]
pub mod zonky;
8 changes: 7 additions & 1 deletion postgresql_archive/src/extractor/registry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::configuration::{theseus, zonky};
#[cfg(feature = "theseus")]
use crate::configuration::theseus;
#[cfg(feature = "zonky")]
use crate::configuration::zonky;
use crate::Error::{PoisonedLock, UnsupportedExtractor};
use crate::Result;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -63,7 +66,9 @@ impl Default for RepositoryRegistry {
/// Creates a new repository registry with the default repositories registered.
fn default() -> Self {
let mut registry = Self::new();
#[cfg(feature = "theseus")]
registry.register(|url| Ok(url.starts_with(theseus::URL)), theseus::extract);
#[cfg(feature = "zonky")]
registry.register(|url| Ok(url.starts_with(zonky::URL)), zonky::extract);
registry
}
Expand Down Expand Up @@ -113,6 +118,7 @@ mod tests {
}

#[test]
#[cfg(feature = "theseus")]
fn test_get_theseus_postgresql_binaries() {
assert!(get(theseus::URL).is_ok());
}
Expand Down
29 changes: 0 additions & 29 deletions postgresql_archive/src/hasher/blake2b_512.rs

This file was deleted.

29 changes: 0 additions & 29 deletions postgresql_archive/src/hasher/blake2s_256.rs

This file was deleted.

8 changes: 4 additions & 4 deletions postgresql_archive/src/hasher/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod blake2b_512;
pub mod blake2s_256;
#[cfg(feature = "md5")]
pub mod md5;
pub mod registry;
#[cfg(feature = "sha1")]
pub mod sha1;
#[cfg(feature = "sha2")]
pub mod sha2_256;
#[cfg(feature = "sha2")]
pub mod sha2_512;
pub mod sha3_256;
pub mod sha3_512;
19 changes: 17 additions & 2 deletions postgresql_archive/src/hasher/registry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#[cfg(feature = "theseus")]
use crate::configuration::theseus;
use crate::hasher::{md5, sha1, sha2_256, sha2_512};
#[cfg(feature = "md5")]
use crate::hasher::md5;
#[cfg(feature = "sha1")]
use crate::hasher::sha1;
#[cfg(feature = "sha2")]
use crate::hasher::{sha2_256, sha2_512};
#[cfg(feature = "maven")]
use crate::repository::maven;
use crate::Error::{PoisonedLock, UnsupportedHasher};
use crate::Result;
Expand Down Expand Up @@ -67,23 +74,28 @@ impl Default for HasherRegistry {
/// Creates a new hasher registry with the default hashers registered.
fn default() -> Self {
let mut registry = Self::new();
#[cfg(feature = "theseus")]
registry.register(
|url, extension| Ok(url.starts_with(theseus::URL) && extension == "sha256"),
sha2_256::hash,
);
// Register the Maven hashers: https://maven.apache.org/resolver/about-checksums.html#implemented-checksum-algorithms
#[cfg(feature = "maven")]
registry.register(
|url, extension| Ok(url.starts_with(maven::URL) && extension == "md5"),
md5::hash,
);
#[cfg(feature = "maven")]
registry.register(
|url, extension| Ok(url.starts_with(maven::URL) && extension == "sha1"),
sha1::hash,
);
#[cfg(feature = "maven")]
registry.register(
|url, extension| Ok(url.starts_with(maven::URL) && extension == "sha256"),
sha2_256::hash,
);
#[cfg(feature = "maven")]
registry.register(
|url, extension| Ok(url.starts_with(maven::URL) && extension == "sha512"),
sha2_512::hash,
Expand Down Expand Up @@ -148,6 +160,7 @@ mod tests {
}

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

#[test]
#[cfg(feature = "theseus")]
fn test_get_theseus_postgresql_binaries() {
assert!(get(theseus::URL, "sha256").is_ok());
}

#[test]
fn test_get_zonkyio_postgresql_binaries() {
#[cfg(feature = "maven")]
fn test_get_zonky_postgresql_binaries() {
assert!(get(maven::URL, "sha512").is_ok());
}
}
29 changes: 0 additions & 29 deletions postgresql_archive/src/hasher/sha3_256.rs

This file was deleted.

Loading

0 comments on commit 36c1bf3

Please sign in to comment.