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

Version 1.7.0 #121

Merged
merged 25 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2d9f8cc
Don't auto-log HTTP exceptions.
josephbirkner Jun 24, 2024
38b40ca
Bump version.
josephbirkner Jul 2, 2024
a6f3f87
Explicitely support zlib.
josephbirkner Jul 4, 2024
cd20e5c
Simplify SSL support by linking statically.
josephbirkner Jul 4, 2024
28f5087
Support multiple servers in the OpenAPI spec.
josephbirkner Jul 4, 2024
f624b4d
Allow parameters which do not define z-zserio-request-part.
josephbirkner Jul 4, 2024
c73dca0
Support new flexible YAML settings file format.
josephbirkner Jul 5, 2024
bfce116
Fix access-after-move.
josephbirkner Jul 5, 2024
4e67871
Fix CI problems.
josephbirkner Jul 8, 2024
f1ad5b4
Use node built into manylinux image instead of the Github version rel…
josephbirkner Jul 8, 2024
ab0c060
Add Python 3.12 to CI.
josephbirkner Jul 8, 2024
c96ca7f
Correctly symlink node20
josephbirkner Jul 8, 2024
0bca753
Use Github-provisioned Node after all, no chance to override it.
josephbirkner Jul 8, 2024
1cfee19
Fix dependency version conflict.
josephbirkner Jul 8, 2024
36ba66b
Update conanfile.py
josephbirkner Jul 9, 2024
1afc220
Fix ctest no-tests parameter.
josephbirkner Jul 9, 2024
997b0b5
Enforce that testing is enabled.
josephbirkner Jul 9, 2024
4efa132
Update docs for http-settings.
josephbirkner Jul 9, 2024
64dbd20
Fix server index access in HTTP client.
josephbirkner Jul 9, 2024
6b588aa
Disable Python 3.12 support for now, waiting for new zserio release w…
josephbirkner Jul 9, 2024
2dd3b75
Improve ZLIB integration.
josephbirkner Jul 15, 2024
bd5f1f2
Add httpcl::Settings::updateTimestamp
josephbirkner Jul 15, 2024
f3edafc
Add test for serverIndex.
josephbirkner Jul 15, 2024
b9cea63
Catch exceptions from load().
josephbirkner Jul 17, 2024
5e89717
Fix include guards.
josephbirkner Jul 17, 2024
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
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
61 changes: 9 additions & 52 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 @@ -112,15 +113,20 @@ if (NOT TARGET Catch2)
endif()

if (NOT TARGET 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
Loading