This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

deploy_token.rb 790 Bytes
Newer Older
1
2
3
4
5
class DeployToken < ActiveRecord::Base
  include Expirable
  include TokenAuthenticatable
  add_authentication_token_field :token

6
  AVAILABLE_SCOPES = %w(read_repository read_registry).freeze
7
8
9
10

  serialize :scopes, Array # rubocop:disable Cop/ActiveRecordSerialize

  validates :scopes, presence: true
11
  validates :project, presence: true
12
13
14
15
16
17
18
19
20
21
22

  belongs_to :project

  before_save :ensure_token

  scope :active, -> { where("revoked = false AND (expires_at >= NOW() OR expires_at IS NULL)") }

  def revoke!
    update!(revoked: true)
  end

Mayra Cabrera's avatar
Mayra Cabrera committed
23
24
  def redis_shared_state_key(user_id)
    "gitlab:deploy_token:#{project_id}:#{user_id}"
25
  end
26
27
28
29
30
31

  def active?
    !revoked
  end

  def username
32
33
34
35
36
    "gitlab+deploy-token-#{id}"
  end

  def has_access_to?(project)
    self.project == project
37
  end
38
end