diff options
author | Matija Čupić <matteeyah@gmail.com> | 2017-12-04 00:53:04 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2017-12-04 00:53:04 +0100 |
commit | 50c8bd6350ebfd8d35deb2a1b41eb36e193d1a14 (patch) | |
tree | 4ba7d1f7e760793ef5bdde54dd8d3e9cf265ba8a | |
parent | e0f84130567dc34edf1ae75fcf595e24991d2fa9 (diff) | |
download | gitlab-ce-50c8bd6350ebfd8d35deb2a1b41eb36e193d1a14.tar.gz |
Generate user agent header for GCP Client
-rw-r--r-- | lib/google_api/cloud_platform/client.rb | 4 | ||||
-rw-r--r-- | spec/lib/google_api/cloud_platform/client_spec.rb | 9 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb index 9242cbe840c..615cd7dc60a 100644 --- a/lib/google_api/cloud_platform/client.rb +++ b/lib/google_api/cloud_platform/client.rb @@ -82,6 +82,10 @@ module GoogleApi def token_life_time(expires_at) DateTime.strptime(expires_at, '%s').to_time.utc - Time.now.utc end + + def user_agent_header + { 'User-Agent': "GitLab/#{Gitlab::VERSION.match('(\d+\.\d+)').captures.first} (GPN:GitLab;)" } + end end end end diff --git a/spec/lib/google_api/cloud_platform/client_spec.rb b/spec/lib/google_api/cloud_platform/client_spec.rb index fac23dce44d..41964034062 100644 --- a/spec/lib/google_api/cloud_platform/client_spec.rb +++ b/spec/lib/google_api/cloud_platform/client_spec.rb @@ -125,4 +125,13 @@ describe GoogleApi::CloudPlatform::Client do it { is_expected.to be_nil } end end + + describe '#user_agent_header' do + subject { client.instance_eval { user_agent_header } } + + it 'returns the correct major and minor GitLab version ' do + stub_const('Gitlab::VERSION', '10.3.0-pre') + expect(subject).to eq({ 'User-Agent': 'GitLab/10.3 (GPN:GitLab;)' }) + end + end end |