Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chrono and time 0.3 as optional dependencies #188

Merged
merged 8 commits into from Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions .circleci/config.yml
Expand Up @@ -29,15 +29,31 @@ jobs:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: dockerfiles/bin/run_integration_tests.sh
- run: dockerfiles/bin/run_integration_tests.sh --tests
test_chrono:
docker:
- image: docker:20.10.16
steps:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: dockerfiles/bin/run_integration_tests.sh --features chrono --tests
test_time:
docker:
- image: docker:20.10.16
steps:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: dockerfiles/bin/run_integration_tests.sh --features time --tests
test_doc:
docker:
- image: docker:20.10.16
steps:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: docker run -ti --rm bollard cargo test --target x86_64-unknown-linux-gnu --doc
- run: docker run -ti --rm bollard cargo test --features time --target x86_64-unknown-linux-gnu --doc
test_clippy:
docker:
- image: docker:20.10.16
Expand All @@ -62,14 +78,16 @@ jobs:
- checkout
- setup_remote_docker
- run: docker build -t bollard .
- run: docker run -ti --rm bollard bash -c "cargo fmt -- --check --verbose"
- run: docker run -ti --rm bollard bash -c "rustup component add rustfmt && cargo fmt -- --check --verbose"
workflows:
version: 2
test-image:
jobs:
- test_ssl
- test_http
- test_unix
- test_chrono
- test_time
- test_doc
- test_clippy
- test_audit
Expand Down
3 changes: 2 additions & 1 deletion .dockerignore
@@ -1,7 +1,8 @@
.DS_Store
.git
Cargo.lock
**/target
/target
/codegen/target/generated-sources/target
doc
main.rs
**/workspace
Expand Down
9 changes: 6 additions & 3 deletions Cargo.toml
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/fussybeaver/bollard"
documentation = "https://docs.rs/bollard"
readme = "README.md"
keywords = ["docker"]
edition = "2018"
edition = "2021"

[features]
# Enable tests specifically for the http connector
Expand All @@ -21,12 +21,14 @@ test_macos = []
# Enable rustls / ssl
ssl = ["dirs-next", "hyper-rustls", "rustls", "rustls-native-certs", "rustls-pemfile", "webpki", "webpki-roots"]
ct_logs = ["ssl", "ct-logs"]
chrono = ["dep:chrono", "bollard-stubs/chrono"]
time = ["dep:time", "bollard-stubs/time"]

[dependencies]
base64 = "0.13"
bollard-stubs = { version = "=1.42.0-rc.2" }
bollard-stubs = { version = "=1.42.0-rc.3", default-features = false }
bytes = "1"
chrono = { version = "0.4", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"], optional = true }
ct-logs = { version = "0.9.0", optional = true }
dirs-next = { version = "2.0", optional = true }
futures-core = "0.3"
Expand All @@ -46,6 +48,7 @@ serde_json = "1.0"
serde_urlencoded = "0.7"
tokio = { version = "1.7", features = ["time", "net", "io-util"] }
thiserror = "1.0"
time = { version = "0.3", features = ["formatting", "parsing"], optional = true }
tokio-util = { version = "0.7", features = ["codec"] }
url = "2.2"
webpki-roots = { version = "0.22", optional = true }
Expand Down
10 changes: 3 additions & 7 deletions Dockerfile
@@ -1,11 +1,7 @@
FROM ekidd/rust-musl-builder:stable AS builder
FROM rust:1.61.0-buster

WORKDIR /tmp/bollard
WORKDIR /usr/src/bollard

COPY . ./

RUN sudo chown -R rust:rust /tmp/bollard \
&& sudo groupadd --gid 999 docker \
&& sudo usermod -a -G docker rust
COPY . .

RUN cargo build
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -40,4 +40,4 @@ test_script:
- ps: Set-Item -path env:RUST_BACKTRACE -value 1
- ps: Set-Item -path env:RUST_LOG -value "hyper=trace,bollard=debug"
- ps: Set-Item -path env:REGISTRY_HTTP_ADDR -value localhost:5000
- cargo test --verbose -- --nocapture --test-threads 1
- cargo test --verbose --tests -- --nocapture --test-threads 1
2 changes: 1 addition & 1 deletion codegen/pom.xml
Expand Up @@ -31,7 +31,7 @@
<supportingFilesToGenerate>models.rs,lib.rs,Cargo.toml,config,README.md</supportingFilesToGenerate>
<configOptions>
<packageName>bollard-stubs</packageName>
<packageVersion>1.42.0-rc.2</packageVersion>
<packageVersion>1.42.0-rc.3</packageVersion>
</configOptions>
</configuration>
</execution>
Expand Down
6 changes: 4 additions & 2 deletions codegen/src/main/java/bollard/BollardCodegen.java
Expand Up @@ -22,6 +22,7 @@ public class BollardCodegen extends RustServerCodegen {

public BollardCodegen() {
super();
typeMapping.put("DateTime", "BollardDate");
}

// Declare custom additions to inline enums that are behaving differently
Expand Down Expand Up @@ -123,9 +124,10 @@ public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
} else if (prop.name.equals("_type")) {
prop.name = "typ";
}
if (prop.dataFormat != null && prop.dataFormat.equals("dateTime")) {
if (prop.dataFormat != null && (prop.dataFormat.equals("dateTime") || prop.datatype.equals("BollardDate"))) {
// set DateTime format on properties where appropriate
prop.datatype = "DateTime<Utc>";
prop.vendorExtensions.put("x-rustgen-is-datetime", true);
prop.datatype = "BollardDate";
}
if (prop.isEnum) {
if (enumToString.contains(model.classname)) {
Expand Down
5 changes: 3 additions & 2 deletions codegen/src/main/resources/bollard/Cargo.mustache
Expand Up @@ -4,10 +4,11 @@ version = "{{appVersion}}"
authors = [ "Bollard contributors" ]
description = "Stubs used for the Bollard rust async Docker client API"
license = "Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"], optional = true }
serde = { version = "1.0", features = ["derive"] }
time = { version = "0.3", features = ["formatting", "parsing"], optional = true }

serde_with = "1.4"
55 changes: 50 additions & 5 deletions codegen/src/main/resources/bollard/models.mustache
Expand Up @@ -9,9 +9,6 @@ use std::collections::HashMap;
use std::default::Default;
use std::hash::Hash;

use chrono::DateTime;
use chrono::Utc;

fn deserialize_nonoptional_vec<'de, D: Deserializer<'de>, T: DeserializeOwned>(
d: D,
) -> Result<Vec<T>, D::Error> {
Expand All @@ -24,6 +21,52 @@ fn deserialize_nonoptional_map<'de, D: Deserializer<'de>, T: DeserializeOwned>(
serde::Deserialize::deserialize(d).map(|x: Option<_>| x.unwrap_or(HashMap::new()))
}

#[cfg(feature = "time")]
pub type BollardDate = time::OffsetDateTime;
#[cfg(feature = "chrono")]
pub type BollardDate = chrono::DateTime<chrono::Utc>;
#[cfg(not(any(feature = "chrono", feature = "time")))]
pub type BollardDate = String;

#[cfg(feature = "time")]
fn deserialize_timestamp<'de, D: Deserializer<'de>>(
d: D
) -> Result<Option<BollardDate>, D::Error> {
let opt: Option<String> = serde::Deserialize::deserialize(d)?;
if let Some(s) = opt {
Ok(Some(
time::OffsetDateTime::parse(&s, &time::format_description::well_known::Rfc3339)
.map_err(|e| serde::de::Error::custom(format!("{:?}", e)))?,
))
} else {
Ok(None)
}
}

#[cfg(not(feature = "time"))]
fn deserialize_timestamp<'de, D: Deserializer<'de>>(
d: D
) -> Result<Option<BollardDate>, D::Error> {
serde::Deserialize::deserialize(d)
}

#[cfg(feature = "time")]
fn serialize_timestamp<S: Serializer>(date: &Option<BollardDate>, s: S) -> Result<S::Ok, S::Error> {
match date {
Some(inner) => Ok(s.serialize_str(&inner.format(&time::format_description::well_known::Rfc3339)
.map_err(|e| serde::ser::Error::custom(format!("{:?}", e)))?)?),
None => Ok(s.serialize_str("")?)
}
}

#[cfg(not(feature = "time"))]
fn serialize_timestamp<S: Serializer>(date: &Option<BollardDate>, s: S) -> Result<S::Ok, S::Error> {
match date {
Some(inner) => s.serialize_some(inner),
None => s.serialize_none()
}
}

{{#models}}{{#model}}
{{#description}}/// {{{description}}}
{{/description}}{{#isEnum}}/// Enumeration of values.
Expand Down Expand Up @@ -68,10 +111,12 @@ pub struct {{classname}} {
#[serde(deserialize_with = "deserialize_nonoptional_map")]{{/isListContainer}}{{#isListContainer}}
#[serde(deserialize_with = "deserialize_nonoptional_vec")]{{/isListContainer}}{{/isContainer}}{{#isEnum}}
#[serde(skip_serializing_if="Option::is_none")]
#[serde(with = "serde_with::rust::string_empty_as_none")]{{/isEnum}}
#[serde(with = "serde_with::rust::string_empty_as_none")]{{/isEnum}}{{#vendorExtensions.x-rustgen-is-datetime}}
#[serde(default, deserialize_with = "deserialize_timestamp", serialize_with = "serialize_timestamp")]{{/vendorExtensions.x-rustgen-is-datetime}}
pub {{name}}: {{#isEnum}}Option<{{classname}}{{enumName}}>{{/isEnum}}{{^isEnum}}{{#isListContainer}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/isListContainer}}{{^isListContainer}}{{#isContainer}}HashMap<String, {{#items}}{{{datatype}}}{{/items}}>{{/isContainer}}{{^isContainer}}{{{datatype}}}{{/isContainer}}{{/isListContainer}}{{/isEnum}}{{#vendorExtensions}}{{/vendorExtensions}},
{{/required}}{{^required}}
#[serde(skip_serializing_if="Option::is_none")]
#[serde(skip_serializing_if="Option::is_none")]{{#vendorExtensions.x-rustgen-is-datetime}}
#[serde(default, deserialize_with = "deserialize_timestamp", serialize_with = "serialize_timestamp")]{{/vendorExtensions.x-rustgen-is-datetime}}
pub {{name}}: Option<{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{#isListContainer}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/isListContainer}}{{^isListContainer}}{{#isContainer}}HashMap<String, {{#items}}{{{datatype}}}{{/items}}>{{/isContainer}}{{^isContainer}}{{{datatype}}}{{/isContainer}}{{/isListContainer}}{{/isEnum}}{{#vendorExtensions}}{{/vendorExtensions}}>,
{{/required}}

Expand Down
7 changes: 4 additions & 3 deletions codegen/target/generated-sources/Cargo.toml
@@ -1,13 +1,14 @@
[package]
name = "bollard-stubs"
version = "1.42.0-rc.2"
version = "1.42.0-rc.3"
authors = [ "Bollard contributors" ]
description = "Stubs used for the Bollard rust async Docker client API"
license = "Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"], optional = true }
serde = { version = "1.0", features = ["derive"] }
time = { version = "0.3", features = ["formatting", "parsing"], optional = true }

serde_with = "1.4"
6 changes: 3 additions & 3 deletions codegen/target/generated-sources/README.md
Expand Up @@ -7,9 +7,9 @@ To see how to make this your own, look here:

[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)

- API version: 1.42.0-rc.2
- Code generation suffix: 1.42.0-rc.2
- Build date: 2022-05-31T18:04:02.348+01:00
- API version: 1.42.0-rc.3
- Code generation suffix: 1.42.0-rc.3
- Build date: 2022-06-18T09:45:11.451+01:00

This autogenerated project defines an API crate `bollard-stubs` which contains:
* Data types representing the underlying data model.
Expand Down