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
95
96
97
|
# 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 "Hiera-eyaml is a backend for Hiera which provides OpenSSL encryption/decryption for Hiera properties\n\nUsage:\n eyaml [options] \n eyaml -i file.eyaml # edit a file\n eyaml -e -s some-string # encrypt a string\n eyaml -e -p # encrypt a password \n eyaml -e -f file.txt # encrypt a file\n cat file.txt | eyaml -e # encrypt a file on a pipe\n\nOptions: \n EOS\n \n opt :createkeys, \"Create public and private keys for use encrypting properties\", :short => 'c'\n opt :decrypt, \"Decrypt something\", :short => 'd'\n opt :encrypt, \"Encrypt something\", :short => 'e'\n opt :edit, \"Decrypt, Edit, and Reencrypt\", :short => 'i', :type => :string\n opt :eyaml, \"Source input is an eyaml file\", :short => 'y', :type => :string\n opt :password, \"Source input is a password entered on the terminal\", :short => 'p'\n opt :string, \"Source input is a string provided as an argument\", :short => 's', :type => :string\n opt :file, \"Source input is a file\", :short => 'f', :type => :string\n opt :stdin, \"Source input is taken from stdin\", :short => :none\n opt :encrypt_method, \"Override default encryption and decryption method (default is PKCS7)\", :short => 'n', :default => \"pkcs7\"\n opt :output, \"Output format of final result (examples, block, string)\", :type => :string, :short => 'o', :default => \"examples\"\n opt :label, \"Apply a label to the encrypted result\", :short => 'l', :type => :string\n opt :debug, \"Be more verbose\", :short => :none\n opt :quiet, \"Be less verbose\", :short => :none\n\n Hiera::Backend::Eyaml::Plugins.options.each do |name, option|\n opt name, option[:desc], :type => option[:type], :short => option[:short], :default => option[:default]\n end\n\n end\n\n actions = [:createkeys, :decrypt, :encrypt, :edit].collect {|x| x if options[x]}.compact\n sources = [:edit, :eyaml, :password, :string, :file, :stdin].collect {|x| x if options[x]}.compact\n # sources << :stdin if STDIN\n\n Trollop::die \"You can only specify one of (\#{actions.join(', ')})\" if actions.count > 1\n Trollop::die \"You can only specify one of (\#{sources.join(', ')})\" if sources.count > 1\n Trollop::die \"Creating keys does not require a source to encrypt/decrypt\" if actions.first == :createkeys and sources.count > 0\n\n options[:source] = sources.first\n options[:action] = actions.first\n options[:source] = :not_applicable if options[:action] == :createkeys\n\n Trollop::die \"Nothing to do\" if options[:source].nil? or options[:action].nil?\n\n options[:input_data] = case options[:source]\n when :stdin\n STDIN.read\n when :password\n Utils.read_password\n when :string\n options[:string]\n when :file\n File.read options[:file]\n when :eyaml\n File.read options[:eyaml]\n when :stdin\n STDIN.read\n else\n if options[:edit]\n options[:eyaml] = options[:edit]\n options[:source] = :eyaml\n File.read options[:edit] \n else\n nil\n end\n end\n\n Eyaml.default_encryption_scheme = options[:encrypt_method].upcase if options[:encrypt_method]\n Eyaml::Options.set options\n Eyaml::Options.debug\n\nend\n"
|