16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/hiera/backend/eyaml/CLI.rb', line 16
def self.parse
options = Trollop::options do
version "Hiera-eyaml version " + Hiera::Backend::Eyaml::VERSION.to_s
banner <<-EOS
Hiera-eyaml is a backend for Hiera which provides OpenSSL encryption/decryption for Hiera properties
Usage:
eyaml [options]
eyaml -i file.eyaml # edit a file
eyaml -e -s some-string # encrypt a string
eyaml -e -p # encrypt a password
eyaml -e -f file.txt # encrypt a file
cat file.txt | eyaml -e # encrypt a file on a pipe
Options:
EOS
opt :createkeys, "Create public and private keys for use encrypting properties", :short => 'c'
opt :decrypt, "Decrypt something"
opt :encrypt, "Encrypt something"
opt :edit, "Decrypt, Edit, and Reencrypt", :type => :string
opt :eyaml, "Source input is an eyaml file", :type => :string
opt :password, "Source input is a password entered on the terminal", :short => 'p'
opt :string, "Source input is a string provided as an argument", :short => 's', :type => :string
opt :file, "Source input is a file", :short => 'f', :type => :string
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 :label, "Apply a label to the encrypted result", :short => 'l', :type => :string
Hiera::Backend::Eyaml::Plugins.options.each do |name, option|
opt 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
sources = [:edit, :eyaml, :password, :string, :file, :stdin].collect {|x| x if options[x]}.compact
Trollop::die "You can only specify one of (#{actions.join(', ')})" if actions.count > 1
Trollop::die "You can only specify one of (#{sources.join(', ')})" if sources.count > 1
Trollop::die "Creating keys does not require a source to encrypt/decrypt" if actions.first == :createkeys and sources.count > 0
options[:source] = sources.first
options[:action] = actions.first
options[:source] = :not_applicable if options[:action] == :createkeys
Trollop::die "Nothing to do" if options[:source].nil? or options[:action].nil?
options[:input_data] = case options[:source]
when :stdin
STDIN.read
when :password
Utils.read_password
when :string
options[:string]
when :file
File.read options[:file]
when :eyaml
File.read options[:eyaml]
when :stdin
STDIN.read
else
if options[:edit]
options[:eyaml] = options[:edit]
options[:source] = :eyaml
File.read options[:edit]
else
nil
end
end
Eyaml.default_encryption_scheme = options[:encrypt_method].upcase if options[:encrypt_method]
Eyaml::Options.set options
end
|