Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect port and filter table #776

Merged
merged 2 commits into from
May 31, 2016
Merged

connect port and filter table #776

merged 2 commits into from
May 31, 2016

Conversation

arlimus
Copy link
Contributor

@arlimus arlimus commented May 31, 2016

(1) Adds style handling to filter table + optimizes its internals. It's the equivalent of:

resource.entries.flatten.uniq.compact

and can be used by:

filter.add(:field, style: :simple)

(2) Puts filter table into port. A forgettable internal change, if it weren't for:

port.where { protocol =~ /tcp/ && port > 80 }.listening?

(becomes especially useful if you want all listening ports on the node and then do some action on those, e.g.

port.protocols(/tcp/).entries.each do |socket|
  describe ssl(port: socket.port).protocols('ssl2') do
    it { should_not be_enabled }
  end
end

)

for quick flattening, filtering, and non-nil results. this also simplifies some interal calls and structure
@arlimus arlimus added the Type: Enhancement Improves an existing feature label May 31, 2016
utilizing filter table to make port more flexible and useful.
@chris-rock
Copy link
Contributor

Awesome work @arlimus. It works as expected:

inspec> port.pids
=> [710, 39533, 40899]
inspec> port(3000).pids
=> [40899]
inspec> port(3001).pids
=> []
inspec> port(3001).processes
=> []
inspec> port(3000).processes
=> ["node"]
inspec> port(3000).protocols
=> ["tcp"]

I just found small issue, where entries is not returning the expected value for listening

inspec> port.protocols(/tcp/).entries
=> [#<struct  port=3000, address="0.0.0.0", protocol="tcp", process="node", pid=40899, listening?=nil>]

We need to adapt the new_entry method and call blocks? Lets do that in another PR, since this is further improvement and only an optimization for the inspec shell

@chris-rock chris-rock merged commit f9bbe8e into master May 31, 2016
@chris-rock chris-rock deleted the dr/port branch May 31, 2016 05:59
@arlimus
Copy link
Contributor Author

arlimus commented May 31, 2016

@chris-rock oh that's right, single entries don't have a functioning listening?. It actually opens an interesting case in filter-table, where aggregate operations on a list of entries are possible (e.g. listening?, enabled?, ...) but aren't being implemented for single entries. We can treat is as an issue in filter-table, which delegates these calls to each entry, without adding an implementation. It's a left-over from the regular .add(:field) calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants