Skip to content

Commit

Permalink
Saving endpoint and initializes a flag to know if it is https or not.
Browse files Browse the repository at this point in the history
  • Loading branch information
fdenefaneo committed Feb 16, 2024
1 parent 4adebe7 commit 8f93667
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ArmoniK.SDK.Client/private/ChannelPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class ChannelPool {
std::mutex channel_mutex_;
armonik::api::common::logger::LocalLogger logger_;
std::shared_ptr<grpc::ChannelCredentials> credentials_{nullptr};
std::string endpoint;
bool is_https{false};
};

} // namespace Internal
Expand Down
27 changes: 21 additions & 6 deletions ArmoniK.SDK.Client/src/ChannelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ std::shared_ptr<grpc::Channel> ChannelPool::AcquireChannel() {
return channel;
}
}
std::string endpoint(properties_.configuration.get_control_plane().getEndpoint());
auto scheme_delim = endpoint.find("://");
if (scheme_delim != std::string::npos) {
endpoint = endpoint.substr(scheme_delim + 3);
}

// TODO Handle TLS
channel = grpc::CreateCustomChannel(
endpoint, credentials_,
Expand Down Expand Up @@ -91,13 +87,32 @@ absl::optional<std::string> get_key(const absl::string_view &path) {
}
}

void initialize_protocol_endpoint(const Common::Properties &properties_, std::string &endpoint, bool &is_https) {
absl::string_view endpoint_view = properties_.configuration.get_control_plane().getEndpoint();
std::string protocol;
protocol.reserve(5);
const auto delim = endpoint_view.find("://");
if (delim != absl::string_view::npos) {
const auto tmp = endpoint_view.substr(delim);
endpoint = {tmp.cbegin(), tmp.cend()};
endpoint_view = endpoint_view.substr(0, delim);

std::transform(endpoint_view.cbegin(), endpoint_view.cend(), std::back_inserter(protocol),
[](const char c) -> char { return static_cast<char>(tolower(c)); });
}
is_https = protocol.back() == 's';
}

ChannelPool::ChannelPool(ArmoniK::Sdk::Common::Properties properties, armonik::api::common::logger::Logger &logger)
: properties_(std::move(properties)), logger_(logger.local()) {
const auto &control_plane = properties_.configuration.get_control_plane();

initialize_protocol_endpoint(properties_, endpoint, is_https);

auto root_cert_pem = get_key(control_plane.getCaCertPemPath());
auto user_private_pem = get_key(control_plane.getUserKeyPemPath());
auto user_public_pem = get_key(control_plane.getUserCertPemPath());
if (user_public_pem && user_private_pem) {
if (user_public_pem && user_private_pem && is_https) {
if (!root_cert_pem) {
logger_.log(armonik::api::common::logger::Level::Info, "No path for root certificate provided.");
}
Expand Down

0 comments on commit 8f93667

Please sign in to comment.