Include instance id token in Cloud host heartbeats
Bug: 388885661 Change-Id: Id8067f6baa17694f1054cd1fd81eed96f4be343c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6302194 Reviewed-by: Gary Kacmarcik <garykac@chromium.org> Commit-Queue: Joe Downing <joedow@chromium.org> Cr-Commit-Position: refs/heads/main@{#1424639}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7cfd981752
commit
d3480205e1
@@ -335,11 +335,13 @@ void CloudServiceClient::ProvisionGceInstance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CloudServiceClient::SendHeartbeat(const std::string& directory_id,
|
void CloudServiceClient::SendHeartbeat(const std::string& directory_id,
|
||||||
|
std::string_view instance_identity_token,
|
||||||
SendHeartbeatCallback callback) {
|
SendHeartbeatCallback callback) {
|
||||||
constexpr char path[] = "/v1alpha/access:sendHeartbeat";
|
constexpr char path[] = "/v1alpha/access:sendHeartbeat";
|
||||||
|
|
||||||
auto request = std::make_unique<SendHeartbeatRequest>();
|
auto request = std::make_unique<SendHeartbeatRequest>();
|
||||||
request->set_directory_id(directory_id);
|
request->set_directory_id(directory_id);
|
||||||
|
request->set_instance_identity_token(instance_identity_token);
|
||||||
|
|
||||||
ExecuteRequest(kSendHeartbeatTrafficAnnotation, path, /*api_key=*/"",
|
ExecuteRequest(kSendHeartbeatTrafficAnnotation, path, /*api_key=*/"",
|
||||||
net::HttpRequestHeaders::kPostMethod, std::move(request),
|
net::HttpRequestHeaders::kPostMethod, std::move(request),
|
||||||
@@ -353,6 +355,7 @@ void CloudServiceClient::UpdateRemoteAccessHost(
|
|||||||
std::optional<std::string> offline_reason,
|
std::optional<std::string> offline_reason,
|
||||||
std::optional<std::string> os_name,
|
std::optional<std::string> os_name,
|
||||||
std::optional<std::string> os_version,
|
std::optional<std::string> os_version,
|
||||||
|
std::string_view instance_identity_token,
|
||||||
UpdateRemoteAccessHostCallback callback) {
|
UpdateRemoteAccessHostCallback callback) {
|
||||||
constexpr char path[] = "/v1alpha/access:updateRemoteAccessHost";
|
constexpr char path[] = "/v1alpha/access:updateRemoteAccessHost";
|
||||||
|
|
||||||
@@ -381,6 +384,7 @@ void CloudServiceClient::UpdateRemoteAccessHost(
|
|||||||
host->mutable_operating_system_info()->set_name(*os_name);
|
host->mutable_operating_system_info()->set_name(*os_name);
|
||||||
host->mutable_operating_system_info()->set_version(*os_version);
|
host->mutable_operating_system_info()->set_version(*os_version);
|
||||||
}
|
}
|
||||||
|
host->set_instance_identity_token(instance_identity_token);
|
||||||
|
|
||||||
ExecuteRequest(kUpdateRemoteAccessHostTrafficAnnotation, path, /*api_key=*/"",
|
ExecuteRequest(kUpdateRemoteAccessHostTrafficAnnotation, path, /*api_key=*/"",
|
||||||
net::HttpRequestHeaders::kPatchMethod, std::move(host),
|
net::HttpRequestHeaders::kPatchMethod, std::move(host),
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "base/functional/callback_forward.h"
|
#include "base/functional/callback_forward.h"
|
||||||
#include "remoting/base/protobuf_http_client.h"
|
#include "remoting/base/protobuf_http_client.h"
|
||||||
@@ -99,6 +100,7 @@ class CloudServiceClient {
|
|||||||
ProvisionGceInstanceCallback callback);
|
ProvisionGceInstanceCallback callback);
|
||||||
|
|
||||||
void SendHeartbeat(const std::string& directory_id,
|
void SendHeartbeat(const std::string& directory_id,
|
||||||
|
std::string_view instance_identity_token,
|
||||||
SendHeartbeatCallback callback);
|
SendHeartbeatCallback callback);
|
||||||
|
|
||||||
void UpdateRemoteAccessHost(const std::string& directory_id,
|
void UpdateRemoteAccessHost(const std::string& directory_id,
|
||||||
@@ -107,6 +109,7 @@ class CloudServiceClient {
|
|||||||
std::optional<std::string> offline_reason,
|
std::optional<std::string> offline_reason,
|
||||||
std::optional<std::string> os_name,
|
std::optional<std::string> os_name,
|
||||||
std::optional<std::string> os_version,
|
std::optional<std::string> os_version,
|
||||||
|
std::string_view instance_identity_token,
|
||||||
UpdateRemoteAccessHostCallback callback);
|
UpdateRemoteAccessHostCallback callback);
|
||||||
|
|
||||||
void GenerateIceConfig(GenerateIceConfigCallback callback);
|
void GenerateIceConfig(GenerateIceConfigCallback callback);
|
||||||
|
@@ -51,6 +51,18 @@ void CloudHeartbeatServiceClient::SendFullHeartbeat(
|
|||||||
std::optional<std::string> signaling_id,
|
std::optional<std::string> signaling_id,
|
||||||
std::optional<std::string> offline_reason,
|
std::optional<std::string> offline_reason,
|
||||||
HeartbeatResponseCallback callback) {
|
HeartbeatResponseCallback callback) {
|
||||||
|
instance_identity_token_getter_->RetrieveToken(base::BindOnce(
|
||||||
|
&CloudHeartbeatServiceClient::SendFullHeartbeatWithIdToken,
|
||||||
|
weak_factory_.GetWeakPtr(), is_initial_heartbeat, std::move(signaling_id),
|
||||||
|
std::move(offline_reason), std::move(callback)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloudHeartbeatServiceClient::SendFullHeartbeatWithIdToken(
|
||||||
|
bool is_initial_heartbeat,
|
||||||
|
std::optional<std::string> signaling_id,
|
||||||
|
std::optional<std::string> offline_reason,
|
||||||
|
HeartbeatResponseCallback callback,
|
||||||
|
std::string_view instance_identity_token) {
|
||||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||||
|
|
||||||
if (offline_reason.has_value() && !offline_reason->empty()) {
|
if (offline_reason.has_value() && !offline_reason->empty()) {
|
||||||
@@ -58,18 +70,18 @@ void CloudHeartbeatServiceClient::SendFullHeartbeat(
|
|||||||
// just updating the Directory to indicate that, we don't need to send a
|
// just updating the Directory to indicate that, we don't need to send a
|
||||||
// heartbeat afterwards.
|
// heartbeat afterwards.
|
||||||
MakeUpdateRemoteAccessHostCall(
|
MakeUpdateRemoteAccessHostCall(
|
||||||
signaling_id, offline_reason,
|
signaling_id, offline_reason, instance_identity_token,
|
||||||
base::BindOnce(&CloudHeartbeatServiceClient::OnReportHostOffline,
|
base::BindOnce(&CloudHeartbeatServiceClient::OnReportHostOffline,
|
||||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||||
} else if (is_initial_heartbeat) {
|
} else if (is_initial_heartbeat) {
|
||||||
MakeUpdateRemoteAccessHostCall(
|
MakeUpdateRemoteAccessHostCall(
|
||||||
signaling_id, offline_reason,
|
signaling_id, offline_reason, instance_identity_token,
|
||||||
base::BindOnce(
|
base::BindOnce(
|
||||||
&CloudHeartbeatServiceClient::OnUpdateRemoteAccessHostResponse,
|
&CloudHeartbeatServiceClient::OnUpdateRemoteAccessHostResponse,
|
||||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||||
} else {
|
} else {
|
||||||
client_->SendHeartbeat(
|
client_->SendHeartbeat(
|
||||||
directory_id_,
|
directory_id_, instance_identity_token,
|
||||||
base::BindOnce(&CloudHeartbeatServiceClient::OnSendHeartbeatResponse,
|
base::BindOnce(&CloudHeartbeatServiceClient::OnSendHeartbeatResponse,
|
||||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||||
}
|
}
|
||||||
@@ -77,10 +89,18 @@ void CloudHeartbeatServiceClient::SendFullHeartbeat(
|
|||||||
|
|
||||||
void CloudHeartbeatServiceClient::SendLiteHeartbeat(
|
void CloudHeartbeatServiceClient::SendLiteHeartbeat(
|
||||||
HeartbeatResponseCallback callback) {
|
HeartbeatResponseCallback callback) {
|
||||||
|
instance_identity_token_getter_->RetrieveToken(
|
||||||
|
base::BindOnce(&CloudHeartbeatServiceClient::SendLiteHeartbeatWithIdToken,
|
||||||
|
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloudHeartbeatServiceClient::SendLiteHeartbeatWithIdToken(
|
||||||
|
HeartbeatResponseCallback callback,
|
||||||
|
std::string_view instance_identity_token) {
|
||||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||||
|
|
||||||
client_->SendHeartbeat(
|
client_->SendHeartbeat(
|
||||||
directory_id_,
|
directory_id_, instance_identity_token,
|
||||||
base::BindOnce(&CloudHeartbeatServiceClient::OnSendHeartbeatResponse,
|
base::BindOnce(&CloudHeartbeatServiceClient::OnSendHeartbeatResponse,
|
||||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||||
}
|
}
|
||||||
@@ -124,12 +144,13 @@ void CloudHeartbeatServiceClient::OnReportHostOffline(
|
|||||||
void CloudHeartbeatServiceClient::MakeUpdateRemoteAccessHostCall(
|
void CloudHeartbeatServiceClient::MakeUpdateRemoteAccessHostCall(
|
||||||
std::optional<std::string> signaling_id,
|
std::optional<std::string> signaling_id,
|
||||||
std::optional<std::string> offline_reason,
|
std::optional<std::string> offline_reason,
|
||||||
|
std::string_view instance_identity_token,
|
||||||
CloudServiceClient::UpdateRemoteAccessHostCallback callback) {
|
CloudServiceClient::UpdateRemoteAccessHostCallback callback) {
|
||||||
constexpr auto* host_version = STRINGIZE(VERSION);
|
constexpr auto* host_version = STRINGIZE(VERSION);
|
||||||
client_->UpdateRemoteAccessHost(directory_id_, host_version, signaling_id,
|
client_->UpdateRemoteAccessHost(directory_id_, host_version, signaling_id,
|
||||||
offline_reason, GetHostOperatingSystemName(),
|
offline_reason, GetHostOperatingSystemName(),
|
||||||
GetHostOperatingSystemVersion(),
|
GetHostOperatingSystemVersion(),
|
||||||
std::move(callback));
|
instance_identity_token, std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloudHeartbeatServiceClient::RunHeartbeatResponseCallback(
|
void CloudHeartbeatServiceClient::RunHeartbeatResponseCallback(
|
||||||
|
@@ -55,6 +55,15 @@ class CloudHeartbeatServiceClient : public HeartbeatServiceClient {
|
|||||||
void CancelPendingRequests() override;
|
void CancelPendingRequests() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Overloads used to create callbacks for |instance_identity_token_getter_|.
|
||||||
|
void SendFullHeartbeatWithIdToken(bool is_initial_heartbeat,
|
||||||
|
std::optional<std::string> signaling_id,
|
||||||
|
std::optional<std::string> offline_reason,
|
||||||
|
HeartbeatResponseCallback callback,
|
||||||
|
std::string_view instance_identity_token);
|
||||||
|
void SendLiteHeartbeatWithIdToken(HeartbeatResponseCallback callback,
|
||||||
|
std::string_view instance_identity_token);
|
||||||
|
|
||||||
void OnSendHeartbeatResponse(
|
void OnSendHeartbeatResponse(
|
||||||
HeartbeatResponseCallback callback,
|
HeartbeatResponseCallback callback,
|
||||||
const HttpStatus& status,
|
const HttpStatus& status,
|
||||||
@@ -75,6 +84,7 @@ class CloudHeartbeatServiceClient : public HeartbeatServiceClient {
|
|||||||
void MakeUpdateRemoteAccessHostCall(
|
void MakeUpdateRemoteAccessHostCall(
|
||||||
std::optional<std::string> signaling_id,
|
std::optional<std::string> signaling_id,
|
||||||
std::optional<std::string> offline_reason,
|
std::optional<std::string> offline_reason,
|
||||||
|
std::string_view instance_identity_token,
|
||||||
CloudServiceClient::UpdateRemoteAccessHostCallback callback);
|
CloudServiceClient::UpdateRemoteAccessHostCallback callback);
|
||||||
|
|
||||||
void RunHeartbeatResponseCallback(HeartbeatResponseCallback callback,
|
void RunHeartbeatResponseCallback(HeartbeatResponseCallback callback,
|
||||||
|
Reference in New Issue
Block a user