Skip to content
Merged
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
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,19 @@ set(models_source_files
src/binsrv/models/binlog_file_record_fwd.hpp
src/binsrv/models/binlog_file_record.hpp

src/binsrv/models/binlog_file_encryption_record_fwd.hpp
src/binsrv/models/binlog_file_encryption_record.hpp

src/binsrv/models/error_response_fwd.hpp
src/binsrv/models/error_response.hpp
src/binsrv/models/error_response.cpp

src/binsrv/models/file_data_envelope_record_fwd.hpp
src/binsrv/models/file_data_envelope_record.hpp

src/binsrv/models/file_key_envelope_record_fwd.hpp
src/binsrv/models/file_key_envelope_record.hpp

src/binsrv/models/response_status_type_fwd.hpp
src/binsrv/models/response_status_type.hpp

Expand Down Expand Up @@ -455,9 +464,6 @@ set(binsrv_source_files
src/binsrv/binlog_file_metadata.hpp
src/binsrv/binlog_file_metadata.cpp

src/binsrv/binlog_file_encryption_metadata_fwd.hpp
src/binsrv/binlog_file_encryption_metadata.hpp

src/binsrv/cout_logger.hpp
src/binsrv/cout_logger.cpp

Expand All @@ -471,12 +477,6 @@ set(binsrv_source_files
src/binsrv/exception_handling_helpers.hpp
src/binsrv/exception_handling_helpers.cpp

src/binsrv/file_data_envelope_fwd.hpp
src/binsrv/file_data_envelope.hpp

src/binsrv/file_key_envelope_fwd.hpp
src/binsrv/file_key_envelope.hpp

src/binsrv/file_keyring.hpp
src/binsrv/file_keyring.cpp

Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,19 @@ may print
"min_timestamp": "2026-02-09T17:22:01",
"max_timestamp": "2026-02-09T17:22:08",
"previous_gtids": "",
"added_gtids": "11111111-aaaa-1111-aaaa-111111111111:1-123456"
"added_gtids": "11111111-aaaa-1111-aaaa-111111111111:1-123456",
"encryption": {
"file_key_envelope": {
"kek_id": "beta",
"data_hex": "A4F6F06C40C44538BB9DE0A468D1708A",
"iv_hex": "52A9AF1A96B5ACB05F6FD720",
"tag_hex": "000102030405060708090A0B0C0D0E0F"
},
"file_data_envelope": {
"cipher": "AES-128-CTR",
"iv_hex": "4515D10B1607C71C6CA883B052A9AF1A"
}
}
},
{
"name": "binlog.000002",
Expand All @@ -214,7 +226,19 @@ may print
"min_timestamp": "2026-02-09T17:22:08",
"max_timestamp": "2026-02-09T17:22:09",
"previous_gtids": "11111111-aaaa-1111-aaaa-111111111111:1-123456",
"added_gtids": "11111111-aaaa-1111-aaaa-111111111111:123457-246912"
"added_gtids": "11111111-aaaa-1111-aaaa-111111111111:123457-246912",
"encryption": {
"file_key_envelope": {
"kek_id": "beta",
"data_hex": "BB9DE0A468D1708AA4F6F06C40C44538",
"iv_hex": "ACB05F6FD72052A9AF1A96B5",
"tag_hex": "000102030405060708090A0B0C0D0E0F"
},
"file_data_envelope": {
"cipher": "AES-128-CTR",
"iv_hex": "6CA883B052A9AF1A4515D10B1607C71C"
}
}
}
]
}
Expand Down
22 changes: 16 additions & 6 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "binsrv/gtids/common_types.hpp"
#include "binsrv/gtids/gtid_set.hpp"

#include "binsrv/models/binlog_file_record.hpp"
#include "binsrv/models/error_response.hpp"
#include "binsrv/models/response_status_type.hpp"
#include "binsrv/models/search_response.hpp"
Expand Down Expand Up @@ -995,12 +996,21 @@ bool handle_version() {
// a record of the response model
void append_record_to_response(binsrv::models::search_response &response,
const binsrv::storage &storage,
const auto &record) {
response.add_record(record.name.str(), record.size,
storage.get_binlog_uri(record.name),
record.previous_gtids, record.added_gtids,
record.timestamps.get_min_timestamp().get_value(),
record.timestamps.get_max_timestamp().get_value());
const binsrv::storage::binlog_record &record) {
binsrv::models::binlog_file_record model_record{
{{record.name.str()},
{record.size},
{storage.get_binlog_uri(record.name)},
{record.previous_gtids},
{record.added_gtids},
{record.timestamps.get_min_timestamp()},
{record.timestamps.get_max_timestamp()},
{record.encryption.has_value()
? binsrv::storage::binlog_encryption_record::to_model(
*record.encryption)
: binsrv::models::optional_binlog_file_encryption_record{}}}};

response.add_record(std::move(model_record));
}

bool handle_list(std::string_view config_file_path) {
Expand Down
6 changes: 3 additions & 3 deletions src/binsrv/binlog_file_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#include <string>
#include <string_view>

#include "binsrv/binlog_file_encryption_metadata.hpp" // IWYU pragma: export

#include "binsrv/events/common_types.hpp"

#include "binsrv/gtids/gtid_set.hpp"

#include "binsrv/models/binlog_file_encryption_record.hpp" // IWYU pragma: export

#include "util/ctime_timestamp.hpp"
#include "util/nv_tuple.hpp"

Expand All @@ -50,7 +50,7 @@ class [[nodiscard]] binlog_file_metadata {
util::nv<"min_timestamp", util::ctime_timestamp>,
util::nv<"max_timestamp", util::ctime_timestamp>,
util::nv<"last_sequence_number", events::seq_no_t>,
util::nv<"encryption", optional_binlog_file_encryption_metadata>
util::nv<"encryption", models::optional_binlog_file_encryption_record>
// clang-format on
>;

Expand Down
2 changes: 1 addition & 1 deletion src/binsrv/events/unknown_body_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ std::ostream &operator<<(std::ostream &output, const unknown_body &obj);

} // namespace binsrv::events

#endif // BINSRV_EVENTS_UNKNOWN_BODY_FWD_HPPß
#endif // BINSRV_EVENTS_UNKNOWN_BODY_FWD_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BINSRV_BINLOG_FILE_ENCRYPTION_METADATA_HPP
#define BINSRV_BINLOG_FILE_ENCRYPTION_METADATA_HPP
#ifndef BINSRV_MODELS_BINLOG_FILE_ENCRYPTION_RECORD_HPP
#define BINSRV_MODELS_BINLOG_FILE_ENCRYPTION_RECORD_HPP

#include "binsrv/binlog_file_encryption_metadata_fwd.hpp" // IWYU pragma: export
#include "binsrv/models/binlog_file_encryption_record_fwd.hpp" // IWYU pragma: export

#include "binsrv/file_data_envelope.hpp" // IWYU pragma: export
#include "binsrv/file_key_envelope.hpp" // IWYU pragma: export
#include "binsrv/models/file_data_envelope_record.hpp" // IWYU pragma: export
#include "binsrv/models/file_key_envelope_record.hpp" // IWYU pragma: export

#include "util/nv_tuple.hpp"

namespace binsrv {
namespace binsrv::models {

class [[nodiscard]] binlog_file_encryption_metadata
class [[nodiscard]] binlog_file_encryption_record
: public util::nv_tuple<
// clang-format off
util::nv<"file_key_envelope", file_key_envelope>,
util::nv<"file_data_envelope", file_data_envelope>
util::nv<"file_key_envelope", file_key_envelope_record>,
util::nv<"file_data_envelope", file_data_envelope_record>
// clang-format on
> {};

} // namespace binsrv
} // namespace binsrv::models

#endif // BINSRV_BINLOG_FILE_ENCRYPTION_METADATA_HPP
#endif // BINSRV_MODELS_BINLOG_FILE_ENCRYPTION_RECORD_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BINSRV_BINLOG_FILE_ENCRYPTION_METADATA_FWD_HPP
#define BINSRV_BINLOG_FILE_ENCRYPTION_METADATA_FWD_HPP
#ifndef BINSRV_MODELS_BINLOG_FILE_ENCRYPTION_RECORD_FWD_HPP
#define BINSRV_MODELS_BINLOG_FILE_ENCRYPTION_RECORD_FWD_HPP

#include <optional>

namespace binsrv {
namespace binsrv::models {

class binlog_file_encryption_metadata;
using optional_binlog_file_encryption_metadata =
std::optional<binlog_file_encryption_metadata>;
class binlog_file_encryption_record;
using optional_binlog_file_encryption_record =
std::optional<binlog_file_encryption_record>;

} // namespace binsrv
} // namespace binsrv::models

#endif // BINSRV_BINLOG_FILE_ENCRYPTION_METADATA_FWD_HPP
#endif // BINSRV_MODELS_BINLOG_FILE_ENCRYPTION_RECORD_FWD_HPP
5 changes: 4 additions & 1 deletion src/binsrv/models/binlog_file_record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "binsrv/gtids/gtid_set.hpp"

#include "binsrv/models/binlog_file_encryption_record.hpp" // IWYU pragma: export

#include "util/ctime_timestamp.hpp"
#include "util/nv_tuple.hpp"

Expand All @@ -37,7 +39,8 @@ struct [[nodiscard]] binlog_file_record
util::nv<"previous_gtids", gtids::optional_gtid_set>,
util::nv<"added_gtids", gtids::optional_gtid_set>,
util::nv<"min_timestamp", util::ctime_timestamp>,
util::nv<"max_timestamp", util::ctime_timestamp>
util::nv<"max_timestamp", util::ctime_timestamp>,
util::nv<"encryption", optional_binlog_file_encryption_record>
// clang-format on
> {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BINSRV_FILE_DATA_ENVELOPE_HPP
#define BINSRV_FILE_DATA_ENVELOPE_HPP
#ifndef BINSRV_MODELS_FILE_DATA_ENVELOPE_RECORD_HPP
#define BINSRV_MODELS_FILE_DATA_ENVELOPE_RECORD_HPP

#include "binsrv/file_data_envelope_fwd.hpp" // IWYU pragma: export
#include "binsrv/models/file_data_envelope_record_fwd.hpp" // IWYU pragma: export

#include <string>

#include "util/hex_value.hpp"
#include "util/nv_tuple.hpp"

namespace binsrv {
namespace binsrv::models {

class [[nodiscard]] file_data_envelope
: public util::nv_tuple<
struct [[nodiscard]] file_data_envelope_record
: util::nv_tuple<
// clang-format off
util::nv<"cipher", std::string>,
util::nv<"iv_hex", util::hex_value>,
util::nv<"tag_hex", util::optional_hex_value>
// clang-format on
> {};

} // namespace binsrv
} // namespace binsrv::models

#endif // BINSRV_FILE_DATA_ENVELOPE_HPP
#endif // BINSRV_MODELS_FILE_DATA_ENVELOPE_RECORD_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BINSRV_FILE_DATA_ENVELOPE_FWD_HPP
#define BINSRV_FILE_DATA_ENVELOPE_FWD_HPP
#ifndef BINSRV_MODELS_FILE_DATA_ENVELOPE_RECORD_FWD_HPP
#define BINSRV_MODELS_FILE_DATA_ENVELOPE_RECORD_FWD_HPP

namespace binsrv {
namespace binsrv::models {

class file_data_envelope;
struct file_data_envelope_record;

} // namespace binsrv
} // namespace binsrv::models

#endif // BINSRV_FILE_DATA_ENVELOPE_FWD_HPP
#endif // BINSRV_MODELS_FILE_DATA_ENVELOPE_RECORD_FWD_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BINSRV_FILE_KEY_ENVELOPE_HPP
#define BINSRV_FILE_KEY_ENVELOPE_HPP
#ifndef BINSRV_MODELS_FILE_KEY_ENVELOPE_RECORD_HPP
#define BINSRV_MODELS_FILE_KEY_ENVELOPE_RECORD_HPP

#include "binsrv/file_key_envelope_fwd.hpp" // IWYU pragma: export
#include "binsrv/models/file_key_envelope_record_fwd.hpp" // IWYU pragma: export

#include <string>

#include "util/hex_value.hpp"
#include "util/nv_tuple.hpp"

namespace binsrv {
namespace binsrv::models {

class [[nodiscard]] file_key_envelope
: public util::nv_tuple<
struct [[nodiscard]] file_key_envelope_record
: util::nv_tuple<
// clang-format off
util::nv<"kek_id", std::string>,
util::nv<"data_hex", util::hex_value>,
Expand All @@ -35,6 +35,6 @@ class [[nodiscard]] file_key_envelope
// clang-format on
> {};

} // namespace binsrv
} // namespace binsrv::models

#endif // BINSRV_FILE_KEY_ENVELOPE_HPP
#endif // BINSRV_MODELS_FILE_KEY_ENVELOPE_RECORD_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

#ifndef BINSRV_FILE_KEY_ENVELOPE_FWD_HPP
#define BINSRV_FILE_KEY_ENVELOPE_FWD_HPP
#ifndef BINSRV_MODELS_FILE_KEY_ENVELOPE_RECORD_FWD_HPP
#define BINSRV_MODELS_FILE_KEY_ENVELOPE_RECORD_FWD_HPP

namespace binsrv {
namespace binsrv::models {

class file_key_envelope;
struct file_key_envelope_record;

} // namespace binsrv
} // namespace binsrv::models

#endif // BINSRV_FILE_KEY_ENVELOPE_FWD_HPP
#endif // BINSRV_MODELS_FILE_KEY_ENVELOPE_RECORD_FWD_HPP
17 changes: 1 addition & 16 deletions src/binsrv/models/search_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "binsrv/models/search_response.hpp"

#include <cstdint>
#include <ctime>
#include <string>
#include <string_view>
Expand All @@ -24,8 +23,6 @@
#include <boost/json/serialize.hpp>
#include <boost/json/value.hpp>

#include "binsrv/gtids/gtid_set.hpp"

#include "binsrv/models/binlog_file_record.hpp"
#include "binsrv/models/response_status_type.hpp"

Expand Down Expand Up @@ -60,19 +57,7 @@ search_response::~search_response() = default;
return boost::json::serialize(json_value);
}

void search_response::add_record(std::string_view name, std::uint64_t size,
std::string_view uri,
gtids::optional_gtid_set previous_gtids,
gtids::optional_gtid_set added_gtids,
std::time_t min_timestamp,
std::time_t max_timestamp) {
binlog_file_record record{{{std::string{name}},
{size},
{std::string{uri}},
{std::move(previous_gtids)},
{std::move(added_gtids)},
{util::ctime_timestamp{min_timestamp}},
{util::ctime_timestamp{max_timestamp}}}};
void search_response::add_record(binlog_file_record record) {
impl_.template get<"result">().emplace_back(std::move(record));
}

Expand Down
7 changes: 1 addition & 6 deletions src/binsrv/models/search_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ class [[nodiscard]] search_response {

[[nodiscard]] auto &root() noexcept { return impl_; }

// 'previous_gtids' and 'added_gtids' are deliberately taken by value as we
// are going to move from them
void add_record(std::string_view name, std::uint64_t size,
std::string_view uri, gtids::optional_gtid_set previous_gtids,
gtids::optional_gtid_set added_gtids,
std::time_t min_timestamp, std::time_t max_timestamp);
void add_record(binlog_file_record record);

private:
impl_type impl_;
Expand Down
Loading
Loading