diff options
| author | Filipa Lacerda <filipa@gitlab.com> | 2017-10-06 10:46:03 +0100 |
|---|---|---|
| committer | Filipa Lacerda <filipa@gitlab.com> | 2017-10-06 10:46:03 +0100 |
| commit | 5ced761ebdcb0579377e338c2e321e4ba0373336 (patch) | |
| tree | d67cc381586fa755fc16809565c4174c6ca28bf0 /lib/google_api | |
| parent | f71df9f536cc99f5e1626dae7dfe0ab15f7bd258 (diff) | |
| parent | 638c616296b37b528c1b56f63a818301a502f7aa (diff) | |
| download | gitlab-ce-5ced761ebdcb0579377e338c2e321e4ba0373336.tar.gz | |
Merge branch 'feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service' of https://gitlab.com/gitlab-org/gitlab-ce into feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service
* 'feature/sm/35954-create-kubernetes-cluster-on-gke-from-k8s-service' of https://gitlab.com/gitlab-org/gitlab-ce:
Use utc for time comparision
Diffstat (limited to 'lib/google_api')
| -rw-r--r-- | lib/google_api/cloud_platform/client.rb | 11 |
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 |
