Class: AwsXRegionSync::AwsSync
- Inherits:
-
Object
- Object
- AwsXRegionSync::AwsSync
show all
- Defined in:
- lib/aws_xregion_sync/aws_sync.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(sync_name, config) ⇒ AwsSync
Returns a new instance of AwsSync.
6
7
8
9
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 6
def initialize sync_name, config
@sync_name = sync_name
@config = config
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4
5
6
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 4
def config
@config
end
|
#sync_name ⇒ Object
Returns the value of attribute sync_name.
4
5
6
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 4
def sync_name
@sync_name
end
|
Instance Method Details
#aws_config ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 36
def aws_config
global = config['aws_client_config']
unless global
global = {}
config['aws_client_config'] = global
end
global
end
|
#create_sync_tag(region, source_identifier, options = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 49
def create_sync_tag region, source_identifier, options = {}
options = {timestamp: Time.now}.merge options
timestamp = options[:timestamp].utc
key = "#{sync_tag_indicator}"
key += "-#{options[:sync_subtype]}" if options[:sync_subtype]
key += "-#{region}"
{key: key, value: build_sync_tag_value(source_identifier, timestamp)}
end
|
#discover_aws_account_id(raise_error_if_not_found = true) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 76
def discover_aws_account_id raise_error_if_not_found = true
return @aws_account_id if defined?(@aws_account_id)
aws_account_id = aws_config['aws_account_id']
unless aws_account_id
aws_account_id = retrieve_aws_account_id
end
raise AwsXRegionSyncConfigError, "The #{self.sync_name} configuration must provide an 'aws_account_id' option to use for manipulating snapshot tags, unable to retrieve id automatically." if (aws_account_id.nil? || aws_account_id.length == 0) && raise_error_if_not_found
@aws_account_id = aws_account_id
end
|
#parse_config_filters(config_filters) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 24
def parse_config_filters config_filters
filters = []
config_filters.each do |cf|
split = cf.to_s.split("=")
raise AwsXRegionSyncConfigError, "The #{sync_name} configuration 'filters' value '#{cf}' must be of the form filter-field=filter-value." unless split.size == 2
filters << split
end
filters
end
|
#parse_sync_tag_value(value) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 59
def parse_sync_tag_value value
values = {}
if value && value.length > 0
split = value.split(" / ")
values[:timestamp] = Time.strptime(split[0], timestamp_format).utc
values[:resource_identifier] = split[1]
end
values
end
|
#sync_tag_indicator ⇒ Object
72
73
74
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 72
def sync_tag_indicator
"Sync"
end
|
#validate_config ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/aws_xregion_sync/aws_sync.rb', line 11
def validate_config
raise AwsXRegionSyncConfigError, "The #{sync_name} configuration must have a valid 'source_region' value." unless config['source_region'] && config['source_region'].length > 0
raise AwsXRegionSyncConfigError, "The #{sync_name} configuration must have a valid 'destination_region' value." unless config['destination_region'] && config['destination_region'].length > 0
if config['filters']
raise AwsXRegionSyncConfigError, "The #{sync_name} configuration 'filters' value must be an Enumerable object." unless config['filters'] && config['filters'].is_a?(Enumerable)
parse_config_filters config['filters']
end
self
end
|