debian-mirror-gitlab/app/models/clusters/agent_token.rb

19 lines
590 B
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module Clusters
class AgentToken < ApplicationRecord
include TokenAuthenticatable
2021-01-29 00:20:46 +05:30
add_authentication_token_field :token, encrypted: :required, token_generator: -> { Devise.friendly_token(50) }
2020-10-24 23:57:45 +05:30
self.table_name = 'cluster_agent_tokens'
2021-04-17 20:07:23 +05:30
belongs_to :agent, class_name: 'Clusters::Agent', optional: false
2021-03-11 19:13:27 +05:30
belongs_to :created_by_user, class_name: 'User', optional: true
2020-10-24 23:57:45 +05:30
before_save :ensure_token
2021-04-17 20:07:23 +05:30
validates :description, length: { maximum: 1024 }
validates :name, presence: true, length: { maximum: 255 }, on: :create
2020-10-24 23:57:45 +05:30
end
end