summaryrefslogtreecommitdiff
path: root/lib/gitlab/lfs_token.rb
blob: 0685eb775ef96bdc61e73ee2b5fe6a76d75bcee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Gitlab
  class LfsToken
    attr_accessor :actor

    def initialize(actor)
      @actor = actor
    end

    def set_token
      token = Devise.friendly_token(50)
      Gitlab::Redis.with do |redis|
        redis.set(redis_key, token, ex: 3600)
      end
      token
    end

    def get_value
      Gitlab::Redis.with do |redis|
        redis.get(redis_key)
      end
    end

    private

    def redis_key
      "gitlab:lfs_token:#{actor.class.name.underscore}_#{actor.id}" if actor
    end
  end
end