Skip to content

Commit

Permalink
Added plugin finder for purpose of plugin cmdline options
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Meakin committed Aug 8, 2013
1 parent a49b677 commit c6b3fe8
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
6 changes: 6 additions & 0 deletions bin/eyaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

require 'rubygems'
require 'hiera/backend/eyaml/CLI'
require 'hiera/backend/eyaml/plugins'
require 'hiera/backend/eyaml/encryptors/pkcs7'

# Register all plugins
Hiera::Backend::Eyaml::Encryptors::Pkcs7.register
Hiera::Backend::Eyaml::Plugins.find

configuration = Hiera::Backend::Eyaml::CLI.parse
Hiera::Backend::Eyaml::CLI.execute configuration
Empty file removed keys/.keepme
Empty file.
8 changes: 6 additions & 2 deletions lib/hiera/backend/eyaml/CLI.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'hiera/backend/eyaml/actions/decrypt_action'
require 'hiera/backend/eyaml/actions/encrypt_action'
require 'hiera/backend/eyaml/actions/edit_action'
require 'hiera/backend/eyaml/plugins'

class Hiera
module Backend
Expand Down Expand Up @@ -39,8 +40,11 @@ def self.parse
opt :stdin, "Source input it taken from stdin", :short => 'z'
opt :encrypt_method, "Override default encryption and decryption method (default is PKCS7)", :short => 'n', :default => "pkcs7"
opt :output, "Output format of final result (examples, block, string)", :type => :string, :default => "examples"
opt :private_key_dir, "Keydir", :type => :string, :default => "./keys"
opt :public_key_dir, "Keydir", :type => :string, :default => "./keys"

Hiera::Backend::Eyaml::Plugins.options.each do |option|
opt option[:name], option[:desc], :type => option[:type], :short => option[:short], :default => option[:default]
end

end

actions = [:createkeys, :decrypt, :encrypt, :edit].collect {|x| x if options[x]}.compact
Expand Down
7 changes: 7 additions & 0 deletions lib/hiera/backend/eyaml/encryptors/pkcs7.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ module Encryptors

class Pkcs7 < Encryptor

def self.register
Hiera::Backend::Eyaml::Plugins.register_options([
{ :name => :private_key_dir, :desc => "Private key directory", :type => :string, :default => "./keys" },
{ :name => :public_key_dir, :desc => "Public key directory", :type => :string, :default => "./keys" }
])
end

ENCRYPT_TAG = "PKCS7"

def encrypt_string plaintext
Expand Down
60 changes: 60 additions & 0 deletions lib/hiera/backend/eyaml/plugins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'rubygems'

class Hiera
module Backend
module Eyaml
class Plugins

@@plugins = []
@@options = []

def self.register_options options_array
@@options += options_array
end

def self.options
@@options
end

def self.find

this_version = Gem::Version.create(Hiera::Backend::Eyaml::VERSION)
index = Gem::VERSION >= "1.8.0" ? Gem::Specification : Gem.source_index

[index].flatten.each do |source|

specs.each do |spec|
next if @@plugins.include? spec

# If this gem depends on Vagrant, verify this is a valid release of
# Vagrant for this gem to load into.
dependency = spec.dependencies.find { |d| d.name == "hiera-eyaml" }
next if dependency && !dependency.requirement.satisfied_by? this_version

file = nil
if Gem::VERSION >= "1.8.0"
file = spec.matches_for_glob("**/eyaml_init.rb").first
else
file = Gem.searcher.matching_files(spec, "eyaml_init.rb").first
end

next unless file

@@plugins << spec
load file
end

end

@@plugins

end

def self.plugins
@@plugins
end

end
end
end
end

0 comments on commit c6b3fe8

Please sign in to comment.