diff --git a/.hooks/pre-commit b/.hooks/pre-commit index 709fb95..825db47 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -6,12 +6,12 @@ make lint &> /dev/null 2>&1 || { exit 1; } -# branch=`git rev-parse --abbrev-ref HEAD` +branch=`git rev-parse --abbrev-ref HEAD` -# # TODO should we add release branches here as well? -# if [[ "$branch" =~ ^master|develop$ ]]; then -# make test > /dev/null 2>&1 || { -# >&2 echo "Tests failed. check 'make test' for more info."; -# exit 1; -# } -# fi +# TODO should we add release branches here as well? +if [[ "$branch" =~ ^master|develop$ ]]; then + make test > /dev/null 2>&1 || { + >&2 echo "Tests failed. check 'make test' for more info."; + exit 1; + } +fi diff --git a/Cargo.lock b/Cargo.lock index 0606bc8..532c627 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "const_fn" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28" +checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" [[package]] name = "cookie" @@ -347,7 +347,7 @@ dependencies = [ [[package]] name = "fej" -version = "1.0.0" +version = "0.1.0" dependencies = [ "chrono", "chrono-tz", @@ -438,42 +438,42 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures-channel" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" +checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" +checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" [[package]] name = "futures-io" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" +checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" [[package]] name = "futures-sink" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" +checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" [[package]] name = "futures-task" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" +checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" [[package]] name = "futures-util" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" +checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ "futures-core", "futures-io", @@ -523,9 +523,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc018e188373e2777d0ef2467ebff62a08e66c3f5857b23c8fbec3018210dc00" +checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" dependencies = [ "bytes", "fnv", @@ -577,9 +577,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.4" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ "bytes", "fnv", @@ -599,9 +599,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.6" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -630,9 +630,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.5" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ "bytes", "futures-channel", @@ -659,7 +659,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", - "hyper 0.14.5", + "hyper 0.14.4", "native-tls", "tokio", "tokio-native-tls", @@ -740,9 +740,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.50" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" +checksum = "dc15e39392125075f60c95ba416f5381ff6c3a948ff02ab12464715adf56c821" dependencies = [ "wasm-bindgen", ] @@ -777,9 +777,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.93" +version = "0.2.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" +checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" [[package]] name = "log" @@ -1066,22 +1066,22 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.6" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.6" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.69", + "syn 1.0.64", ] [[package]] @@ -1136,9 +1136,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid 0.2.1", ] @@ -1168,7 +1168,7 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", ] [[package]] @@ -1248,9 +1248,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.3" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" +checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" dependencies = [ "base64 0.13.0", "bytes", @@ -1261,7 +1261,7 @@ dependencies = [ "futures-util", "http", "http-body", - "hyper 0.14.5", + "hyper 0.14.4", "hyper-tls", "ipnet", "js-sys", @@ -1392,9 +1392,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.2.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ "bitflags", "core-foundation", @@ -1405,9 +1405,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.2.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339" +checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" dependencies = [ "core-foundation-sys", "libc", @@ -1443,9 +1443,9 @@ version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.69", + "syn 1.0.64", ] [[package]] @@ -1504,10 +1504,11 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "socket2" -version = "0.4.0" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ + "cfg-if 1.0.0", "libc", "winapi 0.3.9", ] @@ -1547,11 +1548,11 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", "serde", "serde_derive", - "syn 1.0.69", + "syn 1.0.64", ] [[package]] @@ -1561,13 +1562,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" dependencies = [ "base-x", - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", "serde", "serde_derive", "serde_json", "sha1", - "syn 1.0.69", + "syn 1.0.64", ] [[package]] @@ -1595,11 +1596,11 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.69" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", "unicode-xid 0.2.1", ] @@ -1661,17 +1662,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", "standback", - "syn 1.0.69", + "syn 1.0.64", ] [[package]] name = "tinyvec" -version = "1.2.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -1684,9 +1685,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.5.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" +checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" dependencies = [ "autocfg", "bytes", @@ -1709,9 +1710,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.6" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" +checksum = "5143d049e85af7fbc36f5454d990e62c2df705b3589f123b71f441b6b59f443f" dependencies = [ "bytes", "futures-core", @@ -1791,9 +1792,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.5" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" dependencies = [ "matches", ] @@ -1899,9 +1900,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.73" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" +checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe" dependencies = [ "cfg-if 1.0.0", "serde", @@ -1911,24 +1912,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.73" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" +checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3" dependencies = [ "bumpalo", "lazy_static", "log 0.4.14", - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.69", + "syn 1.0.64", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.23" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" +checksum = "73157efb9af26fb564bb59a009afd1c7c334a44db171d280690d0c3faaec3468" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -1938,9 +1939,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.73" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" +checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b" dependencies = [ "quote 1.0.9", "wasm-bindgen-macro-support", @@ -1948,28 +1949,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.73" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" +checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d" dependencies = [ - "proc-macro2 1.0.26", + "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.69", + "syn 1.0.64", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.73" +version = "0.2.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" +checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa" [[package]] name = "web-sys" -version = "0.3.50" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" +checksum = "59fe19d70f5dacc03f6e46777213facae5ac3801575d56ca6cbd4c93dcd12310" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 12add75..97796ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fej" -version = "1.0.0" +version = "0.1.0" authors = ["Jef Roosens "] edition = "2018" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c54bb86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# syntax = docker/dockerfile:1.2 + +# We use a multi-stage build to end up with a very small final image +FROM alpine:latest AS builder + +ENV PATH "$PATH:/root/.cargo/bin" + +WORKDIR /usr/src/app + +# Install build dependencies, rustup & rust's nightly build & toolchain +RUN apk update && apk add --no-cache openssl-dev build-base curl && \ + { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; } + +# Copy source code over to builder +COPY Cargo.toml Cargo.lock ./ +COPY src/ ./src/ + +# Run the tests, don't want no broken docker image +# And then finally, build the project +# Thank the lords that this article exists +# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172 +# TODO add what these flags do & why they work +# NOTE: cargo install auto-appends bin to the path +RUN --mount=type=cache,target=/usr/src/app/target RUSTFLAGS="-C target-feature=-crt-static" cargo test && \ + RUSTFLAGS="-C target-feature=-crt-static" cargo install --path . --bin fej --root /usr/local + + +# Now, we create the actual image +FROM alpine:latest + +# Install some dynamic libraries needed for everything to work +RUN apk update && apk add --no-cache openssl libgcc + +# Copy binary over to final image +COPY --from=builder /usr/local/bin/fej /usr/local/bin/fej + +CMD ["/usr/local/bin/fej"] diff --git a/LICENSE b/LICENSE index 0ad25db..f288702 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies @@ -7,15 +7,17 @@ Preamble - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. + The GNU General Public License is a free, copyleft license for +software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to +the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you @@ -24,34 +26,44 @@ them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. @@ -60,7 +72,7 @@ modification follow. 0. Definitions. - "This License" refers to version 3 of the GNU Affero General Public License. + "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. @@ -537,45 +549,35 @@ to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. + 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single +under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General +Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published +GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's +versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. @@ -633,29 +635,40 @@ the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Affero General Public License + You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see +For more information on this, and how to apply and follow the GNU GPL, see . + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Makefile b/Makefile index f7eaa8e..ab50282 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,35 @@ +IMAGE := chewingbever/fej + + all: debug .PHONY: all # Builds debug: - @ ./build -m dev -a run build + @ cargo build .PHONY: debug release: - @ ./build -m rel + @ cargo build --release .PHONY: release +image: Dockerfile + @ ./build '$(IMAGE)' +.PHONY: image + push: - @ ./build -m prod -a push + @ ./build '$(IMAGE)' push .PHONY: push # Run run: - @ ./build -m dev -a run + @ RUST_BACKTRACE=1 cargo run --bin fej .PHONY: run -stop: - @ docker stop -t 2 fej -.PHONY: stop - -logs: - @ docker logs -f fej -.PHONY: logs - # Testing test: - @ ./build -m dev -a run -l -- test --no-fail-fast + @ cargo test --no-fail-fast .PHONY: test format: diff --git a/build b/build index d7d86a3..8abbc39 100755 --- a/build +++ b/build @@ -1,27 +1,18 @@ #!/usr/bin/env bash -image="chewingbever/fej" -# Should be either dev or rel -mode="dev" -action="" -attach="--detach" - -while getopts ":i:m:a:l" c; do - case $c in - i ) image="$OPTARG" ;; - m ) mode="$OPTARG" ;; - a ) action="$OPTARG" ;; - l ) attach="" ;; - ? ) exit 1 ;; - esac -done -shift $((OPTIND-1)) +# Simple guard to check input args +[[ $# -eq 1 ]] || [[ $# -eq 2 ]] || { + >&2 echo "Usage: ./build IMAGE [ACTION]" + exit 1 +} # Extract current version from Cargo.toml & get current branch -patch_version=`grep -Po '(?<=version = ").*(?=")' Cargo.toml | head -n1` -major_version=`echo "$patch_version" | sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/'` -minor_version=`echo "$patch_version" | sed -E 's/([0-9]+).([0-9]+).([0-9]+)/\1.\2/'` -branch=`git rev-parse --abbrev-ref HEAD` +patch_version="$(grep -Po '(?<=version = ").*(?=")' Cargo.toml | head -n1)" +major_version="$(echo "$patch_version" | + sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\1/')" +minor_version="$(echo "$patch_version" | + sed -E 's/([0-9]+).([0-9]+).([0-9]+)/\1.\2/')" +branch="$(git branch --show-current)" if [[ "$branch" = "master" ]]; then tags=("$patch_version" "$minor_version" "$major_version" "latest") @@ -34,58 +25,31 @@ else fi -# First, we build the builder -DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile.builder -t "$image-builder:latest" . - # Run the actual build command -if [ "$mode" = "rel" ]; then - DOCKER_BUILDKIT=1 docker build -t "$image:$tags" -f docker/Dockerfile.rel . +DOCKER_BUILDKIT=1 docker build -t "$1:$tags" . -elif [[ "$mode" = "dev" ]]; then - DOCKER_BUILDKIT=1 docker build -t "$image-dev:$tags" -f docker/Dockerfile.dev . - -else - >&2 echo "Invalid mode." - exit 1 - -fi - -if [[ "$action" = push ]]; then +if [[ "$2" = push ]]; then [[ "$branch" =~ ^develop|master$ ]] || { >&2 echo "You can only push from develop or master." exit 2 } - [[ "$mode" = "rel" ]] || { - >&2 echo "You can only push release builds." - exit 3 - } - for tag in "${tags[@]}"; do # Create the tag - docker tag "$image:$tags" "$image:$tag" + docker tag "$1:$tags" "$1:$tag" # Push the tag - docker push "$image:$tag" + docker push "$1:$tag" # Remove the tag again, if it's not the main tag - [[ "$tag" != "$tags" ]] && docker rmi "$image:$tag" + [[ "$tag" != "$tags" ]] && docker rmi "$1:$tag" done - elif [[ "$action" = run ]]; then - if [[ "$mode" = "dev" ]]; then - # Create caching volumes if needed (they need to be named) - docker volume create fej_build-cache - docker volume create fej_registry-cache - - flags="-v fej_build-cache:/usr/src/app/target -v fej_registry-cache:/root/.cargo/registry" - fi - - docker run $attach $flags \ + elif [[ "$2" = run ]]; then + docker run \ --rm \ --interactive \ --tty \ --publish 8000:8000 \ - --name fej \ - "$image$([[ "$mode" != "rel" ]] && echo "-dev"):$tags" "$@" + "$1:$tags" fi diff --git a/docker/Dockerfile.builder b/docker/Dockerfile.builder deleted file mode 100644 index b968c5b..0000000 --- a/docker/Dockerfile.builder +++ /dev/null @@ -1,18 +0,0 @@ -# Our entire toolchain runs in alpine -FROM alpine:latest AS builder - -ENV PATH "$PATH:/root/.cargo/bin" -# Needed for proper compiling of openssl-dev -ENV RUSTFLAGS "-C target-feature=-crt-static" -# Otherwise, the debug build can't be used from the container -ENV ROCKET_ADDRESS "0.0.0.0" - -WORKDIR /usr/src/app - -# Install build dependencies, rustup & rust's nightly build & toolchain -RUN apk update && apk add --no-cache openssl-dev build-base curl && \ - { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; } - -# Copy source code over to builder -COPY Cargo.toml Cargo.lock ./ -COPY src/ ./src/ diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev deleted file mode 100644 index 9205fd4..0000000 --- a/docker/Dockerfile.dev +++ /dev/null @@ -1,6 +0,0 @@ -FROM chewingbever/fej-builder:latest - -ENV RUST_BACKTRACE 1 - -ENTRYPOINT ["cargo"] -CMD ["run"] diff --git a/docker/Dockerfile.rel b/docker/Dockerfile.rel deleted file mode 100644 index 6b4e438..0000000 --- a/docker/Dockerfile.rel +++ /dev/null @@ -1,29 +0,0 @@ -FROM chewingbever/fej-builder:latest AS builder - -# And then finally, build the project -# Thank the lords that this article exists -# https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172 -# TODO add what these flags do & why they work -# NOTE: cargo install auto-appends bin to the path -RUN --mount=type=cache,target=/usr/src/app/target \ - --mount=type=cache,target=/root/.cargo/registry \ - cargo install --path . --bin fej --root /usr/local - - -# Now, we create the actual image -FROM alpine:latest - -# Install some dynamic libraries needed for everything to work -RUN apk update && apk add --no-cache openssl libgcc curl - -# Copy binary over to final image -COPY --from=builder /usr/local/bin/fej /usr/local/bin/fej - -HEALTHCHECK \ - --interval=10s \ - --timeout=5s \ - --start-period=1s \ - --retries=3 \ - CMD curl -q localhost:8000 - -CMD ["/usr/local/bin/fej"] diff --git a/src/errors.rs b/src/errors.rs index afcf04a..dfb137f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,9 +1,6 @@ // I can probably do this way easier using an external crate, I should do that use rocket::http::Status; -/// Represents any general error that the API can encounter during execution. -/// It allows us to more easily process errors, and hopefully allows for -/// more clear error messages. #[derive(Debug, PartialEq)] pub enum FejError { InvalidArgument, diff --git a/src/ivago/README.md b/src/ivago/README.md new file mode 100644 index 0000000..02d2d0e --- /dev/null +++ b/src/ivago/README.md @@ -0,0 +1,5 @@ +# Ivago + +This part of the API is a wrapper around the Ivago website (Ivago being the +company that collects the trash in my city). Their site isn't exactly RESTful, +so this endpoint simply wraps it in a RESTful wrapper. diff --git a/src/ivago/controller/mod.rs b/src/ivago/controller/mod.rs index 7d3a9f9..0084a3d 100644 --- a/src/ivago/controller/mod.rs +++ b/src/ivago/controller/mod.rs @@ -20,14 +20,15 @@ const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling"; /// Endpoint for the actual calendar output const CAL_URL: &str = "https://www.ivago.be/nl/particulier/garbage/pick-up/pickups"; -/// Searches the Ivago API for streets in the given city. +/// Searches the Ivago API for streets in the given city /// /// # Arguments /// -/// * `search_term` - Search term to use to look for streets -pub fn search_streets(search_term: &str) -> Result, FejError> { +/// * `street` - name of the street +/// * `city` - city the street is in +pub fn search_streets(street_name: &str) -> Result, FejError> { let client = reqwest::Client::new(); - let response = client.get(SEARCH_URL).query(&[("q", search_term)]).send()?; + let response = client.get(SEARCH_URL).query(&[("q", street_name)]).send()?; let data: Vec> = response.json()?; // This is pretty cool, filter_map first does get() on all the maps, and @@ -40,14 +41,14 @@ pub fn search_streets(search_term: &str) -> Result, FejError> { .collect()) } -/// Returns the pickup times for the various trash types. +/// Returns the pickup times for the various trash types /// /// # Arguments /// -/// * `street` - Street to look up -/// * `number` - House number in given street -/// * `start_date` - Earliest date for the results -/// * `end_date` - Latest date for the results +/// * `street` - desired street +/// * `number` - house number +/// * `start_date` - earliest date for the results +/// * `end_date` - latest date for the results pub fn get_pickup_times( street: &Street, number: &u32, diff --git a/src/ivago/controller/pickup_time.rs b/src/ivago/controller/pickup_time.rs index f70cbcf..33718db 100644 --- a/src/ivago/controller/pickup_time.rs +++ b/src/ivago/controller/pickup_time.rs @@ -1,20 +1,14 @@ use super::BasicDate; use serde::ser::{Serialize, SerializeStruct, Serializer}; -/// Represents a date when a pickup will occur. Label describes which type of -/// trash will be picked up. +/// Represents a pickup time instance. All fields are a direct map of the +/// original API pub struct PickupTime { date: BasicDate, label: String, } impl PickupTime { - /// Creates a new PickupTime instance. - /// - /// # Arguments - /// - /// * `date` - Date of pickup time - /// * `label` - Type of trash pub fn new(date: BasicDate, label: String) -> PickupTime { PickupTime { date: date, diff --git a/src/ivago/controller/street.rs b/src/ivago/controller/street.rs index 1a7cac9..00f4de4 100644 --- a/src/ivago/controller/street.rs +++ b/src/ivago/controller/street.rs @@ -4,7 +4,7 @@ use rocket::request::FromFormValue; use serde::ser::{Serialize, SerializeStruct, Serializer}; use std::convert::TryFrom; -/// Represents a street in a given city +/// Represents a street pub struct Street { name: String, city: String, @@ -76,7 +76,6 @@ impl<'v> FromFormValue<'v> for Street { mod tests { use super::*; - /// Tests the conversion to string #[test] fn test_to_string() { let street = Street::new(String::from("testname"), String::from("city")); diff --git a/src/ivago/mod.rs b/src/ivago/mod.rs index 627e89b..e4d1037 100644 --- a/src/ivago/mod.rs +++ b/src/ivago/mod.rs @@ -9,26 +9,11 @@ pub fn routes() -> Vec { routes![route_search_streets, route_get_pickup_times] } -/// This route handles the Ivago search endpoint. It returns a list of streets, -/// consisting of a street name & a city. -/// -/// # Arguments -/// -/// * `search_term` - Search term to use to look for streets -#[get("/search?")] -pub fn route_search_streets(q: String) -> Result>, Status> { - Ok(Json(search_streets(q.as_str())?)) +#[get("/search?")] +pub fn route_search_streets(street: String) -> Result>, Status> { + Ok(Json(search_streets(street.as_str())?)) } -/// Handles returning of pickup times for a specific address. It returns a list -/// of pickup times, containing a date and a description of the trash type. -/// -/// # Arguments -/// -/// * `street` - Street to look up -/// * `number` - House number in the given street -/// * `start_date` - Earliest date that can be returned -/// * `end_date` - Latest date that can be returned #[get("/?&&&")] pub fn route_get_pickup_times( street: Street,