hiera-eyaml 2.1.0.rc1 → 2.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fa5555914a9b40a4861fa8ab7462fddd2666c5a
4
- data.tar.gz: cd492618ec115206ab9dd98c29d1300c2c69533f
3
+ metadata.gz: 16a11266f8a3a70c5dd4387ddcc5729b6c26c36d
4
+ data.tar.gz: 543372f0517d250edf247b7ce8bbf2b9c14e4f92
5
5
  SHA512:
6
- metadata.gz: 054f773f175f90541f94bb99400c47ba9bbd9fb5f0af2698f6bc13011bc78e90231ee055eafbdd0c9c9e0baae48246153ad1093e2af5a61775b684be95a83e25
7
- data.tar.gz: 0467744b19299bed0e591082cfe0943eeb4ee4516bfaa7ad460ff854581c879de13b69a1a8a44e77dd085aedee3c62f60a28dec2eab57594cc1817dddf1419e4
6
+ metadata.gz: ac1c9f752166c867a727ee4712ee346856ba44891d4260a308898c8f4ba7aeda014c3c16d56251d998386956c317851b8e33f711f70fed26ac1bee4a92d630f5
7
+ data.tar.gz: fecff71c9049404b361b5d38d92d8f42a3c7fb2078ae95adaa7ab34d74880c1b7aacd800707d063b2d528f8ab1a58665a0c50e25edfaef505d56b03426c4e359
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org/'
2
2
 
3
- gem 'highline', '~> 1.6.19'
4
- gem 'trollop', '~> 2.0'
3
+ gemspec
5
4
 
6
5
  group :development do
7
6
  gem "aruba", '~> 0.6.2'
data/bin/eyaml CHANGED
@@ -12,15 +12,15 @@ Hiera::Backend::Eyaml::Plugins.find
12
12
  begin
13
13
  Hiera::Backend::Eyaml::CLI.parse
14
14
  rescue StandardError => e
15
- Hiera::Backend::Eyaml::Utils.warn e.message
16
- Hiera::Backend::Eyaml::Utils.debug e.backtrace.join("\n")
15
+ Hiera::Backend::Eyaml::LoggingHelper.warn e.message
16
+ Hiera::Backend::Eyaml::LoggingHelper.debug e.backtrace.join("\n")
17
17
  exit 1
18
18
  end
19
19
 
20
20
  begin
21
21
  Hiera::Backend::Eyaml::CLI.execute
22
22
  rescue StandardError => e
23
- Hiera::Backend::Eyaml::Utils.warn e.message
24
- Hiera::Backend::Eyaml::Utils.debug e.backtrace.join("\n")
23
+ Hiera::Backend::Eyaml::LoggingHelper.warn e.message
24
+ Hiera::Backend::Eyaml::LoggingHelper.debug e.backtrace.join("\n")
25
25
  exit 1
26
26
  end
@@ -2,7 +2,7 @@ class Hiera
2
2
  module Backend
3
3
  module Eyaml
4
4
 
5
- VERSION = "2.1.0.rc1"
5
+ VERSION = "2.1.0.rc2"
6
6
  DESCRIPTION = "Hiera-eyaml is a backend for Hiera which provides OpenSSL encryption/decryption for Hiera properties"
7
7
 
8
8
  class RecoverableError < StandardError
@@ -1,5 +1,6 @@
1
1
  require 'trollop'
2
2
  require 'hiera/backend/eyaml'
3
+ require 'hiera/backend/eyaml/logginghelper'
3
4
  require 'hiera/backend/eyaml/utils'
4
5
  require 'hiera/backend/eyaml/plugins'
5
6
  require 'hiera/backend/eyaml/options'
@@ -45,8 +46,8 @@ class Hiera
45
46
  result = executor.execute
46
47
  puts result unless result.nil?
47
48
  rescue Exception => e
48
- Utils.warn e.message
49
- Utils.debug e.backtrace.join("\n")
49
+ LoggingHelper.warn e.message
50
+ LoggingHelper.debug e.backtrace.join("\n")
50
51
  end
51
52
 
52
53
  end
@@ -0,0 +1,72 @@
1
+ require 'hiera/backend/eyaml/logginghelper'
2
+
3
+ class Hiera
4
+ module Backend
5
+ module Eyaml
6
+ class EditHelper
7
+
8
+ def self.find_editor
9
+ editor = ENV['EDITOR']
10
+ editor ||= %w{ /usr/bin/sensible-editor /usr/bin/editor /usr/bin/vim /usr/bin/vi }.collect {|e| e if FileTest.executable? e}.compact.first
11
+ raise StandardError, "Editor not found. Please set your EDITOR env variable" if editor.nil?
12
+ if editor.index(' ')
13
+ editor = editor.dup if editor.frozen? # values from ENV are frozen
14
+ editor.gsub!(/([^\\]|^)~/, '\1' + ENV['HOME']) # replace ~ with home unless escaped
15
+ editor.gsub!(/(^|[^\\])"/, '\1') # remove unescaped quotes during processing
16
+ editor.gsub!(/\\ /, ' ') # unescape spaces since we quote paths
17
+ pieces = editor.split(' ')
18
+ paths = pieces.each_with_index.map {|_,x| pieces[0..x].join(' ')}.reverse # get possible paths, starting with longest
19
+ extensions = (ENV['PATHEXT'] || '').split(';') # handle Windows executables
20
+ pathdirs = ENV['PATH'].split(File::PATH_SEPARATOR)
21
+ paths += pathdirs.collect { |dir| paths.collect { |path| File.expand_path(path, dir) } }.flatten
22
+ editorfile = paths.select { |path|
23
+ FileTest.file?(path) || ! extensions.select {|ext| FileTest.file?(path + ext) }.empty?
24
+ }.first
25
+ raise StandardError, "Editor not found. Please set your EDITOR env variable" if editorfile.nil?
26
+ raw_command = paths[(paths.index editorfile) % pieces.size]
27
+ editor = "\"#{editorfile}\"#{editor[raw_command.size()..-1]}"
28
+ end
29
+ editor
30
+ end
31
+
32
+ def self.secure_file_delete args
33
+ file = File.open(args[:file], 'r+')
34
+ num_bytes = args[:num_bytes]
35
+ [0xff, 0x55, 0xaa, 0x00].each do |byte|
36
+ file.seek(0, IO::SEEK_SET)
37
+ num_bytes.times { file.print(byte.chr) }
38
+ file.fsync
39
+ end
40
+ file.close
41
+ File.delete args[:file]
42
+ end
43
+
44
+ def self.write_tempfile data_to_write
45
+ file = Tempfile.open(['eyaml_edit', '.yaml'])
46
+ path = file.path
47
+ file.close!
48
+
49
+ file = File.open(path, "w")
50
+ file.chmod(0600)
51
+ if ENV['OS'] == 'Windows_NT'
52
+ # Windows doesn't support chmod
53
+ icacls = 'C:\Windows\system32\icacls.exe'
54
+ if File.executable? icacls
55
+ current_user = `C:\\Windows\\system32\\whoami.exe`.chomp
56
+ # Use ACLs to restrict access to the current user only
57
+ command = %Q{#{icacls} "#{file.path}" /grant:r "#{current_user}":f /inheritance:r}
58
+ system "#{command} >NUL 2>&1"
59
+ end
60
+ end
61
+ file.puts data_to_write
62
+ file.close
63
+
64
+ LoggingHelper::debug "Wrote temporary file: #{path}"
65
+
66
+ path
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,40 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+
4
+ class Hiera
5
+ module Backend
6
+ module Eyaml
7
+ class EncryptHelper
8
+
9
+ def self.write_important_file args
10
+ require 'hiera/backend/eyaml/highlinehelper'
11
+ filename = args[ :filename ]
12
+ content = args[ :content ]
13
+ mode = args[ :mode ]
14
+ if File.file? "#{filename}"
15
+ raise StandardError, "User aborted" unless HighlineHelper::confirm? "Are you sure you want to overwrite \"#{filename}\"?"
16
+ end
17
+ open( "#{filename}", "w" ) do |io|
18
+ io.write(content)
19
+ end
20
+ File.chmod( mode, filename ) unless mode.nil?
21
+ end
22
+
23
+ def self.ensure_key_dir_exists key_file
24
+ key_dir = File.dirname key_file
25
+
26
+ unless File.directory? key_dir
27
+ begin
28
+ FileUtils.mkdir_p key_dir
29
+ LoggingHelper::info "Created key directory: #{key_dir}"
30
+ rescue
31
+ raise StandardError, "Cannot create key directory: #{key_dir}"
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  require 'base64'
2
- require 'hiera/backend/eyaml/utils'
2
+ require 'hiera/backend/eyaml/encrypthelper'
3
3
 
4
4
  class Hiera
5
5
  module Backend
@@ -60,19 +60,19 @@ class Hiera
60
60
  end
61
61
 
62
62
  def self.trace msg
63
- Utils::trace :from => plugin_classname, :msg => msg
63
+ LoggingHelper::trace :from => plugin_classname, :msg => msg
64
64
  end
65
65
 
66
66
  def self.debug msg
67
- Utils::debug :from => plugin_classname, :msg => msg
67
+ LoggingHelper::debug :from => plugin_classname, :msg => msg
68
68
  end
69
69
 
70
70
  def self.info msg
71
- Utils::info :from => plugin_classname, :msg => msg
71
+ LoggingHelper::info :from => plugin_classname, :msg => msg
72
72
  end
73
73
 
74
74
  def self.warn msg
75
- Utils::warn :from => plugin_classname, :msg => msg
75
+ LoggingHelper::warn :from => plugin_classname, :msg => msg
76
76
  end
77
77
 
78
78
  end
@@ -1,6 +1,7 @@
1
1
  require 'openssl'
2
2
  require 'hiera/backend/eyaml/encryptor'
3
- require 'hiera/backend/eyaml/utils'
3
+ require 'hiera/backend/eyaml/encrypthelper'
4
+ require 'hiera/backend/eyaml/logginghelper'
4
5
  require 'hiera/backend/eyaml/options'
5
6
 
6
7
  class Hiera
@@ -65,8 +66,8 @@ class Hiera
65
66
  subject = self.option :subject
66
67
 
67
68
  key = OpenSSL::PKey::RSA.new(2048)
68
- Utils.ensure_key_dir_exists private_key
69
- Utils.write_important_file :filename => private_key, :content => key.to_pem, :mode => 0600
69
+ EncryptHelper.ensure_key_dir_exists private_key
70
+ EncryptHelper.write_important_file :filename => private_key, :content => key.to_pem, :mode => 0600
70
71
 
71
72
  cert = OpenSSL::X509::Certificate.new()
72
73
  cert.subject = OpenSSL::X509::Name.parse(subject)
@@ -92,9 +93,9 @@ class Hiera
92
93
 
93
94
  cert.sign key, OpenSSL::Digest::SHA1.new
94
95
 
95
- Utils.ensure_key_dir_exists public_key
96
- Utils.write_important_file :filename => public_key, :content => cert.to_pem
97
- Utils.info "Keys created OK"
96
+ EncryptHelper.ensure_key_dir_exists public_key
97
+ EncryptHelper.write_important_file :filename => public_key, :content => cert.to_pem
98
+ LoggingHelper.info "Keys created OK"
98
99
 
99
100
  end
100
101
 
@@ -0,0 +1,24 @@
1
+ require 'highline/import'
2
+
3
+ class Hiera
4
+ module Backend
5
+ module Eyaml
6
+ class HighlineHelper
7
+
8
+ def self.read_password
9
+ ask("Enter password: ") {|q| q.echo = "*" }
10
+ end
11
+
12
+ def self.confirm? message
13
+ result = ask("#{message} (y/N): ")
14
+ if result.downcase == "y" or result.downcase == "yes"
15
+ true
16
+ else
17
+ false
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,80 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+
4
+ class Hiera
5
+ module Backend
6
+ module Eyaml
7
+ class LoggingHelper
8
+
9
+ def self.structure_message messageinfo
10
+ message = {:from => "hiera-eyaml-core"}
11
+ case messageinfo.class.to_s
12
+ when 'Hash'
13
+ message.merge!(messageinfo)
14
+ else
15
+ message.merge!({:msg => messageinfo.to_s})
16
+ end
17
+ message[:prefix] = "[#{message[:from]}]"
18
+ message[:spacer] = " #{' ' * message[:from].length} "
19
+ formatted_output = message[:msg].split("\n").each_with_index.map do |line, index|
20
+ if index == 0
21
+ "#{message[:prefix]} #{line}"
22
+ else
23
+ "#{message[:spacer]} #{line}"
24
+ end
25
+ end
26
+ formatted_output.join "\n"
27
+ end
28
+
29
+ def self.warn messageinfo
30
+ self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :warn, :cli_color => :red })
31
+ end
32
+
33
+ def self.info messageinfo
34
+ self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :debug, :cli_color => :white, :threshold => 0 })
35
+ end
36
+
37
+ def self.debug messageinfo
38
+ self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :debug, :cli_color => :green, :threshold => 1 })
39
+ end
40
+
41
+ def self.trace messageinfo
42
+ self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :debug, :cli_color => :blue, :threshold => 2 })
43
+ end
44
+
45
+ def self.print_message( args )
46
+ message = args[:message] ||= ""
47
+ hiera_loglevel = args[:hiera_loglevel] ||= :debug
48
+ cli_color = args[:cli_color] ||= :blue
49
+ threshold = args[:threshold]
50
+
51
+ if self.hiera?
52
+ Hiera.send(hiera_loglevel, message) if threshold.nil? or Eyaml.verbosity_level > threshold
53
+ else
54
+ STDERR.puts self.colorize( message, cli_color ) if threshold.nil? or Eyaml.verbosity_level > threshold
55
+ end
56
+ end
57
+
58
+ def self.colorize message, color
59
+ suffix = "\e[0m"
60
+ prefix = case color
61
+ when :red
62
+ "\e[31m"
63
+ when :green
64
+ "\e[32m"
65
+ when :blue
66
+ "\e[34m"
67
+ else #:white
68
+ "\e[0m"
69
+ end
70
+ "#{prefix}#{message}#{suffix}"
71
+ end
72
+
73
+ def self.hiera?
74
+ "hiera".eql? Eyaml::Options[:source]
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end
@@ -21,16 +21,16 @@ class Hiera
21
21
  end
22
22
 
23
23
  def self.trace
24
- Utils::trace "Dump of eyaml tool options dict:"
25
- Utils::trace "--------------------------------"
24
+ LoggingHelper::trace "Dump of eyaml tool options dict:"
25
+ LoggingHelper::trace "--------------------------------"
26
26
  @@options.each do |k, v|
27
27
  begin
28
- Utils::trace sprintf "%18s %-18s = %18s %-18s", "(#{k.class.name})", k.to_s, "(#{v.class.name})", v.to_s
28
+ LoggingHelper::trace sprintf "%18s %-18s = %18s %-18s", "(#{k.class.name})", k.to_s, "(#{v.class.name})", v.to_s
29
29
  rescue
30
- Utils::trace sprintf "%18s %-18s = %18s %-18s", "(#{k.class.name})", k.to_s, "(#{v.class.name})", "<unprintable>" # case where v is binary
30
+ LoggingHelper::trace sprintf "%18s %-18s = %18s %-18s", "(#{k.class.name})", k.to_s, "(#{v.class.name})", "<unprintable>" # case where v is binary
31
31
  end
32
32
  end
33
- Utils::trace "--------------------------------"
33
+ LoggingHelper::trace "--------------------------------"
34
34
  end
35
35
 
36
36
  end
@@ -38,7 +38,7 @@ class Hiera
38
38
  [ "/etc/eyaml/config.yaml", "#{ENV['HOME']}/.eyaml/config.yaml", "#{ENV['EYAML_CONFIG']}" ].each do |config_file|
39
39
  begin
40
40
  yaml_contents = YAML.load_file(config_file)
41
- Utils::info "Loaded config from #{config_file}"
41
+ LoggingHelper::info "Loaded config from #{config_file}"
42
42
  config.merge! yaml_contents
43
43
  rescue
44
44
  raise StandardError, "Could not open config file \"#{config_file}\" for reading"
@@ -1,8 +1,8 @@
1
- require 'hiera/backend/eyaml/utils'
1
+ require 'hiera/backend/eyaml/edithelper'
2
+ require 'hiera/backend/eyaml/highlinehelper'
2
3
  require 'hiera/backend/eyaml/options'
3
4
  require 'hiera/backend/eyaml/parser/parser'
4
5
  require 'hiera/backend/eyaml/subcommand'
5
- require 'highline/import'
6
6
 
7
7
  class Hiera
8
8
  module Backend
@@ -61,14 +61,14 @@ eos
61
61
  raise StandardError, "Could not open file for reading: #{options[:eyaml]}"
62
62
  end
63
63
  else
64
- Utils.info "#{options[:eyaml]} doesn't exist, editing new file"
64
+ LoggingHelper.info "#{options[:eyaml]} doesn't exist, editing new file"
65
65
  options[:input_data] = "---"
66
66
  end
67
67
  options
68
68
  end
69
69
 
70
70
  def self.execute
71
- editor = Utils.find_editor
71
+ editor = EditHelper.find_editor
72
72
 
73
73
  encrypted_parser = Parser::ParserFactory.encrypted_parser
74
74
  tokens = encrypted_parser.parse Eyaml::Options[:input_data]
@@ -76,7 +76,7 @@ eos
76
76
  decrypted_file_content = Eyaml::Options[:no_preamble] ? decrypted_input : (self.preamble + decrypted_input)
77
77
 
78
78
  begin
79
- decrypted_file = Utils.write_tempfile decrypted_file_content unless decrypted_file
79
+ decrypted_file = EditHelper.write_tempfile decrypted_file_content unless decrypted_file
80
80
  system "#{editor} \"#{decrypted_file}\""
81
81
  status = $?
82
82
 
@@ -90,7 +90,7 @@ eos
90
90
  raise StandardError, "Edited file is blank" if edited_file.empty?
91
91
 
92
92
  if edited_file == decrypted_input
93
- Utils.info "No changes detected, exiting"
93
+ LoggingHelper.info "No changes detected, exiting"
94
94
  else
95
95
  decrypted_parser = Parser::ParserFactory.decrypted_parser
96
96
  edited_tokens = decrypted_parser.parse(edited_file)
@@ -123,14 +123,14 @@ eos
123
123
  }
124
124
  end
125
125
  rescue RecoverableError => e
126
- Utils.info e
126
+ LoggingHelper.info e
127
127
  if agree "Return to the editor to try again?"
128
128
  retry
129
129
  else
130
130
  raise e
131
131
  end
132
132
  ensure
133
- Utils.secure_file_delete :file => decrypted_file, :num_bytes => [edited_file.length, decrypted_input.length].max
133
+ EditHelper.secure_file_delete :file => decrypted_file, :num_bytes => [edited_file.length, decrypted_input.length].max
134
134
  end
135
135
 
136
136
  nil
@@ -53,7 +53,8 @@ class Hiera
53
53
 
54
54
  options[:input_data] = case options[:source]
55
55
  when :password
56
- Utils.read_password
56
+ require 'hiera/backend/eyaml/highlinehelper'
57
+ HighlineHelper.read_password
57
58
  when :string
58
59
  options[:string]
59
60
  when :file
@@ -19,7 +19,7 @@ class Hiera
19
19
  def self.execute
20
20
  plugin_versions = {}
21
21
 
22
- Eyaml::Utils.info "hiera-eyaml (core): #{Eyaml::VERSION}"
22
+ Eyaml::LoggingHelper.info "hiera-eyaml (core): #{Eyaml::VERSION}"
23
23
 
24
24
  Plugins.plugins.each do |plugin|
25
25
  plugin_shortname = plugin.name.split("hiera-eyaml-").last
@@ -28,7 +28,7 @@ class Hiera
28
28
  rescue
29
29
  "unknown (is plugin compatible with eyaml 2.0+ ?)"
30
30
  end
31
- Eyaml::Utils.info "hiera-eyaml-#{plugin_shortname} (gem): #{plugin_version}"
31
+ Eyaml::LoggingHelper.info "hiera-eyaml-#{plugin_shortname} (gem): #{plugin_version}"
32
32
  end
33
33
 
34
34
  nil
@@ -1,25 +1,12 @@
1
- require 'highline/import'
2
1
  require 'tempfile'
3
2
  require 'fileutils'
3
+ require 'hiera/backend/eyaml/logginghelper'
4
4
 
5
5
  class Hiera
6
6
  module Backend
7
7
  module Eyaml
8
8
  class Utils
9
9
 
10
- def self.read_password
11
- ask("Enter password: ") {|q| q.echo = "*" }
12
- end
13
-
14
- def self.confirm? message
15
- result = ask("#{message} (y/N): ")
16
- if result.downcase == "y" or result.downcase == "yes"
17
- true
18
- else
19
- false
20
- end
21
- end
22
-
23
10
  def self.camelcase string
24
11
  return string if string !~ /_/ && string =~ /[A-Z]+.*/
25
12
  string.split('_').map{|e| e.capitalize}.join
@@ -30,94 +17,6 @@ class Hiera
30
17
  string.split(/(?=[A-Z])/).collect {|x| x.downcase}.join("_")
31
18
  end
32
19
 
33
- def self.find_editor
34
- editor = ENV['EDITOR']
35
- editor ||= %w{ /usr/bin/sensible-editor /usr/bin/editor /usr/bin/vim /usr/bin/vi }.collect {|e| e if FileTest.executable? e}.compact.first
36
- raise StandardError, "Editor not found. Please set your EDITOR env variable" if editor.nil?
37
- if editor.index(' ')
38
- editor = editor.dup if editor.frozen? # values from ENV are frozen
39
- editor.gsub!(/([^\\]|^)~/, '\1' + ENV['HOME']) # replace ~ with home unless escaped
40
- editor.gsub!(/(^|[^\\])"/, '\1') # remove unescaped quotes during processing
41
- editor.gsub!(/\\ /, ' ') # unescape spaces since we quote paths
42
- pieces = editor.split(' ')
43
- paths = pieces.each_with_index.map {|_,x| pieces[0..x].join(' ')}.reverse # get possible paths, starting with longest
44
- extensions = (ENV['PATHEXT'] || '').split(';') # handle Windows executables
45
- pathdirs = ENV['PATH'].split(File::PATH_SEPARATOR)
46
- paths += pathdirs.collect { |dir| paths.collect { |path| File.expand_path(path, dir) } }.flatten
47
- editorfile = paths.select { |path|
48
- FileTest.file?(path) || ! extensions.select {|ext| FileTest.file?(path + ext) }.empty?
49
- }.first
50
- raise StandardError, "Editor not found. Please set your EDITOR env variable" if editorfile.nil?
51
- raw_command = paths[(paths.index editorfile) % pieces.size]
52
- editor = "\"#{editorfile}\"#{editor[raw_command.size()..-1]}"
53
- end
54
- editor
55
- end
56
-
57
- def self.secure_file_delete args
58
- file = File.open(args[:file], 'r+')
59
- num_bytes = args[:num_bytes]
60
- [0xff, 0x55, 0xaa, 0x00].each do |byte|
61
- file.seek(0, IO::SEEK_SET)
62
- num_bytes.times { file.print(byte.chr) }
63
- file.fsync
64
- end
65
- file.close
66
- File.delete args[:file]
67
- end
68
-
69
- def self.write_tempfile data_to_write
70
- file = Tempfile.open(['eyaml_edit', '.yaml'])
71
- path = file.path
72
- file.close!
73
-
74
- file = File.open(path, "w")
75
- file.chmod(0600)
76
- if ENV['OS'] == 'Windows_NT'
77
- # Windows doesn't support chmod
78
- icacls = 'C:\Windows\system32\icacls.exe'
79
- if File.executable? icacls
80
- current_user = `C:\\Windows\\system32\\whoami.exe`.chomp
81
- # Use ACLs to restrict access to the current user only
82
- command = %Q{#{icacls} "#{file.path}" /grant:r "#{current_user}":f /inheritance:r}
83
- system "#{command} >NUL 2>&1"
84
- end
85
- end
86
- file.puts data_to_write
87
- file.close
88
-
89
- Utils::debug "Wrote temporary file: #{path}"
90
-
91
- path
92
- end
93
-
94
- def self.write_important_file args
95
- filename = args[ :filename ]
96
- content = args[ :content ]
97
- mode = args[ :mode ]
98
- if File.file? "#{filename}"
99
- raise StandardError, "User aborted" unless Utils::confirm? "Are you sure you want to overwrite \"#{filename}\"?"
100
- end
101
- open( "#{filename}", "w" ) do |io|
102
- io.write(content)
103
- end
104
- File.chmod( mode, filename ) unless mode.nil?
105
- end
106
-
107
- def self.ensure_key_dir_exists key_file
108
- key_dir = File.dirname key_file
109
-
110
- unless File.directory? key_dir
111
- begin
112
- FileUtils.mkdir_p key_dir
113
- Utils::info "Created key directory: #{key_dir}"
114
- rescue
115
- raise StandardError, "Cannot create key directory: #{key_dir}"
116
- end
117
- end
118
-
119
- end
120
-
121
20
  def self.find_closest_class args
122
21
  parent_class = args[ :parent_class ]
123
22
  class_name = args[ :class_name ]
@@ -138,7 +37,7 @@ class Hiera
138
37
  root_folder = File.dirname(__FILE__) + "/" + Array.new(num_class_hierarchy_levels).fill("..").join("/")
139
38
  class_folder = root_folder + "/" + classdir
140
39
  Dir[File.expand_path("#{class_folder}/*.rb")].uniq.each do |file|
141
- self.trace "Requiring file: #{file}"
40
+ LoggingHelper.trace "Requiring file: #{file}"
142
41
  require file
143
42
  end
144
43
  end
@@ -157,70 +56,6 @@ class Hiera
157
56
  "hiera".eql? Eyaml::Options[:source]
158
57
  end
159
58
 
160
- def self.structure_message messageinfo
161
- message = {:from => "hiera-eyaml-core"}
162
- case messageinfo.class.to_s
163
- when 'Hash'
164
- message.merge!(messageinfo)
165
- else
166
- message.merge!({:msg => messageinfo.to_s})
167
- end
168
- message[:prefix] = "[#{message[:from]}]"
169
- message[:spacer] = " #{' ' * message[:from].length} "
170
- formatted_output = message[:msg].split("\n").each_with_index.map do |line, index|
171
- if index == 0
172
- "#{message[:prefix]} #{line}"
173
- else
174
- "#{message[:spacer]} #{line}"
175
- end
176
- end
177
- formatted_output.join "\n"
178
- end
179
-
180
- def self.warn messageinfo
181
- self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :warn, :cli_color => :red })
182
- end
183
-
184
- def self.info messageinfo
185
- self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :debug, :cli_color => :white, :threshold => 0 })
186
- end
187
-
188
- def self.debug messageinfo
189
- self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :debug, :cli_color => :green, :threshold => 1 })
190
- end
191
-
192
- def self.trace messageinfo
193
- self.print_message({ :message => self.structure_message( messageinfo ), :hiera_loglevel => :debug, :cli_color => :blue, :threshold => 2 })
194
- end
195
-
196
- def self.print_message( args )
197
- message = args[:message] ||= ""
198
- hiera_loglevel = args[:hiera_loglevel] ||= :debug
199
- cli_color = args[:cli_color] ||= :blue
200
- threshold = args[:threshold]
201
-
202
- if self.hiera?
203
- Hiera.send(hiera_loglevel, message) if threshold.nil? or Eyaml.verbosity_level > threshold
204
- else
205
- STDERR.puts self.colorize( message, cli_color ) if threshold.nil? or Eyaml.verbosity_level > threshold
206
- end
207
- end
208
-
209
- def self.colorize message, color
210
- suffix = "\e[0m"
211
- prefix = case color
212
- when :red
213
- "\e[31m"
214
- when :green
215
- "\e[32m"
216
- when :blue
217
- "\e[34m"
218
- else #:white
219
- "\e[0m"
220
- end
221
- "#{prefix}#{message}#{suffix}"
222
- end
223
-
224
59
  end
225
60
  end
226
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-eyaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.rc1
4
+ version: 2.1.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Poulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-27 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop
@@ -58,8 +58,12 @@ files:
58
58
  - lib/hiera/backend/eyaml.rb
59
59
  - lib/hiera/backend/eyaml/CLI.rb
60
60
  - lib/hiera/backend/eyaml/commands.rb
61
+ - lib/hiera/backend/eyaml/edithelper.rb
62
+ - lib/hiera/backend/eyaml/encrypthelper.rb
61
63
  - lib/hiera/backend/eyaml/encryptor.rb
62
64
  - lib/hiera/backend/eyaml/encryptors/pkcs7.rb
65
+ - lib/hiera/backend/eyaml/highlinehelper.rb
66
+ - lib/hiera/backend/eyaml/logginghelper.rb
63
67
  - lib/hiera/backend/eyaml/options.rb
64
68
  - lib/hiera/backend/eyaml/parser/encrypted_tokens.rb
65
69
  - lib/hiera/backend/eyaml/parser/parser.rb