Skip to content

Commit

Permalink
handshake extended to validate plugin version
Browse files Browse the repository at this point in the history
CURA-10619
  • Loading branch information
saumyaj3 committed Aug 15, 2023
1 parent 9a34ce1 commit c81cbac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/plugin/broadcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/asio/awaitable.hpp>
#include <spdlog/spdlog.h>

#include <coroutine>
#include <functional>
#include <memory>
#include <unordered_map>
Expand Down
11 changes: 11 additions & 0 deletions include/plugin/handshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include "cura/plugins/slots/handshake/v0/handshake.grpc.pb.h"
#include "cura/plugins/v0/slot_id.pb.h"
#include "plugin/metadata.h"
#include "plugin/settings.h"

#include <agrpc/rpc.hpp>
#include <boost/asio/awaitable.hpp>
#include <spdlog/spdlog.h>

#include <coroutine>
#include <string_view>

namespace plugin
Expand Down Expand Up @@ -36,9 +38,18 @@ struct Handshake
request,
writer,
boost::asio::use_awaitable);

spdlog::info("Received handshake request");
spdlog::info("Slot ID: {}, slot version range: {}, plugin name: {}, plugin version: {}", static_cast<int>(request.slot_id()), request.version_range(), request.plugin_name(), request.plugin_version());

const bool exists = Settings::validatePlugin(request, metadata);
if (!exists)
{
grpc::Status status = grpc::Status(grpc::StatusCode::INTERNAL, "Plugin could not be validated, handshake failed!");
co_await agrpc::finish_with_error(writer, status, boost::asio::use_awaitable);
continue;
}

cura::plugins::slots::handshake::v0::CallResponse response;
response.set_plugin_name(static_cast<std::string>(metadata->plugin_name));
response.set_slot_version(static_cast<std::string>(metadata->slot_version));
Expand Down
12 changes: 11 additions & 1 deletion include/plugin/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ struct Settings
return std::nullopt;
}

static bool validatePlugin(const cura::plugins::slots::handshake::v0::CallRequest& request, const std::shared_ptr<Metadata>& metadata)
{
if (request.plugin_name() == metadata->plugin_name && request.plugin_version() == metadata->plugin_version)
{
return true;
}
return false;

}
static std::string settingKey(std::string_view short_key, std::string_view name, std::string_view version)
{
std::string lower_name{ name };
Expand All @@ -73,7 +81,9 @@ struct Settings
{
return std::tolower(c);
});
return fmt::format("_plugin__{}__{}_{}_{}__{}", lower_name, semantic_version.major, semantic_version.minor, semantic_version.patch, short_key);
auto generated_key = fmt::format("_plugin__{}__{}_{}_{}__{}", lower_name, semantic_version.major, semantic_version.minor, semantic_version.patch, short_key);
spdlog::info("generated key is {}", generated_key);
return generated_key;
}
};

Expand Down

0 comments on commit c81cbac

Please sign in to comment.