summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormbakerbp <michael.baker@bulletproof.net>2017-01-24 07:44:23 +0800
committermbakerbp <michael.baker@bulletproof.net>2017-01-24 07:44:23 +0800
commit62a990bc08c23684840d34eccd46c54197cb7d02 (patch)
treea9818c4c9487edcc4773da162d8d89cf60f45fdc
parent737ffa54eb42537f9fbd6bb6a2a708507fd802e3 (diff)
GPG support
-rw-r--r--README.md1
-rw-r--r--lib/oxidized/source/csv.rb10
2 files changed, 8 insertions, 3 deletions
diff --git a/README.md b/README.md
index 61e8b8a..4024efd 100644
--- a/README.md
+++ b/README.md
@@ -243,6 +243,7 @@ source:
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 dc246ab..85fee77 100644
--- a/lib/oxidized/source/csv.rb
+++ b/lib/oxidized/source/csv.rb
@@ -19,9 +19,13 @@ class CSV < Source
def load
nodes = []
- crypto = GPGME::Crypto.new
- file = (@cfg.gpg == 'false') ? open(File.expand_path @cfg.file) : crypto.decrypt(File.open(@cfg.file))
- open(file).each_line do |line|
+ if @cfg.gpg != 'false'
+ crypto = GPGME::Crypto.new :password => @cfg.gpg_password
+ file = crypto.decrypt(File.open(@cfg.file))
+ else
+ file = open(File.expand_path @cfg.file)
+ end
+ file.each_line do |line|
next if line.match(/^\s*#/)
data = line.chomp.split(@cfg.delimiter, -1)
next if data.empty?