-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GPG support for reading router.db #674
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'gpgme' | ||
gemspec |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
gpg_password: 'password' | ||
map: | ||
name: 0 | ||
model: 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,21 @@ def setup | |
Oxidized.asetus.user.source.csv.delimiter = /:/ | ||
Oxidized.asetus.user.source.csv.map.name = 0 | ||
Oxidized.asetus.user.source.csv.map.model = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this line being removed intentionally? If so, can you try to elaborate why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry! Back in again :) |
||
Oxidized.asetus.user.source.csv.gpg = false | ||
Oxidized.asetus.save :user | ||
raise NoConfig, 'no source csv config, edit ~/.config/oxidized/config' | ||
end | ||
end | ||
|
||
def load | ||
nodes = [] | ||
open(File.expand_path @cfg.file).each_line do |line| | ||
if @cfg.gpg != 'false' | ||
crypto = GPGME::Crypto.new :password => @cfg.gpg_password | ||
file = crypto.decrypt(File.open(@cfg.file)).to_s | ||
else | ||
file = open(File.expand_path @cfg.file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps
|
||
end | ||
file.each_line do |line| | ||
next if line.match(/^\s*#/) | ||
data = line.chomp.split(@cfg.delimiter, -1) | ||
next if data.empty? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't put requirements in Gemfile, they're in spec file. But I would not want to mandate installing
gpgme
. I would put it inCVS#setup
asrequire 'gpgme' if @cfg.gpg
, so that we only load it, if user is actually using it.