summaryrefslogtreecommitdiff
path: root/lib/gitlab/lfs_token.rb
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-09-28 11:02:31 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-09-28 12:13:48 -0500
commit2772109ac15bed2bd199294f8d770f49a749b4bd (patch)
treeadae1f9a4d0c073182fd6d2e0c01b7dcb7428e2c /lib/gitlab/lfs_token.rb
parenta4944fb7155fc8aa4d1541d9f1e4e80c00f49292 (diff)
downloadgitlab-ce-2772109ac15bed2bd199294f8d770f49a749b4bd.tar.gz
Handle LFS token creation and retrieval in the same method, and in the same Redis connection.lfs-ssh-authorization-fix
Reset expiry time of token, if token is retrieved again before it expires.
Diffstat (limited to 'lib/gitlab/lfs_token.rb')
-rw-r--r--lib/gitlab/lfs_token.rb21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/gitlab/lfs_token.rb b/lib/gitlab/lfs_token.rb
index f31444b2b07..7b3bbcf6a32 100644
--- a/lib/gitlab/lfs_token.rb
+++ b/lib/gitlab/lfs_token.rb
@@ -17,21 +17,18 @@ module Gitlab
end
end
- def generate
- return value if value
-
- token = Devise.friendly_token(TOKEN_LENGTH)
-
+ def token
Gitlab::Redis.with do |redis|
- redis.set(redis_key, token, ex: EXPIRY_TIME)
- end
+ token = redis.get(redis_key)
- token
- end
+ if token
+ redis.expire(redis_key, EXPIRY_TIME)
+ else
+ token = Devise.friendly_token(TOKEN_LENGTH)
+ redis.set(redis_key, token, ex: EXPIRY_TIME)
+ end
- def value
- Gitlab::Redis.with do |redis|
- redis.get(redis_key)
+ token
end
end