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
95 96 97 98 |
# File 'lib/chef_fixie/authz_objects.rb', line 95 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
100 101 102 |
# File 'lib/chef_fixie/authz_objects.rb', line 100 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
110 111 112 113 114 115 |
# File 'lib/chef_fixie/authz_objects.rb', line 110 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
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chef_fixie/authz_objects.rb', line 83 def get_type(id) Types.each do |t| begin r = AuthzApi.get("#{self.to_resource(t)}/#{id}") return t rescue RestClient::ResourceNotFound=>e # expected if not found end end return :none end |
#resourcify_actor_or_group(a_or_g) ⇒ Object
104 105 106 107 108 |
# File 'lib/chef_fixie/authz_objects.rb', line 104 def resourcify_actor_or_group(a_or_g) return a_or_g if ["actors", "groups"].member?(a_or_g) check_actor_or_group(a_or_g) to_resource(a_or_g) end |
#to_resource(t) ⇒ Object
78 79 80 81 |
# File 'lib/chef_fixie/authz_objects.rb', line 78 def to_resource(t) # This is a rails thing... t.to_s.pluralize t.to_s + "s" # hack end |