module Prepd
Constants
- VERSION
Public Class Methods
base_config()
click to toggle source
# File lib/prepd.rb, line 45 def self.base_config write_config_file unless File.exists?(config_file) default_config.merge(YAML.load(File.read(config_file))) end
cli_options()
click to toggle source
# File lib/prepd.rb, line 69 def self.cli_options; @cli_options; end
cli_options=(config)
click to toggle source
# File lib/prepd.rb, line 65 def self.cli_options=(config) @cli_options = config end
config()
click to toggle source
# File lib/prepd.rb, line 63 def self.config; @config; end
config=(config)
click to toggle source
# File lib/prepd.rb, line 59 def self.config=(config) @config = config end
config_dir()
click to toggle source
# File lib/prepd.rb, line 19 def self.config_dir; @config_dir end
config_dir=(dir)
click to toggle source
# File lib/prepd.rb, line 21 def self.config_dir=(dir) @config_dir = dir end
config_file()
click to toggle source
# File lib/prepd.rb, line 25 def self.config_file; "#{config_dir}/config.yml"; end
create_password_file(config_dir)
click to toggle source
# File lib/prepd.rb, line 88 def self.create_password_file(config_dir) password_dir = "#{config_dir}/vault-keys" password_file = "#{password_dir}/password.txt" return if File.exists?(password_file) FileUtils.mkdir_p(password_dir) unless Dir.exists? password_dir write_password_file(password_file) end
default_config()
click to toggle source
# File lib/prepd.rb, line 27 def self.default_config { version: 1 } end
env()
click to toggle source
# File lib/prepd.rb, line 16 def self.env; @env; end
env=(env)
click to toggle source
# File lib/prepd.rb, line 17 def self.env=(env); @env = env; end
files_dir()
click to toggle source
# File lib/prepd.rb, line 75 def self.files_dir "#{Pathname.new(File.dirname(__FILE__)).parent}/files" end
git_log()
click to toggle source
# File lib/prepd.rb, line 105 def self.git_log config.verbose ? '' : '--quiet' end
log(message)
click to toggle source
# File lib/prepd.rb, line 71 def self.log(message) STDOUT.puts(message) end
machine_is_host?()
click to toggle source
Probe system for whether it is virutal or not and default accordingly hostnamectl | grep Virtualization will return a string when the string is found (vm) and '' when not (host) it will fail on apple machines b/c hostnamectl is not a valid command which means it is the host
# File lib/prepd.rb, line 82 def self.machine_is_host? return true unless system('hostnamectl > /dev/null 2>&1') %x('hostnamectl').index('Virtualization').nil? end
register_workspace(dir)
click to toggle source
# File lib/prepd.rb, line 31 def self.register_workspace(dir) config.workspaces << dir write_config_file end
verify_workspaces()
click to toggle source
# File lib/prepd.rb, line 36 def self.verify_workspaces config.workspaces ||= [] config.workspaces.each do |dir| next if File.exists?(File.expand_path("#{dir}/prepd-workspace.yml")) config.workspaces -= [dir] end write_config_file end
writable_config()
click to toggle source
# File lib/prepd.rb, line 55 def self.writable_config config.to_h.select { |k| %i(version workspaces).include?(k) } end
write_config_file()
click to toggle source
# File lib/prepd.rb, line 50 def self.write_config_file FileUtils.mkdir_p(config_dir) unless Dir.exists?(config_dir) File.open(config_file, 'w') { |f| f.write(YAML.dump(writable_config)) } end
write_password_file(file_name = 'password.txt')
click to toggle source
Generate the key to encrypt ansible-vault files
# File lib/prepd.rb, line 99 def self.write_password_file(file_name = 'password.txt') require 'securerandom' File.open(file_name, 'w') { |f| f.puts(SecureRandom.uuid) } nil end