summaryrefslogtreecommitdiff
path: root/lib/google_api
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-10-06 18:23:53 +0900
committerShinya Maeda <shinya@gitlab.com>2017-10-06 18:23:53 +0900
commit638c616296b37b528c1b56f63a818301a502f7aa (patch)
treef58194566e84063584983a0e8f48d39f3e90bd50 /lib/google_api
parent354e2ef08df3c704ca325415116587440260f67b (diff)
downloadgitlab-ce-638c616296b37b528c1b56f63a818301a502f7aa.tar.gz
Use utc for time comparision
Diffstat (limited to 'lib/google_api')
-rw-r--r--lib/google_api/cloud_platform/client.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb
index 926b7402cd5..5ec1fa37546 100644
--- a/lib/google_api/cloud_platform/client.rb
+++ b/lib/google_api/cloud_platform/client.rb
@@ -5,6 +5,7 @@ module GoogleApi
class Client < GoogleApi::Auth
DEFAULT_MACHINE_TYPE = 'n1-standard-1'.freeze
SCOPE = 'https://www.googleapis.com/auth/cloud-platform'.freeze
+ LEAST_TOKEN_LIFE_TIME = 10.minutes
class << self
def session_key_for_token
@@ -25,9 +26,7 @@ module GoogleApi
return false unless expires_at
# Making sure that the token will have been still alive during the cluster creation.
- unless DateTime.strptime(expires_at, '%s').to_time > Time.now + 10.minutes
- return false
- end
+ return false if token_life_time(expires_at) < LEAST_TOKEN_LIFE_TIME
true
end
@@ -68,6 +67,12 @@ module GoogleApi
m = self_link.match(%r{projects/.*/zones/.*/operations/(.*)})
m[1] if m
end
+
+ private
+
+ def token_life_time(expires_at)
+ DateTime.strptime(expires_at, '%s').to_time.utc - Time.now.utc
+ end
end
end
end