From 167757855f888f42ffe57ac776a1d880d008ce96 Mon Sep 17 00:00:00 2001 From: faumaray Date: Wed, 29 Jul 2026 22:40:35 +0300 Subject: [PATCH] Harden external shortener and add component releases --- .gitea/workflows/release.yml | 56 +++++++++++++++ CMakeLists.txt | 13 +++- abi/module.json | 6 +- component.release.json | 7 ++ src/ExternalShortener.cpp | 18 ++++- src/Plugin.cpp | 113 +++++++++++++++++++++++++------ tests/ExternalShortenerTests.cpp | 4 ++ 7 files changed, 188 insertions(+), 29 deletions(-) create mode 100644 .gitea/workflows/release.yml create mode 100644 component.release.json diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..c1b4e11 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,56 @@ +name: Independent component release +on: + push: + tags: [v*] + schedule: + - cron: '17 2 * * *' + workflow_dispatch: +jobs: + publish: + runs-on: echoion-release-serial + steps: + - name: Check out component + uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + fetch-depth: 0 + ssh-key: ${{ secrets.RELEASE_CHECKOUT_SSH_KEY }} + persist-credentials: false + - name: Check out pinned public release tools + uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + repository: Void/Echoion + ref: ${{ vars.ECHOION_RELEASE_TOOLS_REF }} + path: .echoion-release-tools + fetch-depth: 0 + ssh-key: ${{ secrets.RELEASE_CHECKOUT_SSH_KEY }} + persist-credentials: false + - name: Build, publish, and merge feed transaction + shell: bash + env: + AWS_ACCESS_KEY_ID: ${{ secrets.COMPONENT_OBJECT_STORAGE_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.COMPONENT_OBJECT_STORAGE_SECRET_KEY }} + AWS_DEFAULT_REGION: ${{ vars.COMPONENT_OBJECT_STORAGE_REGION }} + ECHOION_COMPONENT_SSH_KEY: ${{ secrets.RELEASE_CHECKOUT_SSH_KEY }} + ECHOION_DISTRIBUTION_BASE_URL: ${{ vars.ECHOION_DISTRIBUTION_BASE_URL }} + ECHOION_FEED_BASE_URL: ${{ vars.ECHOION_FEED_BASE_URL }} + ECHOION_FEED_COMMIT_SIGNING_KEY: ${{ secrets.RELEASE_FEED_GIT_SIGNING_KEY }} + ECHOION_FEED_PRIVATE_KEY: ${{ secrets.RELEASE_FEED_ED25519_PRIVATE_KEY }} + ECHOION_FEED_REPOSITORY: ssh://gitea@git.faumaray.ru/Void/Echoion.git + ECHOION_FEED_SIGNING_KEY_ID: ${{ vars.ECHOION_FEED_SIGNING_KEY_ID }} + ECHOION_OBJECT_STORAGE_BUCKET: ${{ vars.COMPONENT_OBJECT_STORAGE_BUCKET }} + ECHOION_OBJECT_STORAGE_ENDPOINT: ${{ vars.COMPONENT_OBJECT_STORAGE_ENDPOINT }} + ECHOION_OBJECT_STORAGE_PREFIX: ${{ vars.COMPONENT_OBJECT_STORAGE_PREFIX }} + ECHOION_RELEASE_TAG_ALLOWED_SIGNERS: ${{ secrets.RELEASE_TAG_ALLOWED_SIGNERS }} + GITEA_API_URL: ${{ gitea.api_url }} + GITEA_EVENT_NAME: ${{ gitea.event_name }} + GITEA_REF_NAME: ${{ gitea.ref_name }} + GITEA_RUN_NUMBER: ${{ gitea.run_number }} + GITEA_SHA: ${{ gitea.sha }} + GITEA_REPOSITORY: ${{ gitea.repository }} + GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }} + RELEASE_TOOLS_REF: ${{ vars.ECHOION_RELEASE_TOOLS_REF }} + run: | + set -euo pipefail + [[ "$RELEASE_TOOLS_REF" =~ ^[0-9a-f]{40}$ ]] + test "$(git -C .echoion-release-tools rev-parse HEAD)" = "$RELEASE_TOOLS_REF" + .echoion-release-tools/scripts/release-component.sh component.release.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 71040f6..b0913a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,12 @@ cmake_minimum_required(VERSION 4.0.0) if(NOT DEFINED ECHOION_PRODUCT_VERSION) - set(ECHOION_PRODUCT_VERSION 2.0.0) + set(ECHOION_PRODUCT_VERSION 0.0.0) +endif() +if(NOT DEFINED ECHOION_COMPONENT_VERSION) + set(ECHOION_COMPONENT_VERSION "${ECHOION_PRODUCT_VERSION}") endif() project(EchoionPluginUrlShortenerExternal - VERSION "${ECHOION_PRODUCT_VERSION}" LANGUAGES CXX) + VERSION "${ECHOION_COMPONENT_VERSION}" LANGUAGES CXX) include(GNUInstallDirs) @@ -42,7 +45,11 @@ target_include_directories(EchoionUrlShortenerExternalPlugin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_compile_features(EchoionUrlShortenerExternalPlugin PRIVATE cxx_std_26) target_compile_definitions(EchoionUrlShortenerExternalPlugin PRIVATE - "ECHOION_COMPONENT_VERSION=\"${PROJECT_VERSION}\"") + "ECHOION_COMPONENT_VERSION=\"${PROJECT_VERSION}\"" + ECHOION_COMPONENT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} + ECHOION_COMPONENT_VERSION_MINOR=${PROJECT_VERSION_MINOR} + ECHOION_COMPONENT_VERSION_PATCH=${PROJECT_VERSION_PATCH} + ECHOION_MODULE_BUILD) target_link_libraries(EchoionUrlShortenerExternalPlugin PRIVATE Echoion::ApiPlugin Echoion::ApiConfig diff --git a/abi/module.json b/abi/module.json index 0488364..abc981e 100644 --- a/abi/module.json +++ b/abi/module.json @@ -1,14 +1,16 @@ { "schemaVersion": 1, "contractId": "echoion.plugin.url-shortener-external", - "descriptor": "Void::Plugin::ModuleDescriptor", + "descriptor": "echoion_module_descriptor_v1", + "querySymbol": "echoion_module_abi_query", "moduleId": "url-shortener-external", "activationPolicy": "reloadable", "services": [ { "id": "void.short-url", "version": 1, - "type": "Void::ShortUrl::IShortener" + "contract": "void.short-url.v1", + "transport": "opaque-service-table" } ] } diff --git a/component.release.json b/component.release.json new file mode 100644 index 0000000..25e28aa --- /dev/null +++ b/component.release.json @@ -0,0 +1,7 @@ +{ + "schemaVersion": 1, + "componentId": "EchoionPluginUrlShortenerExternal", + "productCompatibility": ">=2.0.0 <3.0.0", + "publishNightly": true, + "cmakeOptions": {} +} diff --git a/src/ExternalShortener.cpp b/src/ExternalShortener.cpp index f835bb2..1e5a995 100644 --- a/src/ExternalShortener.cpp +++ b/src/ExternalShortener.cpp @@ -415,6 +415,8 @@ namespace Echoion::Plugins::ShortUrl Void::Net::Request request{ .method = config.method, .url = std::move(*endpoint), + .headers = {}, + .body = {}, .timeout = std::chrono::seconds{config.timeoutSeconds}, }; for (const auto& header : config.headers) { @@ -580,11 +582,17 @@ namespace Echoion::Plugins::ShortUrl std::string message, const std::uint32_t retryAfter = 0) { - return {.error = { + return { + .short_url = {}, + .key = {}, + .expires_at_unix_seconds = {}, + .error = + { .code = code, .message = std::move(message), .retry_after_seconds = retryAfter, - }}; + }, + }; } [[nodiscard]] std::uint32_t @@ -885,6 +893,8 @@ namespace Echoion::Plugins::ShortUrl return { .short_url = *cached, .key = keyFromUrl(*cached), + .expires_at_unix_seconds = {}, + .error = {}, }; } @@ -900,6 +910,8 @@ namespace Echoion::Plugins::ShortUrl return { .short_url = *cached, .key = keyFromUrl(*cached), + .expires_at_unix_seconds = {}, + .error = {}, }; } @@ -1049,6 +1061,8 @@ namespace Echoion::Plugins::ShortUrl return { .short_url = std::move(*extracted), .key = key, + .expires_at_unix_seconds = {}, + .error = {}, }; } } diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 93bea7b..c2d0883 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,7 @@ namespace Echoion::Plugins::ShortUrl return kPluginId; } - void applyConfig(const char* config) + void applyConfig(const char *config) { configPayload_ = config != nullptr ? config : ""; } @@ -81,7 +82,7 @@ namespace Echoion::Plugins::ShortUrl } [[nodiscard]] Void::ShortUrl::ShortenResult - shorten(const Void::ShortUrl::ShortenRequest& request) override + shorten(const Void::ShortUrl::ShortenRequest &request) override { if (shortener_ == nullptr) { return { @@ -111,17 +112,25 @@ namespace Echoion::Plugins::ShortUrl return std::make_unique(); } - const Void::Plugin::ModuleDescriptor& moduleDescriptor() + const Void::Plugin::ModuleDescriptor &moduleDescriptor() { static const Void::Plugin::ModuleDescriptor descriptor{ .module_id = "url-shortener-external", - .component_version = {.major = 2, .minor = 0, .patch = 0}, - .abi_hash = - "sha256:251e3fa0ee8228cb2eb79b399deee58524b64fbb4764c8a2644357b3502354fe", + .component_version = + { + .major = ECHOION_COMPONENT_VERSION_MAJOR, + .minor = ECHOION_COMPONENT_VERSION_MINOR, + .patch = ECHOION_COMPONENT_VERSION_PATCH, + .pre_release = {}, + .build = {}, + }, + .abi_hash = "sha256:" + "6f6e445a86fc6a67e25dbd0e1f583de9f768f6f4ba88ed2f2ffe6d" + "0540eb85ea", .abi_contract = Void::Json::object({ {"schemaVersion", 1}, {"contractId", "echoion.plugin.url-shortener-external"}, - {"descriptor", "Void::Plugin::ModuleDescriptor"}, + {"descriptor", "echoion_module_descriptor_v1"}, }), .dependencies = { @@ -129,7 +138,9 @@ namespace Echoion::Plugins::ShortUrl .module_id = "EchoionApi", .version_range = "^2.0.0", .abi_hash = - "sha256:336492a52097dd12f222bb6d9acab19e8eb6a502eab45bb78127bce6d733fbd3", + "sha256:" + "d50293d345a97e52f9844088bdd42277f566bc815a21b763" + "6d3e053f06c6c113", }, }, .activation_policy = Void::Plugin::ActivationPolicy::Reloadable, @@ -138,26 +149,84 @@ namespace Echoion::Plugins::ShortUrl return descriptor; } + const echoion_module_descriptor_v1 &moduleAbiDescriptor() + { + using Bridge = Api::Module::LegacyModuleAbi; + static const echoion_module_dependency_v1 dependencies[]{ + { + .struct_size = sizeof(echoion_module_dependency_v1), + .component_id = Api::Module::Detail::stringView("EchoionApi"), + .version_range = + Api::Module::Detail::stringView(">=2.0.0 <3.0.0"), + .abi_hash = Api::Module::Detail::stringView( + "sha256:" + "d50293d345a97e52f9844088bdd42277f566bc815a21b7636d3e053f06" + "c6c11" + "3"), + .optional = 0, + .reserved_bytes = {}, + }, + { + .struct_size = sizeof(echoion_module_dependency_v1), + .component_id = Api::Module::Detail::stringView("EchoionCore"), + .version_range = + Api::Module::Detail::stringView(">=2.0.0 <3.0.0"), + .abi_hash = Api::Module::Detail::stringView( + "sha256:" + "9cb668e2a502dcfe02d145ed63635d63619732d77ff574968583438270" + "5e8d2" + "1"), + .optional = 0, + .reserved_bytes = {}, + }, + }; + static const echoion_module_descriptor_v1 descriptor{ + .struct_size = sizeof(echoion_module_descriptor_v1), + .abi_version = ECHOION_MODULE_ABI_VERSION, + .component_id = Api::Module::Detail::stringView( + "EchoionPluginUrlShortenerExternal"), + .version_major = ECHOION_COMPONENT_VERSION_MAJOR, + .version_minor = ECHOION_COMPONENT_VERSION_MINOR, + .version_patch = ECHOION_COMPONENT_VERSION_PATCH, + .version_prerelease = {}, + .abi_hash = Api::Module::Detail::stringView( + "sha256:" + "6f6e445a86fc6a67e25dbd0e1f583de9f768f6f4ba88ed2f2ffe6d0540eb85" + "ea"), + .dependencies = dependencies, + .dependency_count = std::size(dependencies), + .activation_policy = ECHOION_ACTIVATION_RELOADABLE_V1, + .api = &Bridge::api, + .reserved = {}, + }; + return descriptor; + } + } // namespace Echoion::Plugins::ShortUrl extern "C" { -const Void::Plugin::ModuleDescriptor* echoion_module_query() +const Void::Plugin::ModuleDescriptor *echoion_module_query() { return &Echoion::Plugins::ShortUrl::moduleDescriptor(); } -void* void_plugin_create() +const echoion_module_descriptor_v1 *echoion_module_abi_query() +{ + return &Echoion::Plugins::ShortUrl::moduleAbiDescriptor(); +} + +void *void_plugin_create() { return std::make_unique< Echoion::Plugins::ShortUrl::ExternalShortenerPlugin>() .release(); } -void void_plugin_destroy(void* instance) +void void_plugin_destroy(void *instance) { std::unique_ptr{ - static_cast( + static_cast( instance)}; } @@ -171,28 +240,28 @@ Void::Plugin::PluginInfo void_plugin_info() }; } -void void_plugin_configure(void* instance, const char* config) +void void_plugin_configure(void *instance, const char *config) { - static_cast(instance) + static_cast(instance) ->applyConfig(config); } -int void_plugin_ready(void* instance) +int void_plugin_ready(void *instance) { - return static_cast( + return static_cast( instance) ->ready() ? 0 : 1; } -Void::Service::IService* void_plugin_service(void* instance) +Void::Service::IService *void_plugin_service(void *instance) { - auto* plugin = - static_cast( + auto *plugin = + static_cast( instance); - return static_cast( - static_cast(plugin)); + return static_cast( + static_cast(plugin)); } } // extern "C" diff --git a/tests/ExternalShortenerTests.cpp b/tests/ExternalShortenerTests.cpp index 4762bc0..21a75a2 100644 --- a/tests/ExternalShortenerTests.cpp +++ b/tests/ExternalShortenerTests.cpp @@ -92,7 +92,9 @@ int main() Void::Net::Response jsonResponse{ .status = 200, + .headers = {}, .body = R"({"data":{"short":"https://sho.rt/Ab1"}})", + .elapsed = {}, }; auto extracted = (*shortener)->previewExtract(jsonResponse); check(extracted && *extracted == "https://sho.rt/Ab1", @@ -147,6 +149,8 @@ int main() Void::Net::Response headerResponse{ .status = 201, .headers = {{.name = "Location", .value = "https://sho.rt/Q1"}}, + .body = {}, + .elapsed = {}, }; auto header = (*queryShortener)->previewExtract(headerResponse); check(header && *header == "https://sho.rt/Q1",