diff --git a/lib/train/transports/gcp.rb b/lib/train/transports/gcp.rb index 42a759aa..2321faba 100644 --- a/lib/train/transports/gcp.rb +++ b/lib/train/transports/gcp.rb @@ -88,6 +88,8 @@ def connect scopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/compute'] authorization = Google::Auth.get_application_default(scopes) + Google::Apis::ClientOptions.default.application_name = 'chef-train' + Google::Apis::ClientOptions.default.application_version = Train::VERSION Google::Apis::RequestOptions.default.authorization = authorization end diff --git a/test/unit/transports/gcp_test.rb b/test/unit/transports/gcp_test.rb index 3f89606c..dfec568d 100644 --- a/test/unit/transports/gcp_test.rb +++ b/test/unit/transports/gcp_test.rb @@ -99,6 +99,18 @@ def transport(options = nil) client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true cache[:api_call].count.must_equal 0 end + + it 'test gcp_compute_client application name' do + client = connection.gcp_compute_client + client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true + client.client_options.application_name.must_equal 'chef-train' + end + + it 'test gcp_compute_client application version' do + client = connection.gcp_compute_client + client.is_a?(Google::Apis::ComputeV1::ComputeService).must_equal true + client.client_options.application_version.must_equal Train::VERSION + end end describe 'gcp_iam_client' do @@ -114,6 +126,18 @@ def transport(options = nil) client.is_a?(Google::Apis::IamV1::IamService).must_equal true cache[:api_call].count.must_equal 0 end + + it 'test gcp_iam_client application name' do + client = connection.gcp_iam_client + client.is_a?(Google::Apis::IamV1::IamService).must_equal true + client.client_options.application_name.must_equal 'chef-train' + end + + it 'test gcp_iam_client application version' do + client = connection.gcp_iam_client + client.is_a?(Google::Apis::IamV1::IamService).must_equal true + client.client_options.application_version.must_equal Train::VERSION + end end describe 'gcp_project_client' do @@ -129,6 +153,18 @@ def transport(options = nil) client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true cache[:api_call].count.must_equal 0 end + + it 'test gcp_project_client application name' do + client = connection.gcp_project_client + client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true + client.client_options.application_name.must_equal 'chef-train' + end + + it 'test gcp_project_client application version' do + client = connection.gcp_project_client + client.is_a?(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService).must_equal true + client.client_options.application_version.must_equal Train::VERSION + end end describe 'gcp_storage_client' do @@ -144,6 +180,18 @@ def transport(options = nil) client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true cache[:api_call].count.must_equal 0 end + + it 'test gcp_storage_client application name' do + client = connection.gcp_storage_client + client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true + client.client_options.application_name.must_equal 'chef-train' + end + + it 'test gcp_storage_client application version' do + client = connection.gcp_storage_client + client.is_a?(Google::Apis::StorageV1::StorageService).must_equal true + client.client_options.application_version.must_equal Train::VERSION + end end describe 'gcp_admin_client' do @@ -159,6 +207,18 @@ def transport(options = nil) client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true cache[:api_call].count.must_equal 0 end + + it 'test gcp_admin_client application name' do + client = connection.gcp_admin_client + client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true + client.client_options.application_name.must_equal 'chef-train' + end + + it 'test gcp_admin_client application version' do + client = connection.gcp_admin_client + client.is_a?(Google::Apis::AdminDirectoryV1::DirectoryService).must_equal true + client.client_options.application_version.must_equal Train::VERSION + end end # test options override of env vars in connect