aws-rds 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +28 -68
- data/README.md +8 -8
- data/lib/aws-rds.rb +3 -0
- data/lib/aws_rds/command.rb +13 -0
- data/lib/aws_rds/create.rb +3 -73
- data/lib/aws_rds/create/params.rb +40 -0
- data/lib/aws_rds/help/create.md +3 -14
- data/lib/aws_rds/profile.rb +48 -0
- data/lib/aws_rds/template_helper.rb +61 -0
- data/lib/aws_rds/version.rb +1 -1
- data/spec/fixtures/demo_project/profiles/default.yml +10 -0
- data/spec/lib/cli_spec.rb +4 -4
- data/spec/spec_helper.rb +4 -3
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16ecd0d223d71b7e91fa20b144a22313bda81df011baecc40bac52e8bc926920
|
|
4
|
+
data.tar.gz: 37586608aebb1ea689da67b972df6820b1ce7d86d4821ac99b555509273bd0a1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 795d2625a798788841763c2389dae931e7bfd940138c62f94f065d05094df43157af003025577d2645aacd521fd8ec05db324ad33f948dd225a9b2dd762be25c
|
|
7
|
+
data.tar.gz: df2ae5fcef01b1fdb012c06303a99b8b95085be3d30948f6ca9ebad4e0586daa260d312f7b8409098a5ea9265f95124350c810c51b417ecd87c34d88b696c3e8
|
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
|
5
5
|
|
|
6
|
+
## [0.2.0]
|
|
7
|
+
- allow erb usage in profiles, can reference config values
|
|
8
|
+
- rework profile and params to classes. profile no longer merged
|
|
9
|
+
|
|
6
10
|
## [0.1.2]
|
|
7
11
|
- remove require byebug
|
|
8
12
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
aws-rds (0.
|
|
4
|
+
aws-rds (0.1.2)
|
|
5
5
|
activesupport
|
|
6
6
|
aws-sdk-ec2
|
|
7
7
|
aws-sdk-rds
|
|
@@ -17,7 +17,7 @@ GEM
|
|
|
17
17
|
i18n (~> 0.7)
|
|
18
18
|
minitest (~> 5.1)
|
|
19
19
|
tzinfo (~> 1.1)
|
|
20
|
-
aws-partitions (1.
|
|
20
|
+
aws-partitions (1.57.0)
|
|
21
21
|
aws-sdk-core (3.14.0)
|
|
22
22
|
aws-partitions (~> 1.0)
|
|
23
23
|
aws-sigv4 (~> 1.0)
|
|
@@ -29,78 +29,40 @@ GEM
|
|
|
29
29
|
aws-sdk-core (~> 3)
|
|
30
30
|
aws-sigv4 (~> 1.0)
|
|
31
31
|
aws-sigv4 (1.0.2)
|
|
32
|
-
byebug (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
codeclimate-test-reporter (0.4.4)
|
|
36
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
|
37
|
-
coderay (1.1.0)
|
|
32
|
+
byebug (10.0.0)
|
|
33
|
+
codeclimate-test-reporter (1.0.8)
|
|
34
|
+
simplecov (<= 0.13)
|
|
38
35
|
colorize (0.8.1)
|
|
39
36
|
concurrent-ruby (1.0.5)
|
|
40
|
-
diff-lcs (1.
|
|
37
|
+
diff-lcs (1.3)
|
|
41
38
|
docile (1.1.5)
|
|
42
|
-
ffi (1.9.6)
|
|
43
|
-
formatador (0.2.5)
|
|
44
|
-
guard (2.10.5)
|
|
45
|
-
formatador (>= 0.2.4)
|
|
46
|
-
listen (~> 2.7)
|
|
47
|
-
lumberjack (~> 1.0)
|
|
48
|
-
nenv (~> 0.1)
|
|
49
|
-
pry (>= 0.9.12)
|
|
50
|
-
thor (>= 0.18.1)
|
|
51
|
-
guard-bundler (2.1.0)
|
|
52
|
-
bundler (~> 1.0)
|
|
53
|
-
guard (~> 2.2)
|
|
54
|
-
guard-compat (~> 1.1)
|
|
55
|
-
guard-compat (1.2.0)
|
|
56
|
-
guard-rspec (4.5.0)
|
|
57
|
-
guard (~> 2.1)
|
|
58
|
-
guard-compat (~> 1.1)
|
|
59
|
-
rspec (>= 2.99.0, < 4.0)
|
|
60
39
|
hashie (3.5.7)
|
|
61
|
-
|
|
62
|
-
i18n (0.9.1)
|
|
40
|
+
i18n (0.9.3)
|
|
63
41
|
concurrent-ruby (~> 1.0)
|
|
64
42
|
jmespath (1.3.1)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
coderay (~> 1.1.0)
|
|
76
|
-
method_source (~> 0.8.1)
|
|
77
|
-
slop (~> 3.4)
|
|
78
|
-
rake (10.4.2)
|
|
79
|
-
rb-fsevent (0.9.4)
|
|
80
|
-
rb-inotify (0.9.5)
|
|
81
|
-
ffi (>= 0.5.0)
|
|
82
|
-
rspec (3.1.0)
|
|
83
|
-
rspec-core (~> 3.1.0)
|
|
84
|
-
rspec-expectations (~> 3.1.0)
|
|
85
|
-
rspec-mocks (~> 3.1.0)
|
|
86
|
-
rspec-core (3.1.7)
|
|
87
|
-
rspec-support (~> 3.1.0)
|
|
88
|
-
rspec-expectations (3.1.2)
|
|
43
|
+
json (2.1.0)
|
|
44
|
+
minitest (5.11.3)
|
|
45
|
+
rake (12.3.0)
|
|
46
|
+
rspec (3.7.0)
|
|
47
|
+
rspec-core (~> 3.7.0)
|
|
48
|
+
rspec-expectations (~> 3.7.0)
|
|
49
|
+
rspec-mocks (~> 3.7.0)
|
|
50
|
+
rspec-core (3.7.1)
|
|
51
|
+
rspec-support (~> 3.7.0)
|
|
52
|
+
rspec-expectations (3.7.0)
|
|
89
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
90
|
-
rspec-support (~> 3.
|
|
91
|
-
rspec-mocks (3.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
54
|
+
rspec-support (~> 3.7.0)
|
|
55
|
+
rspec-mocks (3.7.0)
|
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
57
|
+
rspec-support (~> 3.7.0)
|
|
58
|
+
rspec-support (3.7.1)
|
|
59
|
+
simplecov (0.13.0)
|
|
95
60
|
docile (~> 1.1.0)
|
|
96
|
-
|
|
97
|
-
simplecov-html (~> 0.
|
|
98
|
-
simplecov-html (0.
|
|
99
|
-
|
|
100
|
-
thor (0.19.1)
|
|
61
|
+
json (>= 1.8, < 3)
|
|
62
|
+
simplecov-html (~> 0.10.0)
|
|
63
|
+
simplecov-html (0.10.2)
|
|
64
|
+
thor (0.20.0)
|
|
101
65
|
thread_safe (0.3.6)
|
|
102
|
-
timers (4.0.1)
|
|
103
|
-
hitimes
|
|
104
66
|
tzinfo (1.2.4)
|
|
105
67
|
thread_safe (~> 0.1)
|
|
106
68
|
|
|
@@ -112,10 +74,8 @@ DEPENDENCIES
|
|
|
112
74
|
bundler
|
|
113
75
|
byebug
|
|
114
76
|
codeclimate-test-reporter
|
|
115
|
-
guard
|
|
116
|
-
guard-bundler
|
|
117
|
-
guard-rspec
|
|
118
77
|
rake
|
|
78
|
+
rspec
|
|
119
79
|
|
|
120
80
|
BUNDLED WITH
|
|
121
81
|
1.16.1
|
data/README.md
CHANGED
|
@@ -4,8 +4,8 @@ Simple tool to create AWS RDS db instances consistently with pre-configured sett
|
|
|
4
4
|
|
|
5
5
|
For example, say you have:
|
|
6
6
|
|
|
7
|
-
* profiles/default.yml: default settings
|
|
8
|
-
* profiles/mydb.yml: mydb settings
|
|
7
|
+
* profiles/default.yml: default settings, when no profile is specified.
|
|
8
|
+
* profiles/mydb.yml: mydb settings.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
@@ -16,11 +16,11 @@ aws-rds create mydb --profile mydb --db-name mydbname
|
|
|
16
16
|
* mydb will be the RDS database identifier show on the AWS console
|
|
17
17
|
* mydbname is the database name that contains the tables
|
|
18
18
|
|
|
19
|
-
In a nutshell, the profile parameters are passed to the ruby aws-sdk [AWS::RDS::Client#create_db_instance](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/RDS/Client.html#create_db_instance-instance_method) method. So you can specify any parameter you wish that is available
|
|
19
|
+
In a nutshell, the profile parameters are passed to the ruby aws-sdk [AWS::RDS::Client#create_db_instance](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/RDS/Client.html#create_db_instance-instance_method) method. So you can specify any parameter you wish that is available in the aws-sdk. To check out what a profile looks like view the [example default](example/profiles/default.yml)
|
|
20
20
|
|
|
21
21
|
## config
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
You can configure common global settings. The required settings are listed below. Example:
|
|
24
24
|
|
|
25
25
|
`config/development.yml`
|
|
26
26
|
|
|
@@ -31,15 +31,15 @@ db_subnet_group_name: private-subnet-group-name # fallback db_subnet_group_name
|
|
|
31
31
|
|
|
32
32
|
## Security Group Creation
|
|
33
33
|
|
|
34
|
-
The tool automatically creates a security group and associates it with the newly created db.
|
|
34
|
+
The tool automatically creates a security group and associates it with the newly created db. Normally the default security group is associated with the db. A new security group allows you to control access to the database in finely tune manner without affecting the default security group.
|
|
35
35
|
|
|
36
36
|
## Convention
|
|
37
37
|
|
|
38
|
-
By convention, the security-group
|
|
38
|
+
By convention, the security-group name is the same as the db identifier. So if the db identifier matches the commands the be simplified. Examples:
|
|
39
39
|
|
|
40
40
|
```
|
|
41
|
-
aws-rds create mydb --security-group-name mydb
|
|
42
|
-
aws-rds create mydb # same as above
|
|
41
|
+
aws-rds create mydb --profile myprofile --security-group-name mydb
|
|
42
|
+
aws-rds create mydb --profile myprofile # same as above
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
## More Help
|
data/lib/aws-rds.rb
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
$:.unshift(File.expand_path("../", __FILE__))
|
|
2
2
|
require "aws_rds/version"
|
|
3
|
+
require "colorize"
|
|
3
4
|
|
|
4
5
|
module AwsRds
|
|
5
6
|
autoload :Help, "aws_rds/help"
|
|
6
7
|
autoload :Command, "aws_rds/command"
|
|
7
8
|
autoload :CLI, "aws_rds/cli"
|
|
8
9
|
autoload :AwsServices, "aws_rds/aws_services"
|
|
10
|
+
autoload :Profile, "aws_rds/profile"
|
|
11
|
+
autoload :TemplateHelper, "aws_rds/template_helper"
|
|
9
12
|
autoload :Create, "aws_rds/create"
|
|
10
13
|
autoload :SecurityGroup, "aws_rds/security_group"
|
|
11
14
|
autoload :Config, "aws_rds/config"
|
data/lib/aws_rds/command.rb
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
require "thor"
|
|
2
2
|
|
|
3
|
+
# Override thor's long_desc identation behavior
|
|
4
|
+
# https://github.com/erikhuda/thor/issues/398
|
|
5
|
+
class Thor
|
|
6
|
+
module Shell
|
|
7
|
+
class Basic
|
|
8
|
+
def print_wrapped(message, options = {})
|
|
9
|
+
message = "\n#{message}" unless message[0] == "\n"
|
|
10
|
+
stdout.puts message
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
3
16
|
module AwsRds
|
|
4
17
|
class Command < Thor
|
|
5
18
|
class << self
|
data/lib/aws_rds/create.rb
CHANGED
|
@@ -3,6 +3,8 @@ require 'active_support/core_ext/hash'
|
|
|
3
3
|
|
|
4
4
|
module AwsRds
|
|
5
5
|
class Create
|
|
6
|
+
autoload :Params, "aws_rds/create/params"
|
|
7
|
+
|
|
6
8
|
include AwsServices
|
|
7
9
|
|
|
8
10
|
def initialize(options)
|
|
@@ -22,80 +24,8 @@ module AwsRds
|
|
|
22
24
|
puts "Visit https://console.aws.amazon.com/rds/home?#dbinstances to check on the status"
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
# params are taken from the profile file
|
|
26
27
|
def params
|
|
27
|
-
params
|
|
28
|
-
params = use_database_cli_options(params)
|
|
29
|
-
params = set_security_groups(params)
|
|
30
|
-
params = set_db_subnet_group(params)
|
|
31
|
-
params.symbolize_keys
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def set_db_subnet_group(params)
|
|
35
|
-
params["db_subnet_group_name"] ||= AwsRds.config["db_subnet_group_name"]
|
|
36
|
-
params
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def set_security_groups(params)
|
|
40
|
-
return params unless @options[:security_group]
|
|
41
|
-
return params if @options[:noop]
|
|
42
|
-
|
|
43
|
-
security_group_name = @options[:security_group_name] || @options[:name]
|
|
44
|
-
sg = SecurityGroup.find_or_create(security_group_name)
|
|
45
|
-
params['vpc_security_group_ids'] ||= [sg.group_id]
|
|
46
|
-
params
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# Be able to set the common database options with the CLI options.
|
|
50
|
-
# Other options can be set with the profile files.
|
|
51
|
-
def use_database_cli_options(params)
|
|
52
|
-
params['db_instance_identifier'] = @options[:name] # required
|
|
53
|
-
params['db_name'] = @options[:db_name] if @options[:db_name]
|
|
54
|
-
params['master_username'] = @options[:db_user] if @options[:db_user]
|
|
55
|
-
params['master_user_password'] = @options[:db_password] if @options[:db_password]
|
|
56
|
-
params
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def load_profiles(profile_name)
|
|
60
|
-
profile_file = "#{root}/profiles/#{profile_name}.yml"
|
|
61
|
-
base_path = File.dirname(profile_file)
|
|
62
|
-
default_file = "#{base_path}/default.yml"
|
|
63
|
-
|
|
64
|
-
params_exit_check!(profile_file, default_file)
|
|
65
|
-
|
|
66
|
-
defaults = load_profile(default_file)
|
|
67
|
-
params = load_profile(profile_file)
|
|
68
|
-
params = defaults.merge(params)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def params_exit_check!(profile_file, default_file)
|
|
72
|
-
return if File.exist?(profile_file) or File.exist?(default_file)
|
|
73
|
-
|
|
74
|
-
puts "Unable to find a #{profile_file} or #{default_file} profile file."
|
|
75
|
-
puts "Please double check."
|
|
76
|
-
exit # EXIT HERE
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def load_profile(file)
|
|
80
|
-
return {} unless File.exist?(file)
|
|
81
|
-
|
|
82
|
-
puts "Using profile: #{file}"
|
|
83
|
-
data = YAML.load_file(file)
|
|
84
|
-
data ? data : {} # in case the file is empty
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def profile_name
|
|
88
|
-
# allow user to specify the path also
|
|
89
|
-
if @options[:profile] && File.exist?(@options[:profile])
|
|
90
|
-
profile = File.basename(@options[:profile], '.yml')
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# conventional profile is the name of the ec2 instance
|
|
94
|
-
profile || @options[:profile] || @options[:name]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def root
|
|
98
|
-
ENV['AWS_RDS_ROOT'] || '.'
|
|
28
|
+
@params ||= Params.new(@options).generate
|
|
99
29
|
end
|
|
100
30
|
|
|
101
31
|
def pretty_display(data)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class AwsRds::Create
|
|
2
|
+
class Params
|
|
3
|
+
def initialize(options)
|
|
4
|
+
@options = options
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def generate
|
|
8
|
+
params = AwsRds::Profile.new(@options).load
|
|
9
|
+
params = use_database_cli_options(params)
|
|
10
|
+
params = set_security_groups(params)
|
|
11
|
+
params = set_db_subnet_group(params)
|
|
12
|
+
params.symbolize_keys
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Be able to set the common database options with the CLI options.
|
|
16
|
+
# Other options can be set with the profile files.
|
|
17
|
+
def use_database_cli_options(params)
|
|
18
|
+
params['db_instance_identifier'] = @options[:name] # required
|
|
19
|
+
params['db_name'] = @options[:db_name] if @options[:db_name]
|
|
20
|
+
params['master_username'] = @options[:db_user] if @options[:db_user]
|
|
21
|
+
params['master_user_password'] = @options[:db_password] if @options[:db_password]
|
|
22
|
+
params
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def set_security_groups(params)
|
|
26
|
+
return params unless @options[:security_group]
|
|
27
|
+
return params if @options[:noop]
|
|
28
|
+
|
|
29
|
+
security_group_name = @options[:security_group_name] || @options[:name]
|
|
30
|
+
sg = AwsRds::SecurityGroup.find_or_create(security_group_name)
|
|
31
|
+
params['vpc_security_group_ids'] ||= [sg.group_id]
|
|
32
|
+
params
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def set_db_subnet_group(params)
|
|
36
|
+
params["db_subnet_group_name"] ||= AwsRds.config["db_subnet_group_name"]
|
|
37
|
+
params
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/aws_rds/help/create.md
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
The create command creates an RDS database with a profile file with some pre-configured
|
|
2
|
-
|
|
3
|
-
For example, say you have:
|
|
4
|
-
|
|
5
|
-
* profiles/default.yml
|
|
6
|
-
* profiles/my-db.yml
|
|
7
|
-
|
|
8
|
-
Then `my-db.yml` gets combined with `default.yml` profile. The `default.yml` takes the lowest precedence.
|
|
1
|
+
The create command creates an RDS database with a profile file with some pre-configured settings. The profile file is in the profiles folder. If a profile is not specified, it will only use the `profiles/default.yml` profile.
|
|
9
2
|
|
|
10
3
|
Examples:
|
|
11
4
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
By convention, the profile is name of the db. So the command above can be shortened to:
|
|
15
|
-
|
|
16
|
-
$ aws-rds create my-db
|
|
5
|
+
aws-rds create my-db --profile my-db
|
|
17
6
|
|
|
18
7
|
Security Groups:
|
|
19
8
|
|
|
20
9
|
By default, instead of using the default security group, a new security group is created and associated with the database.
|
|
21
10
|
|
|
22
|
-
This security group is
|
|
11
|
+
This security group's name is the same as database name by convention. This can be overridden at with `--security-group-name`. If the security group already exists, it will use the existing security group that matches the name.
|
|
23
12
|
|
|
24
13
|
If you do not want to specify the security group name every time, you can configure the security group id in the profile file by setting vpc_security_group_ids.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module AwsRds
|
|
2
|
+
class Profile
|
|
3
|
+
include TemplateHelper
|
|
4
|
+
|
|
5
|
+
def initialize(options)
|
|
6
|
+
@options = options
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def load
|
|
10
|
+
return @profile_params if @profile_params
|
|
11
|
+
|
|
12
|
+
check!
|
|
13
|
+
|
|
14
|
+
@profile_params = load_profile(profile_file)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def check!
|
|
18
|
+
return if File.exist?(profile_file)
|
|
19
|
+
|
|
20
|
+
puts "Unable to find a #{profile_file.colorize(:green)} profile file."
|
|
21
|
+
puts "Please double check that it exists or that you specified the right profile."
|
|
22
|
+
exit # EXIT HERE
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def load_profile(file)
|
|
26
|
+
return {} unless File.exist?(file)
|
|
27
|
+
|
|
28
|
+
puts "Using profile: #{file}"
|
|
29
|
+
data = YAML.load(erb_result(file))
|
|
30
|
+
data ? data : {} # in case the file is empty
|
|
31
|
+
data.has_key?("create_db_instance") ? data["create_db_instance"] : data
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def profile_file
|
|
35
|
+
"#{AwsRds.root}/profiles/#{profile_name}.yml"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def profile_name
|
|
39
|
+
# allow user to specify the path also
|
|
40
|
+
if @options[:profile] && File.exist?(@options[:profile])
|
|
41
|
+
profile = File.basename(@options[:profile], '.yml')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# conventional profile is the name of the ec2 instance
|
|
45
|
+
profile || @options[:profile] || "default"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
|
|
3
|
+
module AwsRds::TemplateHelper
|
|
4
|
+
def config
|
|
5
|
+
AwsRds.config
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
def load_custom_helpers
|
|
10
|
+
Dir.glob("#{AwsRds.root}/app/helpers/**/*_helper.rb").each do |path|
|
|
11
|
+
filename = path.sub(%r{.*/},'').sub('.rb','')
|
|
12
|
+
module_name = filename.classify
|
|
13
|
+
|
|
14
|
+
require path
|
|
15
|
+
self.class.send :include, module_name.constantize
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def erb_result(path)
|
|
21
|
+
load_custom_helpers
|
|
22
|
+
template = IO.read(path)
|
|
23
|
+
|
|
24
|
+
# Allow a way to bypass the custom ERB error handling in case
|
|
25
|
+
# the error is in the lambdagem code.
|
|
26
|
+
if ENV['DEBUG']
|
|
27
|
+
return ERB.new(template, nil, "-").result(binding)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
ERB.new(template, nil, "-").result(binding)
|
|
32
|
+
rescue Exception => e
|
|
33
|
+
puts e
|
|
34
|
+
|
|
35
|
+
# how to know where ERB stopped? - https://www.ruby-forum.com/topic/182051
|
|
36
|
+
# syntax errors have the (erb):xxx info in e.message
|
|
37
|
+
# undefined variables have (erb):xxx info in e.backtrac
|
|
38
|
+
error_info = e.message.split("\n").grep(/\(erb\)/)[0]
|
|
39
|
+
error_info ||= e.backtrace.grep(/\(erb\)/)[0]
|
|
40
|
+
raise unless error_info # unable to find the (erb):xxx: error line
|
|
41
|
+
line = error_info.split(':')[1].to_i
|
|
42
|
+
puts "Error evaluating ERB template on line #{line.to_s.colorize(:red)} of: #{path.sub(/^\.\//, '')}"
|
|
43
|
+
|
|
44
|
+
template_lines = template.split("\n")
|
|
45
|
+
context = 5 # lines of context
|
|
46
|
+
top, bottom = [line-context-1, 0].max, line+context-1
|
|
47
|
+
spacing = template_lines.size.to_s.size
|
|
48
|
+
template_lines[top..bottom].each_with_index do |line_content, index|
|
|
49
|
+
line_number = top+index+1
|
|
50
|
+
if line_number == line
|
|
51
|
+
printf("%#{spacing}d %s\n".colorize(:red), line_number, line_content)
|
|
52
|
+
else
|
|
53
|
+
printf("%#{spacing}d %s\n", line_number, line_content)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
puts "\nIf the this error does not make sense and the error is not in the ERB template. Run the command again with DEBUG=1 to show the full lambdagem backtrace"
|
|
58
|
+
exit 1 unless ENV['TEST']
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
data/lib/aws_rds/version.rb
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
allocated_storage: 20
|
|
3
|
+
db_instance_class: db.t2.micro
|
|
4
|
+
master_user_password: aws-rds
|
|
5
|
+
master_username: aws-rds
|
|
6
|
+
engine: postgres
|
|
7
|
+
|
|
8
|
+
# db_name: mydb # can be overridden at the cli
|
|
9
|
+
# vpc_security_group_ids: # automatically created for you if not set
|
|
10
|
+
# db_instance_identifier: not respected here. always set from the cli
|
data/spec/lib/cli_spec.rb
CHANGED
|
@@ -7,13 +7,13 @@ require "spec_helper"
|
|
|
7
7
|
# $ rake clean:vcr ; time rake
|
|
8
8
|
describe AwsRds::CLI do
|
|
9
9
|
before(:all) do
|
|
10
|
-
@args = "--
|
|
10
|
+
@args = "--noop"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
describe "aws-rds" do
|
|
14
|
-
it "
|
|
15
|
-
out = execute("exe/aws-rds
|
|
16
|
-
expect(out).to include("
|
|
14
|
+
it "create" do
|
|
15
|
+
out = execute("exe/aws-rds create mydb #{@args}")
|
|
16
|
+
expect(out).to include("Creating")
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
ENV["TEST"] = "1"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
#
|
|
2
|
+
ENV["AWS_RDS_ENV"] = "test"
|
|
3
|
+
ENV["AWS_RDS_ROOT"] = "spec/fixtures/demo_project"
|
|
4
|
+
# Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
|
|
5
|
+
ENV['HOME'] = "spec/fixtures/home"
|
|
5
6
|
|
|
6
7
|
require "pp"
|
|
7
8
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aws-rds
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tung Nguyen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-01
|
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -181,11 +181,15 @@ files:
|
|
|
181
181
|
- lib/aws_rds/config.rb
|
|
182
182
|
- lib/aws_rds/core.rb
|
|
183
183
|
- lib/aws_rds/create.rb
|
|
184
|
+
- lib/aws_rds/create/params.rb
|
|
184
185
|
- lib/aws_rds/default.yml
|
|
185
186
|
- lib/aws_rds/help.rb
|
|
186
187
|
- lib/aws_rds/help/create.md
|
|
188
|
+
- lib/aws_rds/profile.rb
|
|
187
189
|
- lib/aws_rds/security_group.rb
|
|
190
|
+
- lib/aws_rds/template_helper.rb
|
|
188
191
|
- lib/aws_rds/version.rb
|
|
192
|
+
- spec/fixtures/demo_project/profiles/default.yml
|
|
189
193
|
- spec/lib/cli_spec.rb
|
|
190
194
|
- spec/spec_helper.rb
|
|
191
195
|
homepage: https://github.com/tongueroo/aws-rds
|
|
@@ -213,5 +217,6 @@ signing_key:
|
|
|
213
217
|
specification_version: 4
|
|
214
218
|
summary: RDS DB creation tool
|
|
215
219
|
test_files:
|
|
220
|
+
- spec/fixtures/demo_project/profiles/default.yml
|
|
216
221
|
- spec/lib/cli_spec.rb
|
|
217
222
|
- spec/spec_helper.rb
|