diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-03-19 10:11:12 -0600 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-06 21:20:16 -0500 |
commit | db18993f652425b72c4b854e18a002e0ec44b196 (patch) | |
tree | 7466e5f6b154bd79e72c13a5021d92eb9d7e4a13 /app/models/deploy_token.rb | |
parent | aade8b3652573db40e7b777c72caa922b0bc12ef (diff) | |
download | gitlab-ce-db18993f652425b72c4b854e18a002e0ec44b196.tar.gz |
Create barebones for Deploytoken
Includes:
- Model, factories, create service and controller actions
- As usual, includes specs for everything
- Builds UI (copy from PAT)
- Add revoke action
Closes #31591
Diffstat (limited to 'app/models/deploy_token.rb')
-rw-r--r-- | app/models/deploy_token.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/deploy_token.rb b/app/models/deploy_token.rb new file mode 100644 index 00000000000..185bd806b18 --- /dev/null +++ b/app/models/deploy_token.rb @@ -0,0 +1,25 @@ +class DeployToken < ActiveRecord::Base + include Expirable + include TokenAuthenticatable + add_authentication_token_field :token + + AVAILABLE_SCOPES = %w(read_repo read_registry).freeze + + serialize :scopes, Array # rubocop:disable Cop/ActiveRecordSerialize + + validates :scopes, presence: true + + 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 + + def self.redis_shared_state_key(user_id) + "gitlab:personal_access_token:#{user_id}" + end +end |