Class: Inspec::Resources::SecurityIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/security_identifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SecurityIdentifier

Returns a new instance of SecurityIdentifier.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/inspec/resources/security_identifier.rb', line 17

def initialize(opts = {})
  supported_opt_keys = %i{user group unspecified}
  raise ArgumentError, "Invalid security_identifier param '#{opts}'. Please pass a hash with these supported keys: #{supported_opt_keys}" unless opts.respond_to?(:keys)
  raise ArgumentError, "Unsupported security_identifier options '#{opts.keys - supported_opt_keys}'. Supported keys: #[supported_opt_keys]" unless (opts.keys - supported_opt_keys).empty?
  raise ArgumentError, "Specifying more than one of :user :group or :unspecified for security_identifier is not supported" unless opts.keys && (opts.keys & supported_opt_keys).length == 1

  if opts[:user]
    @type = :user
    @name = opts[:user]
  end
  if opts[:group]
    @type = :group
    @name = opts[:group]
  end
  if opts[:unspecified]
    @type = :unspecified
    @name = opts[:unspecified]
  end
  raise ArgumentError, "Specify one of :user :group or :unspecified for security_identifier" unless @name

  @sids = nil
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/inspec/resources/security_identifier.rb', line 45

def exist?
  fetch_sids unless @sids
  @sids.key?(@name)
end

#sidObject



40
41
42
43
# File 'lib/inspec/resources/security_identifier.rb', line 40

def sid
  fetch_sids unless @sids
  @sids[@name] # nil if not found
end

#to_sObject



50
51
52
# File 'lib/inspec/resources/security_identifier.rb', line 50

def to_s
  "Security Identifier"
end