Harden external shortener and add component releases

This commit is contained in:
faumaray committed 2026-07-29 22:40:35 +03:00
1 parent 4492ef962e
commit 167757855f
7 files changed
+188 -29

No files matched your search

+56
View File
@@ -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
+10 -3
View File
@@ -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
+4 -2
View File
@@ -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"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
{
"schemaVersion": 1,
"componentId": "EchoionPluginUrlShortenerExternal",
"productCompatibility": ">=2.0.0 <3.0.0",
"publishNightly": true,
"cmakeOptions": {}
}
+16 -2
View File
@@ -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 = {},
};
}
}
+91 -22
View File
@@ -1,4 +1,4 @@
#include <echoion/api/module/Module.hpp>
#include <echoion/api/module/LegacyModuleAbi.hpp>
#include <echoion/plugins/short_url/ExternalShortener.hpp>
#include <ExtensionPlugin.hpp>
@@ -6,6 +6,7 @@
#include <Void/Service/Service.hpp>
#include <Void/ShortUrl/ShortUrl.hpp>
#include <iterator>
#include <memory>
#include <string>
#include <string_view>
@@ -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<ExternalShortenerPlugin>();
}
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<createModule>;
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<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin>{
static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin*>(
static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin *>(
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<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin*>(instance)
static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin *>(instance)
->applyConfig(config);
}
int void_plugin_ready(void* instance)
int void_plugin_ready(void *instance)
{
return static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin*>(
return static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin *>(
instance)
->ready()
? 0
: 1;
}
Void::Service::IService* void_plugin_service(void* instance)
Void::Service::IService *void_plugin_service(void *instance)
{
auto* plugin =
static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin*>(
auto *plugin =
static_cast<Echoion::Plugins::ShortUrl::ExternalShortenerPlugin *>(
instance);
return static_cast<Void::Service::IService*>(
static_cast<Void::ShortUrl::IShortener*>(plugin));
return static_cast<Void::Service::IService *>(
static_cast<Void::ShortUrl::IShortener *>(plugin));
}
} // extern "C"
+4
View File
@@ -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",