Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/clusters/agent_token.rb')
-rw-r--r--app/models/clusters/agent_token.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/clusters/agent_token.rb b/app/models/clusters/agent_token.rb
index b2b13f6cef7..f4c497a42cc 100644
--- a/app/models/clusters/agent_token.rb
+++ b/app/models/clusters/agent_token.rb
@@ -2,10 +2,15 @@
module Clusters
class AgentToken < ApplicationRecord
+ TOKEN_PREFIX = "glagent-"
+
include RedisCacheable
include TokenAuthenticatable
- add_authentication_token_field :token, encrypted: :required, token_generator: -> { Devise.friendly_token(50) }
+ add_authentication_token_field :token,
+ encrypted: :required,
+ token_generator: -> { Devise.friendly_token(50) },
+ format_with_prefix: :glagent_prefix
cached_attr_reader :last_used_at
self.table_name = 'cluster_agent_tokens'
@@ -21,6 +26,7 @@ module Clusters
scope :order_last_used_at_desc, -> { order(arel_table[:last_used_at].desc.nulls_last) }
scope :with_status, -> (status) { where(status: status) }
scope :active, -> { where(status: :active) }
+ scope :connected, -> { active.where("last_used_at > ?", Clusters::Agent::INACTIVE_AFTER.ago) }
enum status: {
active: 0,
@@ -30,5 +36,9 @@ module Clusters
def to_ability_name
:cluster
end
+
+ def glagent_prefix
+ TOKEN_PREFIX
+ end
end
end