dice_bag 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dice_bag/command.rb +4 -4
- data/lib/dice_bag/dice_bag_file.rb +3 -5
- data/lib/dice_bag/private_key.rb +39 -0
- data/lib/dice_bag/tasks/config.rake +10 -5
- data/lib/dice_bag/template_file.rb +2 -2
- data/lib/dice_bag/template_helpers.rb +13 -0
- data/lib/dice_bag/templates/database.yml.dice +1 -1
- data/lib/dice_bag/version.rb +1 -1
- metadata +9 -8
data/lib/dice_bag/command.rb
CHANGED
@@ -10,18 +10,18 @@ module DiceBag
|
|
10
10
|
#is called and dice_bag can find what software is used in this project
|
11
11
|
class Command
|
12
12
|
|
13
|
-
def write_all
|
13
|
+
def write_all(params = {})
|
14
14
|
Project.templates_to_generate.each do |template|
|
15
|
-
write(template)
|
15
|
+
write(template, params)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def write(template_name)
|
19
|
+
def write(template_name, params = {})
|
20
20
|
template_file = TemplateFile.new(template_name)
|
21
21
|
template_file.assert_existence
|
22
22
|
config_file = ConfigFile.new(template_name)
|
23
23
|
|
24
|
-
template_file.create_file(config_file)
|
24
|
+
template_file.create_file(config_file, params)
|
25
25
|
end
|
26
26
|
|
27
27
|
|
@@ -5,7 +5,7 @@ require 'dice_bag/version'
|
|
5
5
|
module DiceBag
|
6
6
|
module DiceBagFile
|
7
7
|
attr_reader :file, :filename
|
8
|
-
@@
|
8
|
+
@@overwrite_all = false
|
9
9
|
|
10
10
|
def assert_existence
|
11
11
|
unless File.exists?(@file)
|
@@ -20,9 +20,7 @@ module DiceBag
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def should_write?(new_contents)
|
23
|
-
|
24
|
-
return true if @@force || !$stdin.tty? || ENV['RAILS_ENV'] == 'test' || ENV['RAILS_ENV'] == 'production'
|
25
|
-
return true if !File.exists?(file)
|
23
|
+
return true if @@overwrite_all || !File.exists?(file)
|
26
24
|
return false if diff(file, new_contents).empty?
|
27
25
|
|
28
26
|
while true
|
@@ -35,7 +33,7 @@ module DiceBag
|
|
35
33
|
when 'n'
|
36
34
|
return false
|
37
35
|
when 'a'
|
38
|
-
return @@
|
36
|
+
return @@overwrite_all = true
|
39
37
|
when 'q'
|
40
38
|
exit
|
41
39
|
when 'd'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module DiceBag
|
2
|
+
class PrivateKey
|
3
|
+
|
4
|
+
attr_accessor :private_key
|
5
|
+
@@header = "-----BEGIN RSA PRIVATE KEY-----"
|
6
|
+
@@footer = "-----END RSA PRIVATE KEY-----"
|
7
|
+
|
8
|
+
def initialize(key)
|
9
|
+
@private_key = key
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_valid_private_key?
|
13
|
+
require 'openssl'
|
14
|
+
begin
|
15
|
+
OpenSSL::PKey::RSA.new @private_key
|
16
|
+
return true
|
17
|
+
rescue => e
|
18
|
+
p e.message
|
19
|
+
p e.backtrace
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_rsa_format!
|
25
|
+
strip_down_key
|
26
|
+
body = @private_key.split(/\s+/)
|
27
|
+
@private_key = [@@header, body, @@footer].flatten.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def strip_down_key
|
33
|
+
@private_key.gsub!(@@header,"")
|
34
|
+
@private_key.gsub!(@@footer,"")
|
35
|
+
@private_key.strip!
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -1,28 +1,33 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'dice_bag/command'
|
3
3
|
|
4
|
-
desc "
|
4
|
+
desc "Populate all templates using values from the environment to create configuration files"
|
5
5
|
task :config => ['config:all']
|
6
6
|
|
7
7
|
namespace :config do
|
8
|
-
|
8
|
+
# Deprecated, present only for backward compatibility.
|
9
9
|
task :all do
|
10
10
|
DiceBag::Command.new.write_all
|
11
11
|
end
|
12
12
|
|
13
|
-
desc "
|
13
|
+
desc "As per the config task but automatically overwrites pre-existing configuration files"
|
14
|
+
task :deploy do
|
15
|
+
DiceBag::Command.new.write_all(:deploy => true)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Populate just the specified template to create the associated configuration file"
|
14
19
|
task :file, :filename do |t, args|
|
15
20
|
filename = args[:filename]
|
16
21
|
raise "A filename needs to be provided" if filename.nil?
|
17
22
|
DiceBag::Command.new.write(filename)
|
18
23
|
end
|
19
24
|
|
20
|
-
desc "
|
25
|
+
desc "Generate all configuration file templates needed by this project"
|
21
26
|
task :generate_all do
|
22
27
|
DiceBag::Command.new.generate_all_templates
|
23
28
|
end
|
24
29
|
|
25
|
-
desc "
|
30
|
+
desc "Generate just the specified template, optionally in the specified location"
|
26
31
|
task :generate, :filename, :location do |t, args|
|
27
32
|
filename = args[:filename]
|
28
33
|
location = args[:location]
|
@@ -19,7 +19,7 @@ module DiceBag
|
|
19
19
|
@file = Project.config_files(name)
|
20
20
|
end
|
21
21
|
|
22
|
-
def create_file(config_file)
|
22
|
+
def create_file(config_file, params)
|
23
23
|
# By passing "<>" we're trimming trailing newlines on lines that are
|
24
24
|
# nothing but ERB blocks (see documentation). This is useful for files
|
25
25
|
# like mauth_key where we want to control newlines carefully.
|
@@ -30,7 +30,7 @@ module DiceBag
|
|
30
30
|
warning = Warning.new(@filename)
|
31
31
|
contents = template.result(binding)
|
32
32
|
|
33
|
-
return unless config_file.should_write?(contents)
|
33
|
+
return unless params[:deploy] || config_file.should_write?(contents)
|
34
34
|
config_file.write(contents)
|
35
35
|
puts "File '#{config_file.file}' created"
|
36
36
|
end
|
@@ -1,8 +1,21 @@
|
|
1
|
+
require 'dice_bag/private_key'
|
2
|
+
|
1
3
|
module DiceBag
|
2
4
|
module TemplateHelpers
|
3
5
|
def generate_private_key
|
4
6
|
require 'openssl'
|
5
7
|
OpenSSL::PKey::RSA.generate(2048)
|
6
8
|
end
|
9
|
+
|
10
|
+
def ensure_is_private_key(key)
|
11
|
+
pkey = PrivateKey.new key.dup
|
12
|
+
pkey.to_rsa_format!
|
13
|
+
if pkey.is_valid_private_key?
|
14
|
+
pkey.private_key
|
15
|
+
else
|
16
|
+
raise "The private key provided is invalid"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
end
|
8
21
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<% [:development, :test, :production].each do |env| %>
|
4
4
|
<%= env %>:
|
5
5
|
adapter: <%= configured[env].database_driver || 'mysql2' %>
|
6
|
-
database: <%= configured[env].database_name || "PROJECT_NAME_#{env}" %>
|
6
|
+
database: <%= configured[env].database_name || "PROJECT_NAME_#{env}" %><%= ('<'+'%=ENV["TEST_ENV_NUMBER"] %'+'>') if (env == :test) %>
|
7
7
|
username: <%= configured[env].database_username || 'root' %>
|
8
8
|
password: <%= configured[env].database_password %>
|
9
9
|
host: <%= configured[env].database_host || 'localhost' %>
|
data/lib/dice_bag/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dice_bag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-05-28 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
|
-
requirement: &
|
17
|
+
requirement: &86043750 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *86043750
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: aruba
|
28
|
-
requirement: &
|
28
|
+
requirement: &86043500 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.5.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *86043500
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &86043250 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '2.12'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *86043250
|
48
48
|
description:
|
49
49
|
email:
|
50
50
|
- asmith@mdsol.com
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/dice_bag/templates/google_analytics.yml.dice
|
71
71
|
- lib/dice_bag/templates/aws.yml.dice
|
72
72
|
- lib/dice_bag/railtie.rb
|
73
|
+
- lib/dice_bag/private_key.rb
|
73
74
|
- lib/dice_bag/configuration.rb
|
74
75
|
- lib/dice_bag/tasks/config.rake
|
75
76
|
- lib/dice_bag/available_templates.rb
|