Sha256: f01f6605992cb13a75cf35f7becccd06270d3ebb0c6336646efbc5281139236e
Contents?: true
Size: 1.03 KB
Versions: 22
Compression:
Stored size: 1.03 KB
Contents
class ApiClient < ActiveRecord::Base InsufficientPermission = Class.new(StandardError) belongs_to :creator, class_name: 'User' belongs_to :stack validates :creator, :name, presence: true serialize :permissions, Array PERMISSIONS = %w( read:stack write:stack deploy:stack lock:stack read:hook write:hook ).freeze validates :permissions, subset: {of: PERMISSIONS} class << self def authenticate(token) find_by_id(message_verifier.verify(token).to_i) rescue Shipit::SimpleMessageVerifier::InvalidSignature end def message_verifier @message_verifier ||= Shipit::SimpleMessageVerifier.new(Shipit.api_clients_secret) end end def authentication_token self.class.message_verifier.generate(id) end def check_permissions!(operation, scope) required_permission = "#{operation}:#{scope}" unless permissions.include?(required_permission) raise InsufficientPermission, "This operation requires the `#{required_permission}` permission" end true end end
Version data entries
22 entries across 22 versions & 1 rubygems