Skip to content

Commit

Permalink
Fix CI (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabudilovskiy authored Apr 1, 2024
1 parent f4a3ce1 commit 5eb2327
Show file tree
Hide file tree
Showing 22 changed files with 59 additions and 51 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ jobs:
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: true
- name: init submdule userver
run: |
sudo git submodule update --init --recursive
- name: add Postgres package repository
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Expand Down Expand Up @@ -85,19 +88,19 @@ jobs:
- name: Configure cmake project
run: >
cmake
-B _cmake_build_{{matrix.compiler}}_{{matrix.version}}_{{matrix.type}}
-DCMAKE_BUILD_TYPE={{matrix.type}}
-B cmake_build_main
-G Ninja
-DCMAKE_BUILD_TYPE=${{matrix.type}}
-DCMAKE_C_COMPILER=$(make find-c-compiler compiler=${{matrix.compiler}} version=${{matrix.version}})
-DCMAKE_CXX_COMPILER=$(make find-cxx-compiler compiler=${{matrix.compiler}} version=${{matrix.version}})
- name: Build project
run: >
cmake
--build _cmake_build_{{matrix.compiler}}_{{matrix.version}}_{{matrix.type}}
-j 6
--build cmake_build_main
--target all
- name: Run ${{matrix.make}}
- name: Run tests
run: |
cd _cmake_build_{{matrix.compiler}}_{{matrix.version}}_{{matrix.type}}
cd cmake_build_main
(test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/*cmake*/
/src/codegen/*
/src/codegen/*
*__pycache__*
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
cmake_minimum_required(VERSION 3.27)
cmake_minimum_required(VERSION 3.20)
project(service)
set(CMAKE_CXX_STANDARD 20)

set(openapi-extension-userver_BUILD_UNIT_TESTS false)
set(openapi-extension-userver_BUILD_TEST_SERVICES false)
set(USERVER_LTO OFF)

add_subdirectory(uopenapi)

Expand All @@ -15,11 +16,13 @@ CreateTrivialPart(
)

target_link_libraries(${src_module} PUBLIC openapi-extension-userver_library)
target_link_libraries(${src_module} PUBLIC userver-postgresql)
target_compile_options(${src_module} PUBLIC "-Wno-missing-field-initializers")

add_executable(service service/main.cpp)

target_link_libraries(service PUBLIC ${src_module})

#uservers workarounds
include(uopenapi/userver/cmake/UserverTestsuite.cmake)
SET(USERVER_PYTHON "python3")
userver_testsuite_add_simple()
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ format:

.PHONY: gen-queries
gen-queries:
@python3 scripts/generate_sql_queries.py $(GENERATE_SQL_QUERIES_FLAGS)
@python3 scripts/generate_sql_queries.py $(GENERATE_SQL_QUERIES_FLAGS)
2 changes: 1 addition & 1 deletion src/helpers/auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ namespace helpers{
end_ts);
return result.AsOptionalSingleRow<boost::uuids::uuid>();
}
}
}
2 changes: 1 addition & 1 deletion src/helpers/auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ namespace helpers{
std::string_view login,
std::string_view password,
userver::storages::postgres::TimePointTz end_ts);
}
}
2 changes: 1 addition & 1 deletion src/models/auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ namespace models::auth{
struct Response{
ResponseBody body;
};
}
}
2 changes: 1 addition & 1 deletion src/models/error_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ namespace models{
struct ErrorResponse{
ErrorResponseBody body;
};
}
}
2 changes: 1 addition & 1 deletion src/models/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ namespace models{
std::optional<std::string> due_date;
};
}
REQUIREMENTS_CE_UOPENAPI(models::Task, due_date) = string_requirements<"date-time">{};
REQUIREMENTS_CE_UOPENAPI(models::Task, due_date) = string_requirements<"date-time">{};
2 changes: 1 addition & 1 deletion src/sql/user/get_token.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ SELECT token_id
FROM live_token
UNION ALL
SELECT token_id
FROM new_token;
FROM new_token;
24 changes: 23 additions & 1 deletion src/views/login/handler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
#include "handler.hpp"

#include <helpers/auth.hpp>

namespace views::login{
void Append(userver::components::ComponentList& componentList){
componentList.Append<handler>();
}
}

handler::response handler::handle(views::login::Request req) const {
userver::storages::postgres::TimePointTz now(userver::utils::datetime::Now());
userver::storages::postgres::TimePointTz end_ts(userver::utils::datetime::Now() + std::chrono::hours(1));
auto token = helpers::GetToken(
todo_db,
req.body.login,
req.body.password,
now,
end_ts);
if (!token){
Response400 resp400;
resp400().body.message = "Invalid login or password";
resp400().body.error_code = models::ErrorCode::invalid_credentials;
return resp400;
}
Response200 response200;
response200().body.token = *token;
return response200;
}
}
26 changes: 2 additions & 24 deletions src/views/login/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <uopenapi/all.hpp>
#include <userver/storages/postgres/component.hpp>
#include <userver/storages/postgres/postgres.hpp>
#include <codegen/sql.hpp>
#include <helpers/auth.hpp>
#include <userver/formats/parse/boost_uuid.hpp>
#include <userver/formats/serialize/boost_uuid.hpp>

Expand All @@ -16,28 +14,8 @@ namespace views::login{
handler(const userver::components::ComponentConfig& cfg,
const userver::components::ComponentContext& ctx) : base(cfg, ctx),
todo_db(ctx.FindComponent<userver::components::Postgres>("todo_db").GetCluster()){}
response handle(views::login::Request req) const override{
userver::storages::postgres::TimePointTz now(userver::utils::datetime::Now());
userver::storages::postgres::TimePointTz end_ts(userver::utils::datetime::Now() + std::chrono::hours(1));
auto token = helpers::GetToken(
todo_db,
req.body.login,
req.body.password,
now,
end_ts);
if (token){
Response200 response200;
response200().body.token = *token;
return response200;
}
else {
Response400 resp400;
resp400().body.message = "Invalid login or password";
resp400().body.error_code = models::ErrorCode::invalid_credentials;
return resp400;
}
}
response handle(views::login::Request req) const override;
private:
userver::storages::postgres::ClusterPtr todo_db;
};
}
}
2 changes: 1 addition & 1 deletion src/views/login/handler_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
namespace views::login{
struct handler;
void Append(userver::components::ComponentList& componentList);
}
}
2 changes: 1 addition & 1 deletion src/views/login/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ namespace views::login{

using Response200 = uopenapi::http::response<models::auth::Response, 200>;
using Response400 = uopenapi::http::response<models::ErrorResponse, 400>;
}
}
2 changes: 1 addition & 1 deletion src/views/register/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ namespace views::Register{
void Append(userver::components::ComponentList& componentList){
componentList.Append<handler>();
}
}
}
2 changes: 1 addition & 1 deletion src/views/register/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ namespace views::Register{
private:
userver::storages::postgres::ClusterPtr todo_db;
};
}
}
2 changes: 1 addition & 1 deletion src/views/register/handler_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
namespace views::Register{
struct handler;
void Append(userver::components::ComponentList& componentList);
}
}
2 changes: 1 addition & 1 deletion src/views/register/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ namespace views::Register{

using Response200 = uopenapi::http::response<Response, 200>;
using Response400 = uopenapi::http::response<models::ErrorResponse, 400>;
}
}
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion tests/postgresql/init_data_user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ VALUES('333111c7-9654-4814-b36b-7d39c1ddded2', 'some_login', 'some_password');
INSERT INTO todos.tokens(token_id, user_id, due_ts)
VALUES ('d9ae85b8-6cc5-4e17-a857-a031277113c7',
'333111c7-9654-4814-b36b-7d39c1ddded2',
'2024-03-30 06:00:00.000 +0300')
'2024-03-30 06:00:00.000 +0300')
2 changes: 1 addition & 1 deletion tests/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ async def test_invalid_login(service_client):
)
assert response.status == 400
assert response.json()['error_code'] == 'invalid_credentials'
assert response.json()['message'] == 'Invalid login or password'
assert response.json()['message'] == 'Invalid login or password'
2 changes: 1 addition & 1 deletion uopenapi
Submodule uopenapi updated 0 files

0 comments on commit 5eb2327

Please sign in to comment.