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

feat: add the adapter of sqlpp11 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 74 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Copyright 2021 The casbin Authors. All Rights Reserved.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: CI

on: [push, pull_request]
Expand All @@ -20,25 +6,53 @@ jobs:
linux:
name: "Ubuntu Latest (GNU 9.3.0)"
runs-on: ubuntu-latest
services:
mysql:
image: mysql:5.7
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -uroot -p125463"
--health-interval=10s
--health-timeout=5s
--health-retries=3
env:
MYSQL_ROOT_PASSWORD: 125463
MYSQL_DATABASE: casbin
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v2

- name: Wait for MySQL to be ready
run: |
while ! mysqladmin ping -h "127.0.0.1" -uroot -p125463 --silent; do
echo 'Waiting for MySQL...'
sleep 1
done

- name: Configuring CMake files
id: building-files
run: |
mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=ON

- name: Building library
id: building-lib
run: |
cd build && cmake --build . --config Release --target all -j 10 --
cd build
cmake --build . --config Release --target all -j 10 --

- name: Tests
id: test-lib
env:
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 3306
MYSQL_USER: root
MYSQL_PASSWORD: 125463
MYSQL_DATABASE: casbin
run: |
cd build
ctest -j10 -C Release -T test --output-on-failure

- name: Cleanup
id: clean-up
run: |
rm -r build

Expand All @@ -49,19 +63,27 @@ jobs:
- name: Checkout
id: checkout
uses: actions/checkout@v2

- name: Configuring CMake files
id: building-files
run: |
mkdir build
cd build
cmake ..

- name: Building library
id: building-lib
run: |
cd build
cmake --build . --config Debug --target casbin gtest gtest_main gmock gmock_main casbintest -j 10 --
- name: Tests
id: test-lib
cmake --build . --config Debug --target casbin sqlpp11::sqlpp11 sqlpp11::mysql nlohmann_json::nlohmann_json GTest::gtest_main GTest::gtest 11sql_test -j 10 --

- name: Running Tests
env:
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 3306
MYSQL_USER: root
MYSQL_PASSWORD: 125463
MYSQL_DATABASE: casbin
run: |
cd build
ctest -j10 -C Release -T test --output-on-failure
Expand All @@ -71,22 +93,41 @@ jobs:
runs-on: macos-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v2

- name: Install MySQL
run: |
brew install mysql
brew install mysql-connector-c
export MYSQL_ROOT_DIR=$(brew --prefix mysql)
export MYSQL_INCLUDE_DIR=$MYSQL_ROOT_DIR/include
export MYSQL_LIB_DIR=$MYSQL_ROOT_DIR/lib

- name: Configuring CMake files
id: building-files
env:
MYSQL_INCLUDE_DIR: ${{ env.MYSQL_INCLUDE_DIR }}
MYSQL_LIBRARY: ${{ env.MYSQL_LIB_DIR }}/libmysqlclient.dylib
run: |
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=~/local
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=~/local -DMYSQL_INCLUDE_DIR=${MYSQL_INCLUDE_DIR} -DMYSQL_LIBRARY=${MYSQL_LIBRARY} -DENABLE_TESTING=ON

- name: Building library
id: building-lib
run: |
cd build && cmake --build . --config Debug --target all install -j 10 --
cd build
cmake --build . --config Debug --target all install -j 10 --

- name: Tests
id: test-lib
env:
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 3306
MYSQL_USER: root
MYSQL_PASSWORD: 125463
MYSQL_DATABASE: casbin
run: |
cd build
cd build
ctest -j10 -C Release -T test --output-on-failure

- name: Cleanup
id: clean-up
run: |
rm -r build
rm -r build
43 changes: 11 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The casbin Authors. All Rights Reserved.
# Copyright 2021 The casbin Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -11,41 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.19)

set(CMAKE_WARN_DEPRECATED ON)

#sqlpp11
project(Test VERSION 0.1 LANGUAGES CXX)
### Preamble ###
cmake_minimum_required(VERSION 3.14)
project(11sql VERSION 0.1 LANGUAGES CXX)

##### Project wide setup ####
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_definitions(-DNOMINMAX)

### Dependencies ###
add_subdirectory(dependencies)

#casbin
add_executable(test )

target_link_libraries(test PRIVATE casbin)

set(test_INCLUDE_DIR ${casbin_SOURCE_DIR}/include)
target_include_directories(test PRIVATE ${myexec_INCLUDE_DIR})


target_link_libraries(test
PRIVATE
sqlpp11::sqlpp11
# Corresponding targets for the connectors. These connectors need to be enabled in the the dependencies/sqlpp11 folder. These targets automatically link against sqlpp11::sqlpp11 and therefore sqlpp11::sqlpp11 doesn't need to be linked manually again
# sqlpp11::sqlite3
# sqlpp11::sqlcipher
# sqlpp11::mysql
# sqlpp11::mariadb
# sqlpp11::postgresql
)

target_sources(test
PRIVATE
sqlpp11_adapter.cpp
test.cpp
)
### Main Targets ###
add_definitions(-Dmodelpath=${CMAKE_SOURCE_DIR})
enable_testing()
add_subdirectory(src)
96 changes: 96 additions & 0 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2021 The casbin Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#sqlpp11
include(FetchContent)

FetchContent_Declare(sqlpp11
GIT_REPOSITORY https://github.com/rbock/sqlpp11
GIT_TAG origin/main
)

# Configure the project here as needed
set(BUILD_MYSQL_CONNECTOR ON)
# set(BUILD_MARIADB_CONNECTOR ON)
# set(BUILD_POSTGRESQL_CONNECTOR ON)
# set(BUILD_SQLITE3_CONNECTOR ON)
# set(BUILD_SQLCIPHER_CONNECTOR ON)

# set(USE_SYSTEM_DATE ON)

FetchContent_MakeAvailable(sqlpp11)

#casbin
include(FetchContent)

FetchContent_Declare(
casbin
GIT_REPOSITORY https://github.com/casbin/casbin-cpp.git
GIT_TAG v1.59.0
)

set(CASBIN_BUILD_TEST OFF) # If you don't need to build tests for casbin
set(CASBIN_BUILD_BENCHMARK OFF) # If you don't need to build benchmarks for casbin
set(CASBIN_BUILD_BINDINGS OFF) # If you don't need language bindings provided by casbin
set(CASBIN_BUILD_PYTHON_BINDINGS OFF) # If you don't need python bindings provided by casbin

# Making casbin and its targets accessible to our project
FetchContent_MakeAvailable(casbin)

FetchContent_GetProperties(casbin)

# If casbin wasn't populated, then manually populate it
if(NOT casbin_POPULATED)
FetchContent_Populate(casbin)
add_subdirectory(${casbin_SOURCE_DIR} ${casbin_BINARY_DIR})
endif()


#gtest
include(FetchContent)

FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)
FetchContent_GetProperties(googletest)

# Populating manually, if not done automatically
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()


#json
include(FetchContent)

set(JSON_Install ON)

FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
)

FetchContent_MakeAvailable(json)

14 changes: 14 additions & 0 deletions examples/model.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
2 changes: 2 additions & 0 deletions examples/policy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
p alice data1 read
p bob data2 write
Loading
Loading