Class: Inspec::Resources::SecurityIdentifier

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ SecurityIdentifier

Returns a new instance of SecurityIdentifier.

Raises:

  • (ArgumentError)


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

def initialize(opts = {})
  supported_opt_keys = [: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)


42
43
44
45
# File 'lib/resources/security_identifier.rb', line 42

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

#sidObject



37
38
39
40
# File 'lib/resources/security_identifier.rb', line 37

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