From a29523786389a17feef1a59d5bc1bb0ab20c2bc6 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 5 Sep 2021 09:59:16 +0200 Subject: [PATCH] Some random stuff tbh --- .dockerignore | 17 +++++++++++++---- Dockerfile | 11 +++++++++++ Makefile | 22 ++++++++++++++++++++-- build.sh | 15 +++++++++++++++ src/auth/jwt.rs | 5 +++++ 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 Dockerfile create mode 100644 build.sh diff --git a/.dockerignore b/.dockerignore index a2fdc7d..04c13db 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,13 @@ -.vim/ -out/ -vendor/ -target/ +* + +!Cargo.lock +!Cargo.toml +!Makefile +!migrations +!Rb.yaml +!rustfmt.toml +!src +!tests +!web + +web/node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9e3326 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM rust:1.54 + +RUN apt update && \ + apt install -y --no-install-recommends \ + musl-dev \ + musl-tools \ + libpq-dev \ + libssl-dev && \ + rustup target add x86_64-unknown-linux-musl + +WORKDIR /usr/src/app diff --git a/Makefile b/Makefile index 0f1146d..8a4f1fe 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ CORES != nproc export CC=musl-gcc -fPIC -pie -static export LD_LIBRARY_PATH=$(PREFIX) export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig +export PATH := /usr/local/bin:/root/.cargo/bin:$(PATH) # TODO check for header files (openssl-dev, libpq-dev) both for Arch & Ubuntu @@ -37,15 +38,32 @@ $(shell mkdir -p "$(PREFIX)") .PHONY: all all: build +.PHONY: docker +docker: + docker run \ + --rm \ + -v "$$PWD:/usr/src" \ + --workdir "/usr/src" \ + -it \ + rust:1.54 \ + bash build.sh + + # libpq builds openssl as a dependency .PHONY: build build: libpq .PHONY: clean clean: + echo "$$PATH" @ echo "Note: this only cleans the C dependencies, not the Cargo cache." rm -rf "$(PQ_DIR)" "$(OPENSSL_DIR)" "$(DI_DIR)" "$(PREFIX)" +# This is used inside the Dockerfile +.PHONY: pathfile +pathfile: + echo "$(PREFIX)/lib" >> /etc/ld-musl-x86_64.path + # =====OPENSSL===== # Download the source code & configure the project @@ -53,7 +71,7 @@ $(OPENSSL_DIR)/Configure: curl -sSL "https://www.openssl.org/source/openssl-$(SSL_VER).tar.gz" | \ tar -C "$(OUT_DIR)" -xz cd "$(OPENSSL_DIR)" && \ - CC="$$CC -idirafter /usr/include" ./Configure \ + CC="$$CC -idirafter /usr/include -idirafter /usr/include/x86_64-linux-gnu/" ./Configure \ no-zlib \ no-shared \ --prefix="$(PREFIX)" \ @@ -63,7 +81,7 @@ $(OPENSSL_DIR)/Configure: # Build OpenSSL .PHONY: openssl openssl: $(OPENSSL_DIR)/Configure - C_INCLUDE_PATH="$(PREFIX)/include" $(MAKE) -C "$(OPENSSL_DIR)" depend + env C_INCLUDE_PATH="$(PREFIX)/include" $(MAKE) -C "$(OPENSSL_DIR)" depend $(MAKE) -C "$(OPENSSL_DIR)" -j$(CORES) $(MAKE) -C "$(OPENSSL_DIR)" install_sw diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..a6f57cd --- /dev/null +++ b/build.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e + +# Install build dependencies +apt update +apt install \ + -y --no-install-recommends \ + musl-dev \ + musl-tools \ + libssl-dev \ + libpq-dev + +make pathfile +make diff --git a/src/auth/jwt.rs b/src/auth/jwt.rs index 0f7d37e..997f68e 100644 --- a/src/auth/jwt.rs +++ b/src/auth/jwt.rs @@ -99,6 +99,11 @@ pub fn refresh_token( return Err(RbError::AuthDuplicateRefreshToken); } + // Then we check if the user is blocked + if user.blocked { + return Err(RbError::AuthBlockedUser); + } + // Now we check if the token has already expired let cur_time = Utc::now().naive_utc();