summaryrefslogtreecommitdiff
path: root/app/models/clusters/agent_token.rb
blob: 9d79887b574e1bfc9aa4e32486eb821a1b5449f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

module Clusters
  class AgentToken < ApplicationRecord
    include TokenAuthenticatable
    add_authentication_token_field :token, encrypted: :required, token_generator: -> { Devise.friendly_token(50) }

    self.table_name = 'cluster_agent_tokens'

    belongs_to :agent, class_name: 'Clusters::Agent', optional: false
    belongs_to :created_by_user, class_name: 'User', optional: true

    before_save :ensure_token

    validates :description, length: { maximum: 1024 }
    validates :name, presence: true, length: { maximum: 255 }, on: :create
  end
end