-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward whitelisted gpg options to gpg #23
- Loading branch information
1 parent
7c2c2c1
commit cfe66b8
Showing
7 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'shellwords' | ||
|
||
|
||
module Gem::OpenPGP | ||
extend Shellwords | ||
|
||
WHITELISTED_GPG_OPTIONS = { | ||
"homedir" => "dir", | ||
"verbose" => nil, | ||
"default-user" => "user_id", | ||
"local-user" => "user_id", | ||
"passphrase-fd" => "file_descriptor", | ||
"passphrase-file" => "file_name" | ||
} | ||
|
||
def self.gpg_options | ||
@gpg_options ||= {} | ||
@gpg_options | ||
end | ||
|
||
def self.add_gpg_options cmd | ||
WHITELISTED_GPG_OPTIONS.each_pair do |flag, arg| | ||
mangled_flag = "--gpg-#{flag}" | ||
mangled_flag += " #{arg}" if arg.is_a? String | ||
|
||
cmd.add_option(mangled_flag,"Forward option --#{flag} to gpg") do |value, options| | ||
value = true if arg.nil? #boolean | ||
gpg_options[flag] = value | ||
end | ||
end | ||
end | ||
|
||
def self.get_gpg_options | ||
options = [] | ||
gpg_options.each_pair do |flag, value| | ||
new_flag = "--#{flag}" | ||
if value.is_a? String | ||
new_flag += " " + shellescape(value) | ||
end | ||
options << new_flag | ||
end | ||
|
||
options.join(" ") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
require 'rubygems/gem_openpgp' | ||
require 'rubygems/openpgp/sign_plugins' | ||
require 'rubygems/openpgp/verify_plugins' | ||
require 'rubygems/openpgp/gpg_options' | ||
|
||
# Add gpg forwarding options | ||
[:sign, :verify, :build, :install].each do |cmd_name| | ||
cmd = Gem::CommandManager.instance[cmd_name] | ||
Gem::OpenPGP.add_gpg_options(cmd) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'test/unit' | ||
require 'mocha/setup' | ||
|
||
require "rubygems/command" | ||
require 'rubygems/openpgp/gpg_options' | ||
|
||
class Gem::Commands::TestCommand < Gem::Command | ||
end | ||
|
||
class GpgOptionsText < Test::Unit::TestCase | ||
def setup | ||
@test_cmd = Gem::Command.new "test", "summary" | ||
Gem::OpenPGP.add_gpg_options(@test_cmd) | ||
end | ||
|
||
def teardown | ||
Gem::OpenPGP.instance_variable_set(:@gpg_options,{}) | ||
end | ||
|
||
def test_option_with_argument | ||
@test_cmd.handle_options %W[--gpg-homedir /home/foo/alt-dir] | ||
assert_equal Gem::OpenPGP.gpg_options["homedir"], "/home/foo/alt-dir" | ||
end | ||
|
||
def test_option_with_argument_build | ||
@test_cmd.handle_options %W[--gpg-homedir /home/foo/alt-dir] | ||
assert_equal Gem::OpenPGP.get_gpg_options, "--homedir /home/foo/alt-dir" | ||
end | ||
|
||
def test_option | ||
@test_cmd.handle_options %W[--gpg-verbose] | ||
assert_equal Gem::OpenPGP.gpg_options["verbose"], true | ||
end | ||
|
||
def test_option_build | ||
@test_cmd.handle_options %W[--gpg-verbose] | ||
assert_equal Gem::OpenPGP.get_gpg_options, "--verbose" | ||
end | ||
|
||
|
||
end |