Class: Inspec::Resources::Shadow
- Inherits:
-
Object
- Object
- Inspec::Resources::Shadow
- Defined in:
- lib/resources/shadow.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #expiry_dates(query = nil) ⇒ Object
- #filter(query = {}) ⇒ Object
-
#initialize(path = '/etc/shadow', opts = nil) ⇒ Shadow
constructor
A new instance of Shadow.
- #last_changes(query = nil) ⇒ Object
- #passwords(query = nil) ⇒ Object
- #to_s ⇒ Object
- #users(query = nil) ⇒ Object
Constructor Details
#initialize(path = '/etc/shadow', opts = nil) ⇒ Shadow
Returns a new instance of Shadow.
37 38 39 40 41 42 43 44 |
# File 'lib/resources/shadow.rb', line 37 def initialize(path = '/etc/shadow', opts = nil) opts ||= {} @path = path || '/etc/shadow' @raw_content = opts[:content] || inspec.file(@path).content @lines = @raw_content.to_s.split("\n") @filters = opts[:filters] || '' @params = @lines.map { |l| parse_shadow_line(l) } end |
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
35 36 37 |
# File 'lib/resources/shadow.rb', line 35 def lines @lines end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
34 35 36 |
# File 'lib/resources/shadow.rb', line 34 def params @params end |
Instance Method Details
#expiry_dates(query = nil) ⇒ Object
110 111 112 113 114 |
# File 'lib/resources/shadow.rb', line 110 def expiry_dates(query = nil) warn '[DEPRECATION] The shadow `expiry_dates` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `expiry_date` instead.' query.nil? ? expiry_date : expiry_date(query) end |
#filter(query = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/resources/shadow.rb', line 72 def filter(query = {}) return self if query.nil? || query.empty? res = @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_changes(query = nil) ⇒ Object
104 105 106 107 108 |
# File 'lib/resources/shadow.rb', line 104 def last_changes(query = nil) warn '[DEPRECATION] The shadow `last_changes` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `last_change` instead.' query.nil? ? last_change : last_change(query) end |
#passwords(query = nil) ⇒ Object
98 99 100 101 102 |
# File 'lib/resources/shadow.rb', line 98 def passwords(query = nil) warn '[DEPRECATION] The shadow `passwords` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `password` instead.' query.nil? ? password : password(query) end |
#to_s ⇒ Object
116 117 118 119 |
# File 'lib/resources/shadow.rb', line 116 def to_s f = @filters.empty? ? '' : ' with'+@filters "/etc/shadow#{f}" end |
#users(query = nil) ⇒ Object
92 93 94 95 96 |
# File 'lib/resources/shadow.rb', line 92 def users(query = nil) warn '[DEPRECATION] The shadow `users` property is deprecated and will be removed' \ ' in InSpec 3.0. Please use `user` instead.' query.nil? ? user : user(query) end |