in cpp/acs_agent_helper.cc [163:193]
absl::StatusOr<AcsToken> ParseAcsToken(absl::string_view endpoint) {
absl::StatusOr<std::string> token = GetMetadata(endpoint);
if (!token.ok()) {
return token.status();
}
ABSL_VLOG(2) << "Successfully got token from metadata service: " << *token;
absl::StatusOr<std::string> instance_id = GetValueFromTokenPayloadWithKeys(
*token, {"google", "compute_engine", "instance_id"});
if (!instance_id.ok()) {
return instance_id.status();
}
ABSL_VLOG(2) << "Successfully got instance_id from metadata service: "
<< *instance_id;
absl::StatusOr<std::string> project_number = GetValueFromTokenPayloadWithKeys(
*token, {"google", "compute_engine", "project_number"});
if (!project_number.ok()) {
return project_number.status();
}
ABSL_VLOG(2) << "Successfully got project_number from metadata service: "
<< *project_number;
absl::StatusOr<std::string> zone = GetValueFromTokenPayloadWithKeys(
*token, {"google", "compute_engine", "zone"});
if (!zone.ok()) {
return zone.status();
}
ABSL_VLOG(2) << "Successfully got zone from metadata service: " << *zone;
return AcsToken{.token = *std::move(token),
.instance_id = *std::move(instance_id),
.project_number = *std::move(project_number),
.zone = *std::move(zone)};
}