class Gemstash::Authorization
Authorization
mechanism to manipulate private gems.
Constants
- VALID_PERMISSIONS
Attributes
name[R]
Public Class Methods
[](auth_key)
click to toggle source
# File lib/gemstash/authorization.rb, line 52 def self.[](auth_key) cached_auth = gemstash_env.cache.authorization(auth_key) return cached_auth if cached_auth record = Gemstash::DB::Authorization[auth_key: auth_key] if record auth = new(record) gemstash_env.cache.set_authorization(record.auth_key, auth) auth end end
check(auth_key, permission)
click to toggle source
# File lib/gemstash/authorization.rb, line 44 def self.check(auth_key, permission) raise NotAuthorizedError, "Authorization key required" if auth_key.to_s.strip.empty? auth = self[auth_key] raise NotAuthorizedError, "Authorization key is invalid" unless auth raise NotAuthorizedError, "Authorization key doesn't have #{permission} access" unless auth.can?(permission) end
new(record)
click to toggle source
# File lib/gemstash/authorization.rb, line 65 def initialize(record) @auth_key = record.auth_key @name = record.name @all = record.permissions == "all" @permissions = Set.new(record.permissions.split(",")) end
remove(auth_key)
click to toggle source
# File lib/gemstash/authorization.rb, line 35 def self.remove(auth_key) record = Gemstash::DB::Authorization[auth_key: auth_key] return unless record record.destroy gemstash_env.cache.invalidate_authorization(auth_key) log.info "Authorization '#{auth_key}' with access to '#{record.permissions}' removed" end
Public Instance Methods
all?()
click to toggle source
# File lib/gemstash/authorization.rb, line 78 def all? @all end
can?(permission)
click to toggle source
# File lib/gemstash/authorization.rb, line 72 def can?(permission) raise "Invalid permission '#{permission}'" unless VALID_PERMISSIONS.include?(permission) all? || @permissions.include?(permission) end
fetch?()
click to toggle source
# File lib/gemstash/authorization.rb, line 90 def fetch? can?("fetch") end
push?()
click to toggle source
# File lib/gemstash/authorization.rb, line 82 def push? can?("push") end
yank?()
click to toggle source
# File lib/gemstash/authorization.rb, line 86 def yank? can?("yank") end