2020-07-20 05:09:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Clusters
|
|
|
|
class AgentToken < ApplicationRecord
|
|
|
|
include TokenAuthenticatable
|
2020-10-22 23:08:37 -04:00
|
|
|
add_authentication_token_field :token, encrypted: :required, token_generator: -> { Devise.friendly_token(50) }
|
2020-07-20 05:09:22 -04:00
|
|
|
|
|
|
|
self.table_name = 'cluster_agent_tokens'
|
|
|
|
|
2021-02-19 19:10:55 -05:00
|
|
|
belongs_to :agent, class_name: 'Clusters::Agent', optional: false
|
2021-02-16 13:09:24 -05:00
|
|
|
belongs_to :created_by_user, class_name: 'User', optional: true
|
2020-07-20 05:09:22 -04:00
|
|
|
|
|
|
|
before_save :ensure_token
|
2021-02-19 19:10:55 -05:00
|
|
|
|
|
|
|
validates :description, length: { maximum: 1024 }
|
2020-07-20 05:09:22 -04:00
|
|
|
end
|
|
|
|
end
|