Skip to content

Commit

Permalink
Merge pull request #2 from sabudilovskiy/add_authentication
Browse files Browse the repository at this point in the history
1) Release Authentication(/lpgin, /request)
2) Add vscode workspace
3) Changed structure of project
  • Loading branch information
sabudilovskiy authored Mar 31, 2023
2 parents 4c2c06f + df57b47 commit 5e46047
Show file tree
Hide file tree
Showing 63 changed files with 1,172 additions and 131 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
run: |
sudo apt update
sudo apt install --allow-downgrades -y pep8 $(cat third_party/userver/scripts/docs/en/deps/${{matrix.os}}.md | tr '\n' ' ')
sudo pip install $(cat dependencies/python.md) | tr '\n' ' '
- name: Setup ccache
run: |
Expand All @@ -63,15 +64,15 @@ jobs:
- name: Test run after install
if: matrix.make == 'test-release'
run: |
./local_installation/bin/Timetable-VSU-backend --config=./local_installation/etc/Timetable-VSU-backend/static_config.yaml &
./local_installation/bin/timetable_vsu_backend --config=./local_installation/etc/timetable_vsu_backend/static_config.yaml &
- name: Check work run service
if: matrix.make == 'test-release'
run: |
ps aux | grep Timetable-VSU-backend | grep config && curl http://localhost:8080/ping -v
ps aux | grep timetable_vsu_backend | grep config && curl http://localhost:8080/ping -v
- name: Stop all
if: matrix.make == 'test-release'
run: |
killall Timetable-VSU-backend
killall timetable_vsu_backend
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
ccache-
- name: Setup ccache
run: docker-compose run --rm Timetable-VSU-backend-container bash -c 'ccache -M 2.0GB && ccache -s'
run: docker-compose run --rm timetable_vsu_backend-container bash -c 'ccache -M 2.0GB && ccache -s'

- name: Cmake
run: make docker-cmake-release
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ build*
compile_commands.json
.cache/
.idea/
.vscode/
.cores/
.ccache/
.pgdata/
cmake-build-*
Testing/
configs/static_config.yaml
Makefile.local
28 changes: 28 additions & 0 deletions .vscode/vsu_timetable.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"folders": [
{
"path": "../",
"name" : "vsu_timetable"
},
],
"extensions":{
"recommendations":[
"llvm-vs-code-extensions.vscode-clangd",
"Redocly.openapi-vs-code",
"ms-vscode.makefile-tools",
"vadimcn.vscode-lldb",
"ms-vscode.cmake-tools",
"notskm.clang-tidy",
"ms-vscode.cpptools"
]
},
"settings": {
"files.exclude": {
"third_party": true,
"build*": true,
".*" : true,
"dependencies" : true
},
"clang-tidy.buildPath": "../build_debug"
}
}
44 changes: 37 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(Timetable-VSU-backend CXX)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)

project(timetable_vsu_backend CXX)

include(third_party/userver/cmake/SetupEnvironment.cmake)
include(GNUInstallDirs)
Expand All @@ -9,28 +12,55 @@ add_subdirectory(third_party/userver)

# Common sources
add_library(${PROJECT_NAME}_objs OBJECT
src/hello.hpp
src/hello.cpp
src/views/hello/view.hpp
src/views/hello/view.cpp
src/components/controllers/user_controller.cpp
src/components/controllers/user_controller.hpp
src/components/controllers/user_controller_fwd.hpp
src/components/controllers/user_controller_fwd.cpp
src/components/controllers/token_controller_fwd.cpp
src/components/controllers/user_controller_fwd.cpp
src/components/controllers/token_controller.hpp
src/components/controllers/token_controller.cpp
src/models/auth_token/type.hpp
src/models/auth_token/serialize.hpp
src/http/handler_parsed.hpp
src/models/user/type.hpp
src/models/user_type/parse.cpp
src/models/user_type/parse.hpp
src/models/user_type/postgre.hpp
src/models/user_type/type.hpp
src/utils/component_list_fwd.hpp
src/utils/json_type.cpp
src/utils/json_type.hpp
src/views/login/Request.cpp
src/views/login/Request.hpp
src/views/login/view.cpp
src/views/login/view.hpp
src/views/register/Request.cpp
src/views/register/Request.hpp
src/views/register/view.cpp
src/views/register/view.hpp
)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver-core)
target_link_libraries(${PROJECT_NAME}_objs PUBLIC userver-core userver-postgresql)


# The Service
add_executable(${PROJECT_NAME} src/main.cpp)
add_executable(${PROJECT_NAME} service/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_objs)


# Unit Tests
add_executable(${PROJECT_NAME}_unittest
src/hello_test.cpp
utests/hello_test.cpp
)
target_link_libraries(${PROJECT_NAME}_unittest PRIVATE ${PROJECT_NAME}_objs userver-utest)
add_google_tests(${PROJECT_NAME}_unittest)


# Benchmarks
add_executable(${PROJECT_NAME}_benchmark
src/hello_benchmark.cpp
benchs/hello_benchmark.cpp
)
target_link_libraries(${PROJECT_NAME}_benchmark PRIVATE ${PROJECT_NAME}_objs userver-ubench)
add_google_benchmark_tests(${PROJECT_NAME}_benchmark)
Expand Down
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ cmake-debug cmake-release: cmake-%: build_%/Makefile
# Build using cmake
.PHONY: build-debug build-release
build-debug build-release: build-%: cmake-%
@cmake --build build_$* -j $(NPROCS) --target Timetable-VSU-backend
@cmake --build build_$* -j $(NPROCS) --target timetable_vsu_backend

# Test
.PHONY: test-debug test-release
test-debug test-release: test-%: build-%
@cmake --build build_$* -j $(NPROCS) --target Timetable-VSU-backend_unittest
@cmake --build build_$* -j $(NPROCS) --target Timetable-VSU-backend_benchmark
@cmake --build build_$* -j $(NPROCS) --target timetable_vsu_backend_unittest
@cmake --build build_$* -j $(NPROCS) --target timetable_vsu_backend_benchmark
@cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V)
@pep8 tests

# Start the service (via testsuite service runner)
.PHONY: service-start-debug service-start-release
service-start-debug service-start-release: service-start-%: build-%
@cd ./build_$* && $(MAKE) start-Timetable-VSU-backend
@cd ./build_$* && $(MAKE) start-timetable_vsu_backend

# Cleanup data
.PHONY: clean-debug clean-release
Expand All @@ -63,7 +63,7 @@ dist-clean:
.PHONY: install-debug install-release
install-debug install-release: install-%: build-%
@cd build_$* && \
cmake --install . -v --component Timetable-VSU-backend
cmake --install . -v --component timetable_vsu_backend

.PHONY: install
install: install-release
Expand All @@ -75,22 +75,24 @@ format:
@find tests -name '*.py' -type f | xargs autopep8 -i

# Internal hidden targets that are used only in docker environment
.PHONY: --in-docker-start-debug --in-docker-start-release
--in-docker-start-debug --in-docker-start-release: --in-docker-start-%: install-%
@/home/user/.local/bin/Timetable-VSU-backend \
--config /home/user/.local/etc/Timetable-VSU-backend/static_config.yaml
@sed -i 's/config_vars.yaml/config_vars.docker.yaml/g' /home/user/.local/etc/timetable_vsu_backend/static_config.yaml
@psql 'postgresql://user:password@service-postgres:5432/timetable_vsu_backend_db-1' -f ./postgresql/data/initial_data.sql
@/home/user/.local/bin/timetable_vsu_backend \
--config /home/user/.local/etc/timetable_vsu_backend/static_config.yaml

# Build and run service in docker environment
.PHONY: docker-start-service-debug docker-start-service-release
docker-start-service-debug docker-start-service-release: docker-start-service-%:
@docker-compose run -p 8080:8080 --rm Timetable-VSU-backend-container $(MAKE) -- --in-docker-start-$*
@docker-compose run -p 8080:8080 --rm timetable_vsu_backend-container $(MAKE) -- --in-docker-start-$*

# Start specific target in docker environment
# Start targets makefile in docker environment
.PHONY: docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release
docker-cmake-debug docker-build-debug docker-test-debug docker-clean-debug docker-install-debug docker-cmake-release docker-build-release docker-test-release docker-clean-release docker-install-release: docker-%:
docker-compose run --rm Timetable-VSU-backend-container $(MAKE) $*
docker-compose run --rm timetable_vsu_backend-container $(MAKE) $*

# Stop docker container and cleanup data
# Stop docker container and remove PG data
.PHONY: docker-clean-data
docker-clean-data:
@docker-compose down -v
@rm -rf ./.pgdata
4 changes: 2 additions & 2 deletions src/hello_benchmark.cpp → benchs/hello_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "hello.hpp"
#include "../src/views/hello/view.hpp"

#include <cstdint> // for std::uint64_t
#include <iterator> // for std::size
Expand All @@ -14,7 +14,7 @@ void HelloBenchmark(benchmark::State& state) {

for (auto _ : state) {
const auto name = kNames[i++ % std::size(kNames)];
auto result = service_template::SayHelloTo(name);
auto result = service_template::SayHelloTo(name, service_template::UserType::kKnown);
benchmark::DoNotOptimize(result);
}
});
Expand Down
9 changes: 9 additions & 0 deletions configs/config_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
worker-threads: 4
worker-fs-threads: 2
logger-level: debug

is_testing: false

server-port: 8080

dbconnection: 'postgresql://timetable_vsu_backend_user:password@localhost:5432/timetable_vsu_backend_db_1'
9 changes: 9 additions & 0 deletions configs/config_vars.docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
worker-threads: 4
worker-fs-threads: 2
logger-level: debug

is_testing: false

server-port: 8080

dbconnection: 'postgresql://user:password@service-postgres:5432/timetable_vsu_backend_db_1'
2 changes: 2 additions & 0 deletions configs/config_vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ logger-level: debug
is_testing: false

server-port: 8080

dbconnection: 'postgresql://timetable_vsu_backend_user:password@localhost:5432/timetable_vsu_backend_db_1'
7 changes: 0 additions & 7 deletions configs/config_vars_testing.yaml

This file was deleted.

29 changes: 28 additions & 1 deletion configs/dynamic_config_fallback.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,32 @@
}
}
}
},
"POSTGRES_CONNECTION_PIPELINE_ENABLED": false,
"POSTGRES_CONNECTION_POOL_SETTINGS": {
"postgres-db-1": {
"max_pool_size": 15,
"max_queue_size": 200,
"min_pool_size": 8
}
},
"POSTGRES_DEFAULT_COMMAND_CONTROL": {
"network_timeout_ms": 750,
"statement_timeout_ms": 500
},
"POSTGRES_HANDLERS_COMMAND_CONTROL": {
"/v1/hello": {
"POST": {
"network_timeout_ms": 500,
"statement_timeout_ms": 250
}
}
},
"POSTGRES_QUERIES_COMMAND_CONTROL": {},
"POSTGRES_CONNECTION_SETTINGS": {},
"POSTGRES_STATEMENT_METRICS_SETTINGS": {
"postgres-db-1": {
"max_statement_metrics": 5
}
}
}
}
18 changes: 17 additions & 1 deletion configs/static_config.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ components_manager:
overflow_behavior: discard # Drop logs if the system is too busy to write them down.

tracer: # Component that helps to trace execution times and requests in logs.
service-name: Timetable-VSU-backend # "You know. You all know exactly who I am. Say my name. " (c)
service-name: timetable_vsu_backend # "You know. You all know exactly who I am. Say my name. " (c)

dynamic-config: # Dynamic config storage options, do nothing
fs-cache-path: ''
Expand All @@ -53,6 +53,22 @@ components_manager:
path: /tests/{action}
method: POST
task_processor: main-task-processor
handler-login:
path: /login
method: POST
task_processor: main-task-processor
handler-register:
path: /register
method: POST
task_processor: main-task-processor
postgres-db-1:
dbconnection: $dbconnection
blocking_task_processor: fs-task-processor
dns_resolver: async
sync-start: true
user_controller: {}
token_controller: {}

handler-ping:
path: /ping
method: GET
Expand Down
10 changes: 10 additions & 0 deletions configs_testing/config_vars_testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
worker-threads: 4
worker-fs-threads: 2
logger-level: debug

is_testing: true

server-port: 8080

# timetable_vsu_backend_db_1 is the service name + _ + filename of the db_1.sql
dbconnection: 'postgresql://testsuite:password@localhost:15433/timetable_vsu_backend_db_1'
1 change: 1 addition & 0 deletions dependencies/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psycopg2
Loading

0 comments on commit 5e46047

Please sign in to comment.