module ChefFixie::AuthzUtils

Constants

ACTIONS
TYPES

Public Instance Methods

check_action(action) click to toggle source
# File lib/chef_fixie/authz_objects.rb, line 98
def check_action(action)
  # TODO Improve; stack trace isn't the best way to communicate with the user
  raise "#{action} not one of #{ACTIONS.join(', ')} " if !ACTIONS.member?(action)
end
check_actor_or_group(a_or_g) click to toggle source
# File lib/chef_fixie/authz_objects.rb, line 103
def check_actor_or_group(a_or_g)
  raise "#{a_or_g} not one of :actor or :group" if a_or_g != :actor && a_or_g != :group
end
get_authz_id(x) click to toggle source
# File lib/chef_fixie/authz_objects.rb, line 113
def get_authz_id(x)
  return x.authz_id if x.respond_to?(:authz_id)
  # if it quacks like an authz id
  return x if x.is_a?(String) && x =~ /^[[:xdigit:]]{32}$/
  raise "#{x} doesn't look like an authz_id"
end
get_type(id) click to toggle source
# File lib/chef_fixie/authz_objects.rb, line 86
def get_type(id)
  TYPES.each do |t|
    begin
      r = AuthzApi.get("#{to_resource(t)}/#{id}")
      return t
    rescue RestClient::ResourceNotFound => e
      # expected if not found
    end
  end
  :none
end
resourcify_actor_or_group(a_or_g) click to toggle source
# File lib/chef_fixie/authz_objects.rb, line 107
def resourcify_actor_or_group(a_or_g)
  return a_or_g if %w{actors groups}.member?(a_or_g)
  check_actor_or_group(a_or_g)
  to_resource(a_or_g)
end
to_resource(t) click to toggle source
# File lib/chef_fixie/authz_objects.rb, line 81
def to_resource(t)
  # This is a rails thing... t.to_s.pluralize
  t.to_s + "s" # hack
end