Skip to content

Commit

Permalink
Merge pull request #674 from bulletproofnetworks/master
Browse files Browse the repository at this point in the history
Add GPG support for reading router.db
  • Loading branch information
ytti authored Jan 24, 2017
2 parents 8375aa0 + 07b4d0c commit 2a69179
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
source 'https://rubygems.org'

gemspec
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,15 @@ oxidized

Now tell Oxidized where it finds a list of network devices to backup configuration from. You can either use CSV or SQLite as source. To create a CSV source add the following snippet:

Note: If gpg is set to anything other than false it will attempt to decrypt the file contents
```
source:
default: csv
csv:
file: ~/.config/oxidized/router.db
delimiter: !ruby/regexp /:/
gpg: false
gpg_password: 'password'
map:
name: 0
model: 1
Expand Down
11 changes: 10 additions & 1 deletion lib/oxidized/source/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ def setup
Oxidized.asetus.user.source.csv.delimiter = /:/
Oxidized.asetus.user.source.csv.map.name = 0
Oxidized.asetus.user.source.csv.map.model = 1
Oxidized.asetus.user.source.csv.gpg = false
Oxidized.asetus.save :user
raise NoConfig, 'no source csv config, edit ~/.config/oxidized/config'
end
require 'gpgme' if @cfg.gpg?
end

def load
nodes = []
open(File.expand_path @cfg.file).each_line do |line|
file = File.expand_path(@cfg.file)
file = if @cfg.gpg?
crypto = GPGME::Crypto.new password: @cfg.gpg_password
crypto.decrypt(file).to_s
else
open(file)
end
file.each_line do |line|
next if line.match(/^\s*#/)
data = line.chomp.split(@cfg.delimiter, -1)
next if data.empty?
Expand Down

0 comments on commit 2a69179

Please sign in to comment.