rds_concerto 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.concert.yml +0 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/concerto +6 -0
- data/lib/rds_concerto.rb +11 -0
- data/lib/rds_concerto/aurora.rb +28 -0
- data/lib/rds_concerto/aurora/client.rb +94 -0
- data/lib/rds_concerto/aurora/resource.rb +48 -0
- data/lib/rds_concerto/cli.rb +86 -0
- data/lib/rds_concerto/config.rb +73 -0
- data/lib/rds_concerto/version.rb +3 -0
- data/rds_concerto.gemspec +32 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a2517c6d84fb8cf3bba71e26892dc0ef6ca9ab0aaf67c566d9ca8886b4c229b
|
4
|
+
data.tar.gz: 3fe1a66adb8672f2cbec6912e902e87ec0e224a3fa523b9d2c4bddc9bd3b0c9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c802ce68b8f2f0992718fb4d668bf70619e57f16a2f129811e112b2560a84ffac7c302ee67b52aafc5a417c51819799ba90a189db597d3e5e3888ae76e43f766
|
7
|
+
data.tar.gz: ea83ae1b26e155bbde0ab34f6dcd18e74b9262a47c6512f3168d4e612088c04b65a852631ae0612deccf7099c514c3a15a47fcc45464d8786b7fe8c56ff3a1d6
|
data/.concert.yml
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rds_concerto (0.1.0)
|
5
|
+
aws-sdk-rds
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
aws-eventstream (1.0.3)
|
12
|
+
aws-partitions (1.240.0)
|
13
|
+
aws-sdk-core (3.78.0)
|
14
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
15
|
+
aws-partitions (~> 1, >= 1.239.0)
|
16
|
+
aws-sigv4 (~> 1.1)
|
17
|
+
jmespath (~> 1.0)
|
18
|
+
aws-sdk-rds (1.71.0)
|
19
|
+
aws-sdk-core (~> 3, >= 3.71.0)
|
20
|
+
aws-sigv4 (~> 1.1)
|
21
|
+
aws-sigv4 (1.1.0)
|
22
|
+
aws-eventstream (~> 1.0, >= 1.0.2)
|
23
|
+
coderay (1.1.2)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
jmespath (1.4.0)
|
26
|
+
method_source (0.9.2)
|
27
|
+
pry (0.12.2)
|
28
|
+
coderay (~> 1.1.0)
|
29
|
+
method_source (~> 0.9.0)
|
30
|
+
rake (10.5.0)
|
31
|
+
rspec (3.9.0)
|
32
|
+
rspec-core (~> 3.9.0)
|
33
|
+
rspec-expectations (~> 3.9.0)
|
34
|
+
rspec-mocks (~> 3.9.0)
|
35
|
+
rspec-core (3.9.0)
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-expectations (3.9.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-mocks (3.9.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.9.0)
|
43
|
+
rspec-support (3.9.0)
|
44
|
+
thor (0.20.3)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler
|
51
|
+
pry
|
52
|
+
rake (~> 10.0)
|
53
|
+
rds_concerto!
|
54
|
+
rspec (~> 3.0)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 jiikko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# RdsConcerto
|
2
|
+
|
3
|
+
This gem provide feature which to clone Aurora(MySQL) instance.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rds_concerto', require: false, group: :development
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rds_concerto
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
### Config
|
23
|
+
Put yaml to project root as `.concert.yml`.
|
24
|
+
|
25
|
+
```yaml
|
26
|
+
aws:
|
27
|
+
region: ap-northeast-1
|
28
|
+
access_key_id: aaaaaaaaaaaaaaaaa
|
29
|
+
secret_access_key: bbbbbbbbbbbbbbb
|
30
|
+
account_id: 111111111
|
31
|
+
database_url_format: "mysql2://master_username:master_user_password@{{endpoint}}/your_db_name?pool=5"
|
32
|
+
db_instance:
|
33
|
+
source:
|
34
|
+
identifier: a
|
35
|
+
cluster_identifier: b
|
36
|
+
new:
|
37
|
+
available_types:
|
38
|
+
- db.r4.large
|
39
|
+
- db.r4.2xlarge
|
40
|
+
- db.r4.3xlarge
|
41
|
+
default_instance_type: db.r4.large
|
42
|
+
db_parameter_group_name: default
|
43
|
+
db_cluster_parameter_group_name: default
|
44
|
+
publicly_accessible: false
|
45
|
+
db_subnet_group_name: default-vpc-**************
|
46
|
+
```
|
47
|
+
|
48
|
+
* db_instance.db_subnet_group_name
|
49
|
+
* optional. need subnet name, if you want public access.
|
50
|
+
* database_url_format
|
51
|
+
* optional.
|
52
|
+
* If you exec url command, need it.
|
53
|
+
|
54
|
+
### Command
|
55
|
+
```shell
|
56
|
+
bundle exec bin/concerto --help
|
57
|
+
```
|
58
|
+
|
59
|
+
## Warnging
|
60
|
+
|
61
|
+
This tool is not provied data mask feature. You will need to mask in other ways.
|
62
|
+
I think good way is to do clone from masked db. the masked db do to restore from backup each day.
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
74
|
+
|
75
|
+
## TODO
|
76
|
+
* raise error when arg do not include in available_types
|
77
|
+
* matomeru args of RdsConcerto::CLI methods
|
78
|
+
* command log
|
79
|
+
* override mysql login and password
|
80
|
+
* Web interface
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rds_concerto"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/concerto
ADDED
data/lib/rds_concerto.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rds_concerto/version"
|
2
|
+
require "rds_concerto/aurora"
|
3
|
+
|
4
|
+
module RdsConcerto
|
5
|
+
DEFAULT_CONFIG_FILE_NAME = './.concert.yml'
|
6
|
+
end
|
7
|
+
|
8
|
+
require "rds_concerto/cli"
|
9
|
+
require "rds_concerto/config"
|
10
|
+
require "rds_concerto/aurora/client"
|
11
|
+
require "rds_concerto/aurora/resource"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'aws-sdk-rds'
|
4
|
+
|
5
|
+
module RdsConcerto::Aurora
|
6
|
+
def self.new(config_path: nil)
|
7
|
+
config_path = config_path || ENV['CONCERT_CONFIG_PATH'] || RdsConcerto::DEFAULT_CONFIG_FILE_NAME
|
8
|
+
yaml = File.open(config_path)
|
9
|
+
hash = YAML.load(ERB.new(yaml.read).result) || raise('yaml parse error')
|
10
|
+
RdsConcerto::Config.configure_from_hash(hash)
|
11
|
+
if ENV['VERBOSE_CONCERTO']
|
12
|
+
puts RdsConcerto::Config.inspect
|
13
|
+
end
|
14
|
+
unless RdsConcerto::Config.valid?
|
15
|
+
raise RdsConcerto::Config.errors.inspect
|
16
|
+
end
|
17
|
+
return Client.new(
|
18
|
+
rds_client: Aws::RDS::Client.new(rds_client_args(hash)),
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.rds_client_args(hash)
|
23
|
+
{ region: 'ap-northeast-1',
|
24
|
+
access_key_id: hash['aws']['access_key_id'].to_s,
|
25
|
+
secret_access_key: hash['aws']['secret_access_key'].to_s,
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class RdsConcerto::Aurora::Client
|
2
|
+
attr_reader :rds_client
|
3
|
+
|
4
|
+
def initialize(rds_client: )
|
5
|
+
@rds_client = rds_client
|
6
|
+
end
|
7
|
+
|
8
|
+
def source_db_instance
|
9
|
+
@source_db_instance ||= self.all_instances.detect { |x| x[:name] == RdsConcerto::Config.source_identifier }
|
10
|
+
end
|
11
|
+
|
12
|
+
def cloned_instances
|
13
|
+
list = self.all_instances.reject { |x| x[:name] == RdsConcerto::Config.source_identifier }
|
14
|
+
list.select { |x| /^#{clone_instance_name_base}/ =~ x[:name] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def all_instances
|
18
|
+
rds_client.describe_db_instances.db_instances.map do |db_instance|
|
19
|
+
response = rds_client.list_tags_for_resource(
|
20
|
+
resource_name: get_arn(identifier: db_instance.db_instance_identifier)
|
21
|
+
)
|
22
|
+
{ name: db_instance.db_instance_identifier,
|
23
|
+
size: db_instance.db_instance_class,
|
24
|
+
engine: db_instance.engine,
|
25
|
+
version: db_instance.engine_version,
|
26
|
+
storage: db_instance.allocated_storage,
|
27
|
+
endpoint: db_instance.endpoint&.address,
|
28
|
+
status: db_instance.db_instance_status,
|
29
|
+
created_at: db_instance.instance_create_time,
|
30
|
+
tag: response.tag_list.map(&:to_hash),
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def clone!(instance_name: nil, klass: nil, identifier: nil, dry_run: false)
|
36
|
+
name = "#{clone_instance_name_base}-#{Time.now.to_i}"
|
37
|
+
identifier_value = identifier || `hostname`.chomp[0..10]
|
38
|
+
tags = [{ key: "created_by", value: identifier_value }]
|
39
|
+
klass ||= RdsConcerto::Config.default_instance_type
|
40
|
+
RdsConcerto::Aurora::Resource.new(rds_client: rds_client, name: name).
|
41
|
+
create!(tags: tags, instance_class: klass) unless dry_run
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy!(name: nil, skip_final_snapshot: true, dry_run: false)
|
45
|
+
if [RdsConcerto::Config.source_identifier, RdsConcerto::Config.source_cluster_identifier].include?(name)
|
46
|
+
raise 'Command failed. Can not delete source resource.'
|
47
|
+
end
|
48
|
+
if not cloned_instances.map { |x| x[:name] }.include?(name)
|
49
|
+
raise 'Command failed. Do not found resource.'
|
50
|
+
end
|
51
|
+
RdsConcerto::Aurora::Resource.new(rds_client: rds_client, name: name).
|
52
|
+
delete!(skip_final_snapshot: skip_final_snapshot) unless dry_run
|
53
|
+
end
|
54
|
+
|
55
|
+
def url(name)
|
56
|
+
unless RdsConcerto::Config.has_vals_for_url_command?
|
57
|
+
raise 'Please set vals in `.concerto.yaml`.'
|
58
|
+
end
|
59
|
+
instance =
|
60
|
+
if name
|
61
|
+
cloned_instances.detect {|i| i[:name] == name }
|
62
|
+
else
|
63
|
+
cloned_instances.first
|
64
|
+
end
|
65
|
+
unless instance
|
66
|
+
puts "Instance is not existing."
|
67
|
+
exit(1)
|
68
|
+
end
|
69
|
+
unless instance[:endpoint]
|
70
|
+
puts "A instance is continue preparing."
|
71
|
+
exit(1)
|
72
|
+
end
|
73
|
+
RdsConcerto::Config.database_url_format.gsub('{{endpoint}}', instance[:endpoint])
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def get_arn(identifier: )
|
79
|
+
"arn:aws:rds:#{RdsConcerto::Config.region}:#{RdsConcerto::Config.aws_account_id}:db:#{identifier}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def clone_instance_name_base
|
83
|
+
source = source_db_instance
|
84
|
+
unless source
|
85
|
+
raise 'Source db instance do not found'
|
86
|
+
end
|
87
|
+
unless source[:status] == "available"
|
88
|
+
raise 'Source db instance do not available'
|
89
|
+
end
|
90
|
+
instance_name = source[:name]
|
91
|
+
"#{source[:name]}-clone"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class RdsConcerto::Aurora::Resource
|
2
|
+
attr_reader :name, :rds_client
|
3
|
+
|
4
|
+
def initialize(rds_client: , name: )
|
5
|
+
@rds_client = rds_client
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete!(skip_final_snapshot: )
|
10
|
+
{ db_instance_response: rds_client.delete_db_instance(db_instance_identifier: name, skip_final_snapshot: skip_final_snapshot),
|
11
|
+
rdb_cluster_response: rds_client.delete_db_cluster(db_cluster_identifier: name, skip_final_snapshot: skip_final_snapshot),
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def create!(tags: , instance_class: )
|
16
|
+
{ db_cluster_response: restore_db_cluster!(name: name, tags: tags),
|
17
|
+
db_instance_response: create_db_instance!(name: name, tags: tags, instance_class: instance_class),
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def restore_db_cluster!(name: , tags: )
|
24
|
+
rds_client.restore_db_cluster_to_point_in_time(
|
25
|
+
db_cluster_identifier: name,
|
26
|
+
source_db_cluster_identifier: RdsConcerto::Config.source_cluster_identifier,
|
27
|
+
restore_type: "copy-on-write",
|
28
|
+
use_latest_restorable_time: true,
|
29
|
+
db_cluster_parameter_group_name: RdsConcerto::Config.db_cluster_parameter_group_name,
|
30
|
+
db_subnet_group_name: RdsConcerto::Config.db_subnet_group_name,
|
31
|
+
tags: tags,
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_db_instance!(name: , tags: , instance_class: )
|
36
|
+
rds_client.create_db_instance(
|
37
|
+
db_instance_identifier: name,
|
38
|
+
db_cluster_identifier: name,
|
39
|
+
db_instance_class: instance_class,
|
40
|
+
engine: "aurora-mysql",
|
41
|
+
multi_az: false,
|
42
|
+
publicly_accessible: true,
|
43
|
+
db_subnet_group_name: RdsConcerto::Config.db_subnet_group_name,
|
44
|
+
db_parameter_group_name: RdsConcerto::Config.db_parameter_group_name,
|
45
|
+
tags: tags,
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
class RdsConcerto::CLI < Thor
|
4
|
+
# https://github.com/erikhuda/thor/issues/607
|
5
|
+
include Thor::Actions
|
6
|
+
add_runtime_options!
|
7
|
+
|
8
|
+
desc "list", "レプリカやクローン一覧の閲覧"
|
9
|
+
option :config, aliases: "-c", default: RdsConcerto::DEFAULT_CONFIG_FILE_NAME, desc: "設定ファイル"
|
10
|
+
def list(stdout=true)
|
11
|
+
out = ''
|
12
|
+
out += show_replica
|
13
|
+
out << "\n"
|
14
|
+
out += show_clones
|
15
|
+
out << "\n"
|
16
|
+
if stdout
|
17
|
+
puts out
|
18
|
+
else
|
19
|
+
out
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "create NAME(レプリカを選択したい場合。指定しなければ適当に選びます)", "インスタンスの作成"
|
24
|
+
option :type, aliases: "-t", default: nil, desc: "インスタンスタイプ"
|
25
|
+
option :config, aliases: "-c", default: RdsConcerto::DEFAULT_CONFIG_FILE_NAME, desc: "設定ファイル"
|
26
|
+
def create
|
27
|
+
concerto = RdsConcerto::Aurora.new(config_path: options[:config])
|
28
|
+
concerto.clone!(klass: options[:type], dry_run: options[:pretend])
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "destroy NAME", "インスタンスの削除"
|
32
|
+
option :config, aliases: "-c", default: RdsConcerto::DEFAULT_CONFIG_FILE_NAME, desc: "設定ファイル"
|
33
|
+
option :name, desc: "instance identifier of delete target"
|
34
|
+
def destroy(name=nil)
|
35
|
+
concerto = RdsConcerto::Aurora.new(config_path: options[:config])
|
36
|
+
concerto.destroy!(name: name || options[:name], dry_run: options[:pretend])
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "url NAME(URL を取得するインスタンスを指定したい場合。指定しなければ適当に選びます)", "インスタンスに接続するための URL の取得"
|
40
|
+
def url(name = nil)
|
41
|
+
concerto = RdsConcerto::Aurora.new(config_path: options[:config])
|
42
|
+
puts concerto.url(name)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def show_replica
|
48
|
+
concerto = RdsConcerto::Aurora.new(config_path: options[:config])
|
49
|
+
out = "-source db instance-"
|
50
|
+
row = <<~EOH
|
51
|
+
-------
|
52
|
+
name: %{name}
|
53
|
+
size: %{size}
|
54
|
+
engine: %{engine}
|
55
|
+
version: %{version}
|
56
|
+
endpoint: %{endpoint}
|
57
|
+
status: %{status}
|
58
|
+
created_at: %{created_at}
|
59
|
+
EOH
|
60
|
+
|
61
|
+
if concerto.source_db_instance
|
62
|
+
out << row % concerto.source_db_instance
|
63
|
+
end
|
64
|
+
out
|
65
|
+
end
|
66
|
+
|
67
|
+
def show_clones
|
68
|
+
concerto = RdsConcerto::Aurora.new(config_path: options[:config])
|
69
|
+
out = "-clone db instances-"
|
70
|
+
row = <<~EOH
|
71
|
+
-------
|
72
|
+
name: %{name}
|
73
|
+
size: %{size}
|
74
|
+
engine: %{engine}
|
75
|
+
version: %{version}
|
76
|
+
endpoint: %{endpoint}
|
77
|
+
status: %{status}
|
78
|
+
created_at: %{created_at}
|
79
|
+
tags: %{tag}
|
80
|
+
EOH
|
81
|
+
concerto.cloned_instances.each do |hash|
|
82
|
+
out << row % hash
|
83
|
+
end
|
84
|
+
out
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class RdsConcerto::Config
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_reader \
|
8
|
+
:source_identifier,
|
9
|
+
:source_cluster_identifier,
|
10
|
+
:region,
|
11
|
+
:aws_account_id,
|
12
|
+
:default_instance_type,
|
13
|
+
:available_types,
|
14
|
+
:db_parameter_group_name,
|
15
|
+
:db_cluster_parameter_group_name,
|
16
|
+
:db_subnet_group_name,
|
17
|
+
:master_user_password,
|
18
|
+
:master_username,
|
19
|
+
:database_url_format
|
20
|
+
|
21
|
+
def configure_from_hash(hash)
|
22
|
+
@source_identifier = hash.dig('db_instance', 'source', 'identifier')
|
23
|
+
@source_cluster_identifier = hash.dig('db_instance', 'source', 'cluster_identifier')
|
24
|
+
@region = hash.dig('aws', 'region')
|
25
|
+
@aws_account_id = hash.dig('aws', 'account_id')
|
26
|
+
@default_instance_type = hash.dig('db_instance', 'new', 'default_instance_type')
|
27
|
+
@available_types = hash.dig('db_instance', 'new', 'available_types')
|
28
|
+
@db_parameter_group_name = hash.dig('db_instance', 'new', 'db_parameter_group_name')
|
29
|
+
@db_cluster_parameter_group_name = hash.dig('db_instance', 'new', 'db_cluster_parameter_group_name')
|
30
|
+
@db_subnet_group_name = hash.dig('db_instance', 'new', 'db_subnet_group_name')
|
31
|
+
@master_user_password = hash.dig('db_instance', 'new', 'master_user_password')
|
32
|
+
@master_username = hash.dig('db_instance', 'new', 'master_username')
|
33
|
+
@database_url_format = hash.dig('database_url_format')
|
34
|
+
|
35
|
+
@errors = []
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid?
|
39
|
+
true
|
40
|
+
validate_presence
|
41
|
+
return @errors.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_vals_for_url_command?
|
45
|
+
!!database_url_format
|
46
|
+
end
|
47
|
+
|
48
|
+
def errors
|
49
|
+
@errors.join("\n")
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate_presence
|
53
|
+
requireds =
|
54
|
+
%w( source_identifier
|
55
|
+
source_cluster_identifier
|
56
|
+
region
|
57
|
+
aws_account_id
|
58
|
+
default_instance_type
|
59
|
+
db_parameter_group_name
|
60
|
+
db_cluster_parameter_group_name
|
61
|
+
)
|
62
|
+
blank_names = []
|
63
|
+
requireds.each do |name|
|
64
|
+
if public_send(name).nil?
|
65
|
+
blank_names << name
|
66
|
+
end
|
67
|
+
end
|
68
|
+
unless blank_names.empty?
|
69
|
+
@errors << "Need #{blank_names.join(', ')}. Check config yaml"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rds_concerto/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rds_concerto"
|
7
|
+
spec.version = RdsConcerto::VERSION
|
8
|
+
spec.authors = ["jiikko"]
|
9
|
+
spec.email = ["n905i.1214@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{tool that to clone AWS-RDS Aurora instance}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/jiikko/rds_concerto"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "aws-sdk-rds"
|
26
|
+
spec.add_dependency "thor"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "pry"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rds_concerto
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jiikko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-rds
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: tool that to clone AWS-RDS Aurora instance
|
98
|
+
email:
|
99
|
+
- n905i.1214@gmail.com
|
100
|
+
executables:
|
101
|
+
- concerto
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".concert.yml"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/concerto
|
117
|
+
- lib/rds_concerto.rb
|
118
|
+
- lib/rds_concerto/aurora.rb
|
119
|
+
- lib/rds_concerto/aurora/client.rb
|
120
|
+
- lib/rds_concerto/aurora/resource.rb
|
121
|
+
- lib/rds_concerto/cli.rb
|
122
|
+
- lib/rds_concerto/config.rb
|
123
|
+
- lib/rds_concerto/version.rb
|
124
|
+
- rds_concerto.gemspec
|
125
|
+
homepage: https://github.com/jiikko/rds_concerto
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.7.6
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: tool that to clone AWS-RDS Aurora instance
|
149
|
+
test_files: []
|