summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2017-01-25 00:02:56 +0200
committerGitHub <noreply@github.com>2017-01-25 00:02:56 +0200
commit2a69179c7765455ad9b468f33c8df78188e7dec5 (patch)
treed66e7664953eca981ea1eb885304c1ee26dcb256
parent8375aa0ad364e4cb274ba96be1ddfb312c148e38 (diff)
parent07b4d0c52ce7b5c2377a4547686b95b7ddb62986 (diff)
Merge pull request #674 from bulletproofnetworks/master
Add GPG support for reading router.db
-rw-r--r--Gemfile1
-rw-r--r--README.md3
-rw-r--r--lib/oxidized/source/csv.rb11
3 files changed, 13 insertions, 2 deletions
diff --git a/Gemfile b/Gemfile
index fa75df1..851fabc 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,2 @@
source 'https://rubygems.org'
-
gemspec
diff --git a/README.md b/README.md
index fe58322..8921e8e 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb
index d498e0b..c1e310a 100644
--- a/lib/oxidized/source/csv.rb
+++ b/lib/oxidized/source/csv.rb
@@ -11,14 +11,23 @@ class CSV < Source
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?