Read about our upcoming Code of Conduct on this issue

deploy_tokens_presenter.rb 1.01 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
module Projects
  module Settings
    class DeployTokensPresenter < Gitlab::View::Presenter::Simple
      include Enumerable

      presents :deploy_tokens

      def length
        deploy_tokens.length
      end

      def each
        deploy_tokens.each do |deploy_token|
          yield deploy_token
        end
      end

Mayra Cabrera's avatar
Mayra Cabrera committed
18
19
      def temporal_token
        @temporal_token ||= Gitlab::Redis::SharedState.with do |redis|
20
21
22
23
24
25
          token = redis.get(deploy_token_key)
          redis.del(deploy_token_key)
          token
        end
      end

Mayra Cabrera's avatar
Mayra Cabrera committed
26
27
28
29
30
31
32
33
34
      def attributes_deploy_token
        @attributes_deploy_token ||= Gitlab::Redis::SharedState.with do |redis|
          attributes_key = deploy_token_key + ":attributes"
          attributes_content = redis.get(attributes_key) || '{}'
          redis.del(attributes_key)
          JSON.parse(attributes_content)
        end
      end

35
36
37
      private

      def deploy_token_key
Mayra Cabrera's avatar
Mayra Cabrera committed
38
        @deploy_token_key ||= DeployToken.redis_shared_state_key(current_user.id)
39
40
41
42
      end
    end
  end
end