Module: ChefFixie::AuthzUtils
- Included in:
- AuthzObjectMixin
- Defined in:
- lib/chef_fixie/authz_objects.rb
Constant Summary collapse
- TYPES =
order is an attempt to optimize by most probable.
[:object, :actor, :group, :container]
- ACTIONS =
[:create, :read, :update, :delete, :grant]
Instance Method Summary collapse
- #check_action(action) ⇒ Object
- #check_actor_or_group(a_or_g) ⇒ Object
- #get_authz_id(x) ⇒ Object
- #get_type(id) ⇒ Object
- #resourcify_actor_or_group(a_or_g) ⇒ Object
- #to_resource(t) ⇒ Object
Instance Method Details
#check_action(action) ⇒ Object
98 99 100 101 |
# 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) ⇒ Object
103 104 105 |
# 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) ⇒ Object
113 114 115 116 117 118 |
# 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) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# 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) ⇒ Object
107 108 109 110 111 |
# 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) ⇒ Object
81 82 83 84 |
# 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 |