-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Utils methods into specific helper classes
- Loading branch information
Showing
12 changed files
with
134 additions
and
101 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
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,40 @@ | ||
require 'tempfile' | ||
require 'fileutils' | ||
|
||
class Hiera | ||
module Backend | ||
module Eyaml | ||
class EncryptHelper | ||
|
||
def self.write_important_file args | ||
require 'hiera/backend/eyaml/highlinehelper' | ||
filename = args[ :filename ] | ||
content = args[ :content ] | ||
mode = args[ :mode ] | ||
if File.file? "#{filename}" | ||
raise StandardError, "User aborted" unless HighlineHelper::confirm? "Are you sure you want to overwrite \"#{filename}\"?" | ||
end | ||
open( "#{filename}", "w" ) do |io| | ||
io.write(content) | ||
end | ||
File.chmod( mode, filename ) unless mode.nil? | ||
end | ||
|
||
def self.ensure_key_dir_exists key_file | ||
key_dir = File.dirname key_file | ||
|
||
unless File.directory? key_dir | ||
begin | ||
FileUtils.mkdir_p key_dir | ||
LoggingHelper::info "Created key directory: #{key_dir}" | ||
rescue | ||
raise StandardError, "Cannot create key directory: #{key_dir}" | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'highline/import' | ||
|
||
class Hiera | ||
module Backend | ||
module Eyaml | ||
class HighlineHelper | ||
|
||
def self.read_password | ||
ask("Enter password: ") {|q| q.echo = "*" } | ||
end | ||
|
||
def self.confirm? message | ||
result = ask("#{message} (y/N): ") | ||
if result.downcase == "y" or result.downcase == "yes" | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
end | ||
end | ||
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
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