Class: Inspec::Resources::Shadow
- Inherits:
-
Object
- Object
- Inspec::Resources::Shadow
- Includes:
- FileReader
- Defined in:
- lib/resources/shadow.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #expiry_date(query = nil) ⇒ Object
- #filter(query = {}) ⇒ Object
-
#initialize(path = '/etc/shadow', opts = {}) ⇒ Shadow
constructor
A new instance of Shadow.
- #last_change(query = nil) ⇒ Object
- #lines ⇒ Object
- #password(query = nil) ⇒ Object
- #to_s ⇒ Object
-
#user(query = nil) ⇒ Object
Next 4 are deprecated methods.
Methods included from FileReader
Constructor Details
#initialize(path = '/etc/shadow', opts = {}) ⇒ Shadow
Returns a new instance of Shadow.
39 40 41 42 43 |
# File 'lib/resources/shadow.rb', line 39 def initialize(path = '/etc/shadow', opts = {}) @opts = opts @path = path || '/etc/shadow' @filters = @opts[:filters] || '' end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
37 38 39 |
# File 'lib/resources/shadow.rb', line 37 def params @params end |
Instance Method Details
#expiry_date(query = nil) ⇒ Object
111 112 113 114 115 |
# File 'lib/resources/shadow.rb', line 111 def expiry_date(query = nil) warn '[DEPRECATION] The shadow `expiry_date` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `expiry_dates` instead.' query.nil? ? where.expiry_dates : where('expiry_date' => query) end |
#filter(query = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/resources/shadow.rb', line 71 def filter(query = {}) return self if query.nil? || query.empty? res = set_params filters = '' query.each do |attr, condition| condition = condition.to_s if condition.is_a? Integer filters += " #{attr} = #{condition.inspect}" res = res.find_all do |line| case line[attr.to_s] when condition true else false end end end content = res.map { |x| x.values.join(':') }.join("\n") Shadow.new(@path, content: content, filters: @filters + filters) end |
#last_change(query = nil) ⇒ Object
105 106 107 108 109 |
# File 'lib/resources/shadow.rb', line 105 def last_change(query = nil) warn '[DEPRECATION] The shadow `last_change` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `last_changes` instead.' query.nil? ? where.last_changes : where('last_change' => query) end |
#lines ⇒ Object
117 118 119 120 121 |
# File 'lib/resources/shadow.rb', line 117 def lines warn '[DEPRECATION] The shadow `lines` property is deprecated and will be removed' \ ' in InSpec 3.0.' shadow_content.to_s.split("\n") end |
#password(query = nil) ⇒ Object
99 100 101 102 103 |
# File 'lib/resources/shadow.rb', line 99 def password(query = nil) warn '[DEPRECATION] The shadow `password` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `passwords` instead.' query.nil? ? where.passwords : where('password' => query) end |
#to_s ⇒ Object
123 124 125 126 |
# File 'lib/resources/shadow.rb', line 123 def to_s f = @filters.empty? ? '' : ' with'+@filters "#{@path}#{f}" end |
#user(query = nil) ⇒ Object
Next 4 are deprecated methods. We define them here so we can emit a deprecation message. They are also defined on the Table, above.
93 94 95 96 97 |
# File 'lib/resources/shadow.rb', line 93 def user(query = nil) warn '[DEPRECATION] The shadow `user` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `users` instead.' query.nil? ? where.users : where('user' => query) end |