From e4680d181c368d901e27023c1f7ab524007d5b64 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Tue, 24 Jan 2017 06:47:57 +0800 Subject: Untested GPG work --- Gemfile | 2 +- README.md | 2 ++ lib/oxidized/manager.rb | 1 + lib/oxidized/source/csv.rb | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index fa75df1..23758ed 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' - +gem 'gpgme' gemspec diff --git a/README.md b/README.md index fe58322..61e8b8a 100644 --- a/README.md +++ b/README.md @@ -235,12 +235,14 @@ 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' map: name: 0 model: 1 diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb index bf28ae7..60394fd 100644 --- a/lib/oxidized/manager.rb +++ b/lib/oxidized/manager.rb @@ -3,6 +3,7 @@ module Oxidized require 'oxidized/input/input' require 'oxidized/output/output' require 'oxidized/source/source' + require 'gpgme' class Manager class << self def load dir, file diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index d498e0b..c41162d 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -11,6 +11,7 @@ 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 @@ -18,7 +19,8 @@ class CSV < Source def load nodes = [] - open(File.expand_path @cfg.file).each_line do |line| + file = @cfg.gpg == 'false' ? open(File.expand_path @cfg.file) : crypto.decrypt File.open(@cfg.file) + open(file).each_line do |line| next if line.match(/^\s*#/) data = line.chomp.split(@cfg.delimiter, -1) next if data.empty? -- cgit v1.2.1 From da69f568422ad918e734ecbc0feef15b1b7cac03 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Tue, 24 Jan 2017 06:50:24 +0800 Subject: Syntax error --- lib/oxidized/source/csv.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index c41162d..757acf4 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -19,7 +19,7 @@ class CSV < Source def load nodes = [] - file = @cfg.gpg == 'false' ? open(File.expand_path @cfg.file) : crypto.decrypt File.open(@cfg.file) + file = (@cfg.gpg == 'false') ? open(File.expand_path @cfg.file) : crypto.decrypt(File.open(@cfg.file)) open(file).each_line do |line| next if line.match(/^\s*#/) data = line.chomp.split(@cfg.delimiter, -1) -- cgit v1.2.1 From 737ffa54eb42537f9fbd6bb6a2a708507fd802e3 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Tue, 24 Jan 2017 07:40:36 +0800 Subject: Update --- lib/oxidized/source/csv.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index 757acf4..dc246ab 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -19,6 +19,7 @@ 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| next if line.match(/^\s*#/) -- cgit v1.2.1 From 62a990bc08c23684840d34eccd46c54197cb7d02 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Tue, 24 Jan 2017 07:44:23 +0800 Subject: GPG support --- README.md | 1 + lib/oxidized/source/csv.rb | 10 +++++++--- 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? -- cgit v1.2.1 From 0e7bbeaad452e8e719e1d66c314bcc4523e46579 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Tue, 24 Jan 2017 07:50:44 +0800 Subject: GPG support working --- lib/oxidized/source/csv.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index 85fee77..449b297 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -21,7 +21,7 @@ class CSV < Source nodes = [] if @cfg.gpg != 'false' crypto = GPGME::Crypto.new :password => @cfg.gpg_password - file = crypto.decrypt(File.open(@cfg.file)) + file = crypto.decrypt(File.open(@cfg.file)).to_s else file = open(File.expand_path @cfg.file) end -- cgit v1.2.1 From ce283fa4399bf0bfaf7d677e52ce7a65b424e776 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Tue, 24 Jan 2017 10:45:34 +0800 Subject: Requested changes --- Gemfile | 1 - README.md | 2 +- lib/oxidized/manager.rb | 1 - lib/oxidized/source/csv.rb | 13 +++++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index 23758ed..851fabc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,2 @@ source 'https://rubygems.org' -gem 'gpgme' gemspec diff --git a/README.md b/README.md index 4024efd..8921e8e 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ source: csv: file: ~/.config/oxidized/router.db delimiter: !ruby/regexp /:/ - gpg: 'false' + gpg: false gpg_password: 'password' map: name: 0 diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb index 60394fd..bf28ae7 100644 --- a/lib/oxidized/manager.rb +++ b/lib/oxidized/manager.rb @@ -3,7 +3,6 @@ module Oxidized require 'oxidized/input/input' require 'oxidized/output/output' require 'oxidized/source/source' - require 'gpgme' class Manager class << self def load dir, file diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index 449b297..c508358 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -10,21 +10,22 @@ class CSV < Source Oxidized.asetus.user.source.csv.file = File.join(Config::Root, 'router.db') 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 = [] - if @cfg.gpg != 'false' - crypto = GPGME::Crypto.new :password => @cfg.gpg_password - file = crypto.decrypt(File.open(@cfg.file)).to_s + file = File.expand_path(@cfg.file) + file = if @cfg.gpg? + crypto = GPGME::Crypto.new password: @cfg.gpg_password + crypto.decrypt(file).to_s else - file = open(File.expand_path @cfg.file) - end + open(file) + end file.each_line do |line| next if line.match(/^\s*#/) data = line.chomp.split(@cfg.delimiter, -1) -- cgit v1.2.1 From 07b4d0c52ce7b5c2377a4547686b95b7ddb62986 Mon Sep 17 00:00:00 2001 From: mbakerbp Date: Wed, 25 Jan 2017 05:46:50 +0800 Subject: Update --- lib/oxidized/source/csv.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index c508358..c1e310a 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -10,6 +10,7 @@ class CSV < Source Oxidized.asetus.user.source.csv.file = File.join(Config::Root, 'router.db') 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' -- cgit v1.2.1