Replace token file with Google auth in MapBuilder. (#1417)
This allows Cartographer to use normal Application Default Credentials (ADC) instead of a hand-generated format. Google-internally, we'll only use ADC going forward. At your option, I can keep the old code for the token files around if you think it would be generally useful. Many OSS programs follow the same approach.master
parent
1d20cef33e
commit
d6772cf274
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
#include "absl/memory/memory.h"
|
#include "absl/memory/memory.h"
|
||||||
#include "async_grpc/client.h"
|
#include "async_grpc/client.h"
|
||||||
#include "async_grpc/token_file_credentials.h"
|
|
||||||
#include "cartographer/cloud/internal/handlers/add_sensor_data_batch_handler.h"
|
#include "cartographer/cloud/internal/handlers/add_sensor_data_batch_handler.h"
|
||||||
#include "cartographer/cloud/internal/handlers/add_trajectory_handler.h"
|
#include "cartographer/cloud/internal/handlers/add_trajectory_handler.h"
|
||||||
#include "cartographer/cloud/internal/handlers/finish_trajectory_handler.h"
|
#include "cartographer/cloud/internal/handlers/finish_trajectory_handler.h"
|
||||||
|
@ -68,7 +67,7 @@ class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface {
|
||||||
public:
|
public:
|
||||||
LocalTrajectoryUploader(const std::string& uplink_server_address,
|
LocalTrajectoryUploader(const std::string& uplink_server_address,
|
||||||
int batch_size, bool enable_ssl_encryption,
|
int batch_size, bool enable_ssl_encryption,
|
||||||
const std::string& token_file_path);
|
bool enable_google_auth);
|
||||||
~LocalTrajectoryUploader();
|
~LocalTrajectoryUploader();
|
||||||
|
|
||||||
// Starts the upload thread.
|
// Starts the upload thread.
|
||||||
|
@ -108,19 +107,15 @@ class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface {
|
||||||
|
|
||||||
LocalTrajectoryUploader::LocalTrajectoryUploader(
|
LocalTrajectoryUploader::LocalTrajectoryUploader(
|
||||||
const std::string& uplink_server_address, int batch_size,
|
const std::string& uplink_server_address, int batch_size,
|
||||||
bool enable_ssl_encryption, const std::string& token_file_path)
|
bool enable_ssl_encryption, bool enable_google_auth)
|
||||||
: batch_size_(batch_size) {
|
: batch_size_(batch_size) {
|
||||||
auto channel_creds =
|
auto channel_creds =
|
||||||
enable_ssl_encryption
|
enable_google_auth
|
||||||
? ::grpc::SslCredentials(::grpc::SslCredentialsOptions())
|
? grpc::GoogleDefaultCredentials()
|
||||||
: ::grpc::InsecureChannelCredentials();
|
: (enable_ssl_encryption
|
||||||
|
? ::grpc::SslCredentials(::grpc::SslCredentialsOptions())
|
||||||
|
: ::grpc::InsecureChannelCredentials());
|
||||||
|
|
||||||
if (!token_file_path.empty()) {
|
|
||||||
auto call_creds = async_grpc::TokenFileCredentials(
|
|
||||||
token_file_path, std::chrono::seconds(kTokenRefreshIntervalInSeconds));
|
|
||||||
channel_creds =
|
|
||||||
grpc::CompositeChannelCredentials(channel_creds, call_creds);
|
|
||||||
}
|
|
||||||
client_channel_ = ::grpc::CreateChannel(uplink_server_address, channel_creds);
|
client_channel_ = ::grpc::CreateChannel(uplink_server_address, channel_creds);
|
||||||
std::chrono::system_clock::time_point deadline =
|
std::chrono::system_clock::time_point deadline =
|
||||||
std::chrono::system_clock::now() +
|
std::chrono::system_clock::now() +
|
||||||
|
@ -340,10 +335,10 @@ void LocalTrajectoryUploader::EnqueueSensorData(
|
||||||
|
|
||||||
std::unique_ptr<LocalTrajectoryUploaderInterface> CreateLocalTrajectoryUploader(
|
std::unique_ptr<LocalTrajectoryUploaderInterface> CreateLocalTrajectoryUploader(
|
||||||
const std::string& uplink_server_address, int batch_size,
|
const std::string& uplink_server_address, int batch_size,
|
||||||
bool enable_ssl_encryption, const std::string& token_file_path) {
|
bool enable_ssl_encryption, bool enable_google_auth) {
|
||||||
return make_unique<LocalTrajectoryUploader>(uplink_server_address, batch_size,
|
return make_unique<LocalTrajectoryUploader>(uplink_server_address, batch_size,
|
||||||
enable_ssl_encryption,
|
enable_ssl_encryption,
|
||||||
token_file_path);
|
enable_google_auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cloud
|
} // namespace cloud
|
||||||
|
|
|
@ -64,7 +64,7 @@ class LocalTrajectoryUploaderInterface {
|
||||||
// Returns LocalTrajectoryUploader with the actual implementation.
|
// Returns LocalTrajectoryUploader with the actual implementation.
|
||||||
std::unique_ptr<LocalTrajectoryUploaderInterface> CreateLocalTrajectoryUploader(
|
std::unique_ptr<LocalTrajectoryUploaderInterface> CreateLocalTrajectoryUploader(
|
||||||
const std::string& uplink_server_address, int batch_size,
|
const std::string& uplink_server_address, int batch_size,
|
||||||
bool enable_ssl_encryption, const std::string& token_file_path);
|
bool enable_ssl_encryption, bool enable_google_auth);
|
||||||
|
|
||||||
} // namespace cloud
|
} // namespace cloud
|
||||||
} // namespace cartographer
|
} // namespace cartographer
|
||||||
|
|
|
@ -68,7 +68,7 @@ MapBuilderServer::MapBuilderServer(
|
||||||
map_builder_server_options.uplink_server_address(),
|
map_builder_server_options.uplink_server_address(),
|
||||||
map_builder_server_options.upload_batch_size(),
|
map_builder_server_options.upload_batch_size(),
|
||||||
map_builder_server_options.enable_ssl_encryption(),
|
map_builder_server_options.enable_ssl_encryption(),
|
||||||
map_builder_server_options.token_file_path());
|
map_builder_server_options.enable_google_auth());
|
||||||
}
|
}
|
||||||
server_builder.RegisterHandler<handlers::AddTrajectoryHandler>();
|
server_builder.RegisterHandler<handlers::AddTrajectoryHandler>();
|
||||||
server_builder.RegisterHandler<handlers::AddOdometryDataHandler>();
|
server_builder.RegisterHandler<handlers::AddOdometryDataHandler>();
|
||||||
|
|
|
@ -41,8 +41,8 @@ proto::MapBuilderServerOptions CreateMapBuilderServerOptions(
|
||||||
lua_parameter_dictionary->GetInt("upload_batch_size"));
|
lua_parameter_dictionary->GetInt("upload_batch_size"));
|
||||||
map_builder_server_options.set_enable_ssl_encryption(
|
map_builder_server_options.set_enable_ssl_encryption(
|
||||||
lua_parameter_dictionary->GetBool("enable_ssl_encryption"));
|
lua_parameter_dictionary->GetBool("enable_ssl_encryption"));
|
||||||
map_builder_server_options.set_token_file_path(
|
map_builder_server_options.set_enable_google_auth(
|
||||||
lua_parameter_dictionary->GetString("token_file_path"));
|
lua_parameter_dictionary->GetBool("enable_google_auth"));
|
||||||
return map_builder_server_options;
|
return map_builder_server_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,5 +26,5 @@ message MapBuilderServerOptions {
|
||||||
string uplink_server_address = 5;
|
string uplink_server_address = 5;
|
||||||
int32 upload_batch_size = 6;
|
int32 upload_batch_size = 6;
|
||||||
bool enable_ssl_encryption = 7;
|
bool enable_ssl_encryption = 7;
|
||||||
string token_file_path = 8;
|
bool enable_google_auth = 9;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,5 @@ MAP_BUILDER_SERVER = {
|
||||||
uplink_server_address = "",
|
uplink_server_address = "",
|
||||||
upload_batch_size = 100,
|
upload_batch_size = 100,
|
||||||
enable_ssl_encryption = false,
|
enable_ssl_encryption = false,
|
||||||
token_file_path = "",
|
enable_google_auth = false,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue