From d6772cf2747b5f9235b153d7c5fabb97c7a8f552 Mon Sep 17 00:00:00 2001 From: Steve Wolter Date: Wed, 12 Sep 2018 09:14:58 +0200 Subject: [PATCH] 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. --- .../internal/local_trajectory_uploader.cc | 23 ++++++++----------- .../internal/local_trajectory_uploader.h | 2 +- .../cloud/internal/map_builder_server.cc | 2 +- .../cloud/map_builder_server_options.cc | 4 ++-- .../proto/map_builder_server_options.proto | 2 +- configuration_files/map_builder_server.lua | 2 +- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cartographer/cloud/internal/local_trajectory_uploader.cc b/cartographer/cloud/internal/local_trajectory_uploader.cc index 99fffb6..4a0dc69 100644 --- a/cartographer/cloud/internal/local_trajectory_uploader.cc +++ b/cartographer/cloud/internal/local_trajectory_uploader.cc @@ -21,7 +21,6 @@ #include "absl/memory/memory.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_trajectory_handler.h" #include "cartographer/cloud/internal/handlers/finish_trajectory_handler.h" @@ -68,7 +67,7 @@ class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface { public: LocalTrajectoryUploader(const std::string& uplink_server_address, int batch_size, bool enable_ssl_encryption, - const std::string& token_file_path); + bool enable_google_auth); ~LocalTrajectoryUploader(); // Starts the upload thread. @@ -108,19 +107,15 @@ class LocalTrajectoryUploader : public LocalTrajectoryUploaderInterface { LocalTrajectoryUploader::LocalTrajectoryUploader( 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) { auto channel_creds = - enable_ssl_encryption - ? ::grpc::SslCredentials(::grpc::SslCredentialsOptions()) - : ::grpc::InsecureChannelCredentials(); + enable_google_auth + ? grpc::GoogleDefaultCredentials() + : (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); std::chrono::system_clock::time_point deadline = std::chrono::system_clock::now() + @@ -340,10 +335,10 @@ void LocalTrajectoryUploader::EnqueueSensorData( std::unique_ptr CreateLocalTrajectoryUploader( 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(uplink_server_address, batch_size, enable_ssl_encryption, - token_file_path); + enable_google_auth); } } // namespace cloud diff --git a/cartographer/cloud/internal/local_trajectory_uploader.h b/cartographer/cloud/internal/local_trajectory_uploader.h index 906a453..323e2c2 100644 --- a/cartographer/cloud/internal/local_trajectory_uploader.h +++ b/cartographer/cloud/internal/local_trajectory_uploader.h @@ -64,7 +64,7 @@ class LocalTrajectoryUploaderInterface { // Returns LocalTrajectoryUploader with the actual implementation. std::unique_ptr CreateLocalTrajectoryUploader( 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 cartographer diff --git a/cartographer/cloud/internal/map_builder_server.cc b/cartographer/cloud/internal/map_builder_server.cc index bb96864..dcbbc38 100644 --- a/cartographer/cloud/internal/map_builder_server.cc +++ b/cartographer/cloud/internal/map_builder_server.cc @@ -68,7 +68,7 @@ MapBuilderServer::MapBuilderServer( map_builder_server_options.uplink_server_address(), map_builder_server_options.upload_batch_size(), map_builder_server_options.enable_ssl_encryption(), - map_builder_server_options.token_file_path()); + map_builder_server_options.enable_google_auth()); } server_builder.RegisterHandler(); server_builder.RegisterHandler(); diff --git a/cartographer/cloud/map_builder_server_options.cc b/cartographer/cloud/map_builder_server_options.cc index 560478c..25fcc87 100644 --- a/cartographer/cloud/map_builder_server_options.cc +++ b/cartographer/cloud/map_builder_server_options.cc @@ -41,8 +41,8 @@ proto::MapBuilderServerOptions CreateMapBuilderServerOptions( lua_parameter_dictionary->GetInt("upload_batch_size")); map_builder_server_options.set_enable_ssl_encryption( lua_parameter_dictionary->GetBool("enable_ssl_encryption")); - map_builder_server_options.set_token_file_path( - lua_parameter_dictionary->GetString("token_file_path")); + map_builder_server_options.set_enable_google_auth( + lua_parameter_dictionary->GetBool("enable_google_auth")); return map_builder_server_options; } diff --git a/cartographer/cloud/proto/map_builder_server_options.proto b/cartographer/cloud/proto/map_builder_server_options.proto index 7f53ba9..747ee8a 100644 --- a/cartographer/cloud/proto/map_builder_server_options.proto +++ b/cartographer/cloud/proto/map_builder_server_options.proto @@ -26,5 +26,5 @@ message MapBuilderServerOptions { string uplink_server_address = 5; int32 upload_batch_size = 6; bool enable_ssl_encryption = 7; - string token_file_path = 8; + bool enable_google_auth = 9; } diff --git a/configuration_files/map_builder_server.lua b/configuration_files/map_builder_server.lua index 384fe79..dc73d16 100644 --- a/configuration_files/map_builder_server.lua +++ b/configuration_files/map_builder_server.lua @@ -22,5 +22,5 @@ MAP_BUILDER_SERVER = { uplink_server_address = "", upload_batch_size = 100, enable_ssl_encryption = false, - token_file_path = "", + enable_google_auth = false, }