Sudo.resource()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
1
# frozen_string_literal: true
2
3
require_relative '../../privilege'
4
5
module AMA
6
  module Chef
7
    module User
8
      module Handler
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
47
    end
48
  end
49
end
50