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