Total Complexity | 0 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | # frozen_string_literal: true |
||
9 | class Privilege |
||
10 | module Group |
||
11 | # Sudo privilege granter/revoker |
||
12 | class Sudo < Privilege |
||
13 | def grant(resource_factory, owner, privilege) |
||
14 | resource(resource_factory, owner, privilege).action = :install |
||
15 | end |
||
16 | |||
17 | def revoke(resource_factory, owner, privilege) |
||
18 | resource(resource_factory, owner, privilege).action = :remove |
||
19 | end |
||
20 | |||
21 | private |
||
22 | |||
23 | def resource(resource_factory, owner, privilege) |
||
24 | resource_factory.sudo "group:#{owner.id}" do |
||
25 | privilege.options.each do |key, value| |
||
26 | if self.class.properties.keys.include?(key) |
||
27 | send(key, value) |
||
28 | else |
||
29 | ::Chef::Log.warn( |
||
30 | "Account #{owner.id} sudo privilege " \ |
||
31 | "has unknown option #{key}" |
||
32 | ) |
||
33 | end |
||
34 | end |
||
35 | group owner.id.to_s |
||
36 | end |
||
37 | end |
||
38 | |||
39 | # yes, i'm evading excessive line length |
||
40 | ::AMA::Chef::User::Handler::Privilege.tap do |registry| |
||
41 | registry.register(:group, :sudo, new) |
||
42 | end |
||
43 | end |
||
44 | end |
||
45 | end |
||
46 | end |
||
50 |