Skip to content

Commit

Permalink
Merge pull request #121 from ndsev/version-1-7-0
Browse files Browse the repository at this point in the history
Version 1.7.0
  • Loading branch information
josephbirkner authored Jul 17, 2024
2 parents d698e93 + 5e89717 commit 9adec61
Show file tree
Hide file tree
Showing 24 changed files with 286 additions and 194 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@ jobs:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}:2023.2
container: ghcr.io/klebert-engineering/manylinux-cpp17-py${{ matrix.python-version }}-x86_64:2024.1
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Cache Conan packages
uses: actions/cache@v2
with:
path: ~/.conan/data
key: ${{ runner.os }}-conan-${{ hashFiles('**/conanfile.txt') }}
restore-keys: |
${{ runner.os }}-conan-
- name: Which Node.js?
run: |
echo "Node at $(which node): $(node -v); npm: $(npm -v)"
- name: Checkout code
uses: actions/checkout@v2
- name: Configure
run: |
python3 -m venv venv && . ./venv/bin/activate
pip install -U setuptools wheel pip conan==2.2.1
mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release ..
pip install -U setuptools wheel pip conan==2.5.0
mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DZSWAG_ENABLE_TESTING=ON ..
- name: Build
working-directory: build
run: |
Expand All @@ -38,7 +35,7 @@ jobs:
working-directory: build
run: |
. ../venv/bin/activate
ctest -C Release --verbose --no-test=fail
ctest -C Release --verbose --no-tests=error
- name: Deploy
uses: actions/upload-artifact@v2
with:
Expand All @@ -65,7 +62,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: python -m pip install setuptools wheel conan==2.2.1
- run: python -m pip install setuptools wheel conan==2.5.0
- run: mkdir build
- name: Build (macOS)
if: matrix.os == 'macos-13'
Expand All @@ -76,7 +73,8 @@ jobs:
cmake -DPython3_ROOT_DIR=$pythonLocation \
-DPython3_FIND_FRAMEWORK=LAST \
-DCMAKE_BUILD_TYPE=Release \
-DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF ..
-DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF \
-DZSWAG_ENABLE_TESTING=ON ..
cmake --build .
mv bin/wheel bin/wheel-auditme # Same as on Linux
mkdir bin/wheel && mv bin/wheel-auditme/zswag*.whl bin/wheel
Expand All @@ -88,7 +86,7 @@ jobs:
working-directory: build
run: |
echo "cmake -DPython3_ROOT_DIR=$env:pythonLocation"
cmake "-DPython3_ROOT_DIR=$env:pythonLocation" -DPython3_FIND_REGISTRY=LAST -DHTTPLIB_USE_ZLIB_IF_AVAILABLE=OFF -DCMAKE_BUILD_TYPE=Release ..
cmake "-DPython3_ROOT_DIR=$env:pythonLocation" -DPython3_FIND_REGISTRY=LAST -DCMAKE_BUILD_TYPE=Release -DZSWAG_ENABLE_TESTING=ON ..
cmake --build . --config Release
- name: Deploy
uses: actions/upload-artifact@v2
Expand All @@ -98,4 +96,4 @@ jobs:
- name: Test
working-directory: build
run: |
ctest -C Release --verbose --no-test=fail
ctest -C Release --verbose --no-tests=error
67 changes: 12 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ project(zswag)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ZSWAG_VERSION 1.6.7post1)
set(ZSWAG_VERSION 1.7.0)

option(ZSWAG_BUILD_WHEELS "Enable zswag whl-output to WHEEL_DEPLOY_DIRECTORY." ON)
option(ZSWAG_KEYCHAIN_SUPPORT "Enable zswag keychain support." ON)
option(ZSWAG_ENABLE_TESTING "Enable testing for the project" OFF)

if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
message (STATUS "Testing will be enabled as zswag is the top-level project.")
set (ZSWAG_ENABLE_TESTING ON CACHE BOOL "By default, enable testing if this is the main project")
endif()

Expand Down Expand Up @@ -79,7 +80,7 @@ if (ZSWAG_BUILD_WHEELS)
endif()
endif()

if (NOT TARGET yaml-cpp)
if (NOT TARGET yaml-cpp::yaml-cpp)
FetchContent_Declare(yaml-cpp
GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git"
GIT_TAG "yaml-cpp-0.7.0"
Expand All @@ -103,24 +104,29 @@ if (NOT TARGET speedyj)
FetchContent_MakeAvailable(speedyj)
endif()

if (NOT TARGET Catch2)
if (NOT TARGET Catch2::Catch2)
FetchContent_Declare(Catch2
GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
GIT_TAG "v3.4.0"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(Catch2)
endif()

if (NOT TARGET httplib)
if (NOT TARGET httplib::httplib)
if (NOT TARGET ZLIB::ZLIB)
find_package(ZLIB CONFIG REQUIRED)
endif ()
set (HTTPLIB_IS_USING_ZLIB TRUE)
FetchContent_Declare(httplib
GIT_REPOSITORY "https://github.com/yhirose/cpp-httplib.git"
GIT_TAG "v0.15.3"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(httplib)
target_compile_definitions(httplib
INTERFACE
CPPHTTPLIB_OPENSSL_SUPPORT)
target_link_libraries(httplib INTERFACE OpenSSL::SSL)
CPPHTTPLIB_OPENSSL_SUPPORT)
target_link_libraries(
httplib INTERFACE OpenSSL::SSL ZLIB::ZLIB)
endif()

if(ZSWAG_BUILD_WHEELS AND NOT TARGET pybind11)
Expand Down Expand Up @@ -160,55 +166,6 @@ if (ZSWAG_BUILD_WHEELS)
add_dependencies(wheel zswag-server-wheel)
endif()

##############
# deploy openssl libs

if (WIN32)
set(OPENSSL_DEPLOY_DIR "${ZSWAG_DEPLOY_DIR}/${CMAKE_BUILD_TYPE}")
else()
set(OPENSSL_DEPLOY_DIR "${ZSWAG_DEPLOY_DIR}")
endif()

message(STATUS "Deploying to ${OPENSSL_DEPLOY_DIR}")
message(STATUS "OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")

if(APPLE)
set(OPENSSL_LIB_DIR "${OPENSSL_INCLUDE_DIR}/../lib")
set(OPENSSL_LIBS
"${OPENSSL_LIB_DIR}/libcrypto.3.dylib"
"${OPENSSL_LIB_DIR}/libssl.3.dylib"
)
elseif(MSVC)
set(OPENSSL_LIB_DIR "${OPENSSL_INCLUDE_DIR}/../bin")
set(OPENSSL_LIBS
"${OPENSSL_LIB_DIR}/libcrypto-3-x64.dll"
"${OPENSSL_LIB_DIR}/libssl-3-x64.dll"
)
elseif(UNIX AND NOT APPLE)
set(OPENSSL_LIB_DIR "${OPENSSL_INCLUDE_DIR}/../lib")
set(OPENSSL_LIBS
"${OPENSSL_LIB_DIR}/libcrypto.so.3"
"${OPENSSL_LIB_DIR}/libssl.so.3"
)
endif()

foreach(file_i ${OPENSSL_LIBS})
get_filename_component(filename ${file_i} NAME)
add_custom_command(
OUTPUT "${OPENSSL_DEPLOY_DIR}/${filename}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${file_i}"
"${OPENSSL_DEPLOY_DIR}/${filename}"
DEPENDS "${file_i}"
COMMENT "Copying ${file_i} to ${OPENSSL_DEPLOY_DIR}"
)
list(APPEND COPIED_OPENSSL_LIBS "${OPENSSL_DEPLOY_DIR}/${filename}")
endforeach(file_i)

add_custom_target(copy_openssl_libs ALL DEPENDS ${COPIED_OPENSSL_LIBS})

add_dependencies(zswagcl copy_openssl_libs)




Expand Down
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,26 +581,28 @@ variable. The YAML file contains a list of HTTP-related configs that are
applied to HTTP requests based on a regular expression which is matched
against the requested URL.

For example, the following entry would match all requests due to the `.*`
url-match-pattern:
For example, the following entry would match all requests due to the `*`
url-match-pattern for the `scope` field:

```yaml
- url: .*
basic-auth:
user: johndoe
keychain: keychain-service-string
proxy:
host: localhost
port: 8888
user: test
keychain: ...
cookies:
key: value
headers:
key: value
query:
key: value
api-key: value
http-settings:
# Under http-settings, a list of settings is defined for specific URL scopes.
- scope: * # URL scope - e.g. https://*.nds.live/* or *.google.com.
basic-auth: # Basic auth credentials for matching requests.
user: johndoe
keychain: keychain-service-string
proxy: # Proxy settings for matching requests.
host: localhost
port: 8888
user: test
keychain: ...
cookies: # Additional Cookies for matching requests.
key: value
headers: # Additional Headers for matching requests.
key: value
query: # Additional Query parameters for matching requests.
key: value
api-key: value # API Key as required by OpenAPI config - see description below.
```

**Note:** For `proxy` configs, the credentials are optional.
Expand Down
21 changes: 21 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from conan import ConanFile
from conan.tools.cmake import CMakeDeps

class ZswagRecipe(ConanFile):
name = "zswag"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps"

# Specify options
default_options = {
"openssl*:shared": False
}

def requirements(self):
self.requires("openssl/3.2.0")
self.requires("keychain/1.3.0")
self.requires("spdlog/1.11.0")
self.requires("pybind11/2.10.4")
self.requires("zlib/1.2.13")
# keychain and libsecret have a conflict here.
self.requires("glib/2.78.3", override=True)
11 changes: 0 additions & 11 deletions conanfile.txt

This file was deleted.

4 changes: 1 addition & 3 deletions libs/httpcl/include/httpcl/http-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class IHttpClient
Error(Result result, std::string const& message)
: std::runtime_error(message)
, result(std::move(result))
{
log().error(message);
}
{}
};

virtual ~IHttpClient() = default;
Expand Down
21 changes: 19 additions & 2 deletions libs/httpcl/include/httpcl/http-settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <map>
#include <vector>
#include <string>
#include <shared_mutex>
#include <atomic>
#include "yaml-cpp/yaml.h"


namespace httpcl
Expand Down Expand Up @@ -41,6 +44,10 @@ struct Config
std::string keychain;
};

std::optional<std::string> scope;
std::regex urlPattern;
std::string urlPatternString;

std::map<std::string, std::string> cookies;
std::optional<BasicAuthentication> auth;
std::optional<Proxy> proxy;
Expand All @@ -67,7 +74,7 @@ struct Config
};

/**
* Loads settings from HTTP_SETTINGS_FILE.
* Loads/stores settings from/to HTTP_SETTINGS_FILE.
* Allows returning config for a specific URL.
*/
struct Settings
Expand All @@ -85,7 +92,17 @@ struct Settings
/**
* Map from URL pattern to some config values.
*/
std::map<std::string, Config> settings;
std::vector<Config> settings;
YAML::Node document;
mutable std::shared_mutex mutex;
std::chrono::steady_clock::time_point lastRead;

/**
* Prompt settings instance to re-parse the HTTP settings file,
* by calling updateTimestamp with std::chrono::steady_clock::now().
*/
static void updateTimestamp(std::chrono::steady_clock::time_point time);
static std::atomic<std::chrono::steady_clock::time_point> lastUpdated;
};

struct secret
Expand Down
Loading

0 comments on commit 9adec61

Please sign in to comment.