diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-03-19 19:11:12 +0300 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2018-04-07 05:20:16 +0300 |
commit | db18993f652425b72c4b854e18a002e0ec44b196 (patch) | |
tree | 7466e5f6b154bd79e72c13a5021d92eb9d7e4a13 /app/models | |
parent | aade8b3652573db40e7b777c72caa922b0bc12ef (diff) |
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')
-rw-r--r-- | app/models/deploy_token.rb | 25 | ||||
-rw-r--r-- | app/models/project.rb | 1 |
2 files changed, 26 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 diff --git a/app/models/project.rb b/app/models/project.rb index 96907f3b23d..3cfb163abf4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -222,6 +222,7 @@ class Project < ActiveRecord::Base has_many :environments has_many :deployments has_many :pipeline_schedules, class_name: 'Ci::PipelineSchedule' + has_many :deploy_tokens has_many :active_runners, -> { active }, through: :runner_projects, source: :runner, class_name: 'Ci::Runner' |