Sha256: 8afe6934473cd09bd20592ee9b3529c431033da104036b033c4c46022efcb66b
Contents?: true
Size: 1.13 KB
Versions: 15
Compression:
Stored size: 1.13 KB
Contents
module Shipit class ApiClient < ActiveRecord::Base InsufficientPermission = Class.new(StandardError) belongs_to :creator, class_name: 'User' belongs_to :stack, optional: true 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 end
Version data entries
15 entries across 15 versions & 1 rubygems