From da8923512737f0d9383feaebaf43e781e914b71e Mon Sep 17 00:00:00 2001 From: Michael Baker Date: Thu, 23 Nov 2017 06:18:41 +0800 Subject: fix: GPG bug fix when loading file (#1109) * GPG bug fix * Update Sources.md * Update README.md --- README.md | 3 --- docs/Sources.md | 25 +++++++++++++++++++++++++ lib/oxidized/source/csv.rb | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2262d79..d501cb5 100644 --- a/README.md +++ b/README.md @@ -246,15 +246,12 @@ 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/docs/Sources.md b/docs/Sources.md index b04261c..7029b72 100644 --- a/docs/Sources.md +++ b/docs/Sources.md @@ -26,6 +26,31 @@ Example csv `/var/lib/oxidized/router.db`: rtr01.local:192.168.1.1:ios:oxidized:5uP3R53cR3T:T0p53cR3t ``` +If you would like to use a GPG encrypted file as the source then you can use the following example: + +```yaml +source: + default: csv + csv: + file: ~/.config/oxidized/router.db + delimiter: !ruby/regexp /:/ + gpg: true + gpg_password: 'password' + map: + name: 0 + model: 1 +``` + +> Please note, if you are running GPG v2 then you will be prompted for your gpg password on start up, if you use GPG >= 2.1 then you can add the following config to stop that behaviour: + +> Within `~/.gnupg/gpg-agent.conf` + +> `allow-loopback-pinentry` + +> and within: `~/.gnupg/gpg.conf` + +> `pinentry-mode loopback` + ### Source: SQL Oxidized uses the `sequel` ruby gem. You can use a variety of databases that aren't explicitly listed. For more information visit https://github.com/jeremyevans/sequel Make sure you have the correct adapter! ### Source: MYSQL diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index c1e310a..27cb49e 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -21,9 +21,9 @@ class CSV < Source def load nodes = [] file = File.expand_path(@cfg.file) - file = if @cfg.gpg? + if @cfg.gpg? crypto = GPGME::Crypto.new password: @cfg.gpg_password - crypto.decrypt(file).to_s + file = crypto.decrypt(File.open(file)).to_s else open(file) end -- cgit v1.2.1