Module: OpscodeAcl::AclBase

Defined in:
lib/chef/knife/acl_base.rb

Constant Summary collapse

PERM_TYPES =
%w(create read update delete grant)
ACTOR_TYPES =
%w(client group)
OBJECT_TYPES =
%w(clients groups containers data nodes roles cookbooks sandboxes environments)
OBJECT_NAME_SPEC =
/^[\-[:alnum:]_\.]+$/

Instance Method Summary collapse

Instance Method Details

#get_ace(object_type, object_name, perm) ⇒ Object



76
77
78
# File 'lib/chef/knife/acl_base.rb', line 76

def get_ace(object_type, object_name, perm)
  get_acl(object_type, object_name)[perm]
end

#get_acl(object_type, object_name) ⇒ Object



72
73
74
# File 'lib/chef/knife/acl_base.rb', line 72

def get_acl(object_type, object_name)
  rest.get_rest("#{object_type}/#{object_name}/_acl")
end

#update_ace!(object_type, object_name, ace_type, ace) ⇒ Object



80
81
82
# File 'lib/chef/knife/acl_base.rb', line 80

def update_ace!(object_type, object_name, ace_type, ace)
  rest.put_rest("#{object_type}/#{object_name}/_acl/#{ace_type}", ace_type => ace)
end

#validate_actor_name!(name) ⇒ Object



48
49
50
51
# File 'lib/chef/knife/acl_base.rb', line 48

def validate_actor_name!(name)
  # Same rules apply to object's and actors
  validate_object_name!(name)
end

#validate_actor_type!(type) ⇒ Object



41
42
43
44
45
46
# File 'lib/chef/knife/acl_base.rb', line 41

def validate_actor_type!(type)
  if ! ACTOR_TYPES.include?(type)
    ui.fatal "Unknown actor type \"#{type}\". The following types are permitted: #{ACTOR_TYPES.join(', ')}"
    exit 1
  end
end

#validate_all_params!Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/chef/knife/acl_base.rb', line 61

def validate_all_params!
  # Helper method to valid parameters for commands that modify permisisons
  # This assumes including class has the necessary accessors
  # We the validation to ensure we can give the user more helpful error messages.
  validate_perm_type!(perm)
  validate_actor_type!(actor_type)
  validate_actor_name!(actor_name)
  validate_object_name!(object_name)
  validate_object_type!(object_type)
end

#validate_object_name!(name) ⇒ Object



34
35
36
37
38
39
# File 'lib/chef/knife/acl_base.rb', line 34

def validate_object_name!(name)
  if ! OBJECT_NAME_SPEC.match(name)
    ui.fatal "Invalid name: #{name}"
    exit 1
  end
end

#validate_object_type!(type) ⇒ Object



27
28
29
30
31
32
# File 'lib/chef/knife/acl_base.rb', line 27

def validate_object_type!(type)
  if ! OBJECT_TYPES.include?(type)
    ui.fatal "Unknown object type \"#{type}\".  The following types are permitted: #{OBJECT_TYPES.join(', ')}"
    exit 1
  end
end

#validate_perm_type!(perm) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/chef/knife/acl_base.rb', line 53

def validate_perm_type!(perm)
  if ! PERM_TYPES.include?(perm)
    ui.fatal "Invalid permission \"#{perm}\". The following permissions are permitted: #{PERM_TYPES.join(',')}"
    exit 1
  end

end