
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
convert switch and router config files to structured data
require 'ios_parser'
text = my_method_to_get_a_raw_config
config = IOSParser.parse(text)
my_http_client.put_json(config.to_json)
config = IOSParser.from_json(my_http_client.get_json)
config.find('hostname').to_hash
# => { :args => ["hostname", "myswitch"], :commands => [] }
case
-style Queriesconfig.find_all(starts_with: ['interface', /Gigabit/])
# => [{:args=>["interface", "GigabitEthernet0/1"],
# :commands=>[{:args=>["switchport", "mode", "trunk"], :commands=>[]},
# {:args=>["logging", "event", "trunk-status"], :commands=>[]},
# {:args=>["speed", 1000], :commands=>[]}]},
# {:args=>["interface", "GigabitEthernet0/2"],
# :commands=>[{:args=>["switchport", "mode", "trunk"], :commands=>[]},
# {:args=>["logging", "event", "trunk-status"], :commands=>[]},
# {:args=>["speed", 1000], :commands=>[]}]}]
config.find(starts_with: ['interface', 'GigabitEthernet0/1']).find('speed').args[1]
# => 1000
#find_all
returns an Array
, so you can't chain IOSParser
queries after it. Instead, you can use nested queries with Ruby's Array
and Enumerable
APIs. This is useful to transform and clean data.
config.find_all("interface").flat_map do |i|
s = i.find("speed")
s ? [{ interface: i.args.last, speed: s.args.last }] : []
end
# => [{:interface=>"GigabitEthernet0/1", :speed=>1000},
# {:interface=>"GigabitEthernet0/2", :speed=>1000}]
Compound matchers combine or modify the meaning of other matchers. Their argument can be a single hash if all of the affected matchers have different names, and an array of hashes if it is necessary to use the same matcher name with multiple arguments.
parent
- matches commands by their parents (e.g., parent: { starts_with: 'interface' }
will match the first level of subcommands of any interface section)any_child
- matches commands that match at least one child command (e.g., any_child: { name: 'speed' }
will match any command that has a child command starting with speed
)no_child
- matches commands that do not match any child command (e.g., no_child: { name: 'speed' }
will match commands that do not have a child command starting with speed
)any
- matches commands that match any of an array of queries (e.g., any: [{ starts_with: 'interface' }, { starts_with: 'ip route' }]
will match all interfaces and all IOS-style static routes)all
- matches commands that match all of an array of queries (e.g., all: { starts_with: 'interface', line: /FastEthernet/ }
will match all FastEthernet interfaces)none
- negation of any
not_all
/ not
- negation of all
name
- matches the first argument of a command (e.g., name: ip
will match ip route
or ip http server
)starts_with
- matches the leading arguments of a commandcontains
- matches any sequence of arguments of a commandends_with
- matches the trailling arguments of a commandline
- matches the string form of a command (all the arguments separated by single spaces)depth
- matches based on how many command sections contain the command (e.g., depth: 0
will only match top-level commands), accepts integers and integer rangesAfter checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/bjmllr/ios_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Copyright (C) 2016 Ben Miller
The gem is available as free software under the terms of the GNU General Public License, Version 3.
FAQs
Unknown package
We found that ios_parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.