Skip to content

Commit d3384ed

Browse files
authored
Merge pull request #25 from CU-CloudCollab/modify-securirty-groups
Modify securirty groups
2 parents a5d842d + 30f2036 commit d3384ed

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

lib/cucloud/rds_utils.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_instance(db_instance_identifier)
2424
def does_db_exist?(db_instance_identifier)
2525
get_instance(db_instance_identifier).instance_create_time
2626
true
27-
rescue Aws::RDS::Errors::DBInstanceNotFound
27+
rescue
2828
false
2929
end
3030

@@ -46,6 +46,32 @@ def delete_db_instance(db_instance_identifier, db_snapshot_identifier = nil)
4646
end
4747
end
4848

49+
# Modify the security groups for a RDS instance
50+
# @param db_instance_identifier [String] RDS instance identifier
51+
# @param vpc_security_group_ids [Array] Array of security groups to apply
52+
# @return [Hash] Hash represnting the return from AWS
53+
def modify_security_group(db_instance_identifier, vpc_security_groups)
54+
modify_db_instance(db_instance_identifier: db_instance_identifier, vpc_security_group_ids: vpc_security_groups)
55+
end
56+
57+
# Modify the options group for a RDS instance
58+
# @param db_instance_identifier [String] RDS instance identifier
59+
# @param option_group_name [Sting] Name od the options group to apply
60+
# @return [Hash] Hash represnting the return from AWS
61+
def modify_option_group(db_instance_identifier, option_group_name)
62+
modify_db_instance(db_instance_identifier: db_instance_identifier, option_group_name: option_group_name)
63+
end
64+
65+
# Base function to modify DB, resets defualts for apply_immediately and copy_tags_to_snapshot
66+
# @param options [hash] Hash represnting the configuration for the RDS restore
67+
# @return [Hash] Hash represnting the return from AWS
68+
def modify_db_instance(options)
69+
options[:apply_immediately] = options[:apply_immediately].nil? ? true : options[:apply_immediately]
70+
options[:copy_tags_to_snapshot] = options[:copy_tags_to_snapshot].nil? ? true : options[:copy_tags_to_snapshot]
71+
72+
@rds.modify_db_instance(options)
73+
end
74+
4975
# Restore DB from a snapshot
5076
# @param db_instance_identifier [String] RDS instance identifier
5177
# @param db_snapshot_identifier [String] Name for final snapshot, default is nil
@@ -57,6 +83,7 @@ def restore_db(db_instance_identifier, restore_from, options = {})
5783
options[:db_instance_identifier] = db_instance_identifier
5884
options[:db_snapshot_identifier] = db_snapshot_identifier
5985
@rds.restore_db_instance_from_db_snapshot(options)
86+
@rds.wait_until(:db_instance_deleted, db_instance_identifier: db_instance_identifier)
6087
end
6188

6289
# Delete a givne db instance

lib/cucloud/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Cucloud
22
# Disable mutable constant warning - freezing this oddly breaks bundler
33
# rubocop:disable Style/MutableConstant
4-
VERSION = '0.7.2'
4+
VERSION = '0.7.3'
55
end

spec/rds_utils_spec.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,29 @@
5151
expect(Cucloud::RdsUtils.new(rds_client)).to be_a_kind_of(Cucloud::RdsUtils)
5252
end
5353

54-
context 'while describe_db_instances is returns an instand not found error' do
54+
context 'while modify_db_instance is stubbed out' do
55+
before do
56+
rds_client.stub_responses(
57+
:modify_db_instance,
58+
db_instance: {
59+
db_instance_identifier: 'testDb'
60+
}
61+
)
62+
end
63+
describe '#modify_security_group' do
64+
it 'shoud not rais an error' do
65+
expect { rds_utils.modify_security_group('testDb', ['sg-084646']) }.not_to raise_error
66+
end
67+
end
68+
69+
describe '#modify_option_group' do
70+
it 'shoud not rais an error' do
71+
expect { rds_utils.modify_option_group('testDb', 'options-group') }.not_to raise_error
72+
end
73+
end
74+
end
75+
76+
context 'while describe_db_instances returns an instand not found error' do
5577
before do
5678
rds_client.stub_responses(
5779
:describe_db_instances,

0 commit comments

Comments
 (0)