Module: Prepd
- Defined in:
- lib/prepd.rb,
lib/prepd/cli.rb,
lib/prepd/version.rb,
lib/prepd/models/base.rb,
lib/prepd/models/data.rb,
lib/prepd/cli/commands.rb,
lib/prepd/models/setup.rb,
lib/prepd/models/cluster.rb,
lib/prepd/models/machine.rb,
lib/prepd/models/project.rb,
lib/prepd/models/developer.rb,
lib/prepd/models/workspace.rb
Defined Under Namespace
Modules: Cli, Component
Classes: Base, Cluster, Command, Creator, Data, Developer, Machine, Project, Setup, StringInquirer, Workspace
Constant Summary
collapse
- VERSION =
'0.3.0'
Class Method Summary
collapse
Class Method Details
.base_config ⇒ Object
45
46
47
48
|
# 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 ⇒ Object
69
|
# File 'lib/prepd.rb', line 69
def self.cli_options; @cli_options; end
|
.cli_options=(config) ⇒ Object
65
66
67
|
# File 'lib/prepd.rb', line 65
def self.cli_options=(config)
@cli_options = config
end
|
.config ⇒ Object
63
|
# File 'lib/prepd.rb', line 63
def self.config; @config; end
|
.config=(config) ⇒ Object
59
60
61
|
# File 'lib/prepd.rb', line 59
def self.config=(config)
@config = config
end
|
.config_dir ⇒ Object
19
|
# File 'lib/prepd.rb', line 19
def self.config_dir; @config_dir end
|
.config_dir=(dir) ⇒ Object
21
22
23
|
# File 'lib/prepd.rb', line 21
def self.config_dir=(dir)
@config_dir = dir
end
|
.config_file ⇒ Object
25
|
# File 'lib/prepd.rb', line 25
def self.config_file; "#{config_dir}/config.yml"; end
|
.create_password_file(config_dir) ⇒ Object
88
89
90
91
92
93
94
|
# 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 ⇒ Object
27
28
29
|
# File 'lib/prepd.rb', line 27
def self.default_config
{ version: 1 }
end
|
.env ⇒ Object
16
|
# File 'lib/prepd.rb', line 16
def self.env; @env; end
|
.env=(env) ⇒ Object
17
|
# File 'lib/prepd.rb', line 17
def self.env=(env); @env = env; end
|
.files_dir ⇒ Object
75
76
77
|
# File 'lib/prepd.rb', line 75
def self.files_dir
"#{Pathname.new(File.dirname(__FILE__)).parent}/files"
end
|
.git_log ⇒ Object
105
106
107
|
# File 'lib/prepd.rb', line 105
def self.git_log
config.verbose ? '' : '--quiet'
end
|
.log(message) ⇒ Object
71
72
73
|
# File 'lib/prepd.rb', line 71
def self.log(message)
STDOUT.puts(message)
end
|
.machine_is_host? ⇒ Boolean
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
82
83
84
85
|
# 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) ⇒ Object
31
32
33
34
|
# File 'lib/prepd.rb', line 31
def self.register_workspace(dir)
config.workspaces << dir
write_config_file
end
|
.verify_workspaces ⇒ Object
36
37
38
39
40
41
42
43
|
# 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 ⇒ Object
55
56
57
|
# File 'lib/prepd.rb', line 55
def self.writable_config
config.to_h.select { |k| %i(version workspaces).include?(k) }
end
|
.write_config_file ⇒ Object
50
51
52
53
|
# 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') ⇒ Object
Generate the key to encrypt ansible-vault files
99
100
101
102
103
|
# 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
|