Class: Simnos::Client
- Inherits:
-
Object
- Object
- Simnos::Client
- Includes:
- Filterable
- Defined in:
- lib/simnos/client.rb
Constant Summary collapse
- MAGIC_COMMENT =
"# -*- mode: ruby -*-\n# vi: set ft=ruby :\n"
Instance Method Summary collapse
- #apply ⇒ Object
- #export ⇒ Object
-
#initialize(filepath, options = {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Filterable
Constructor Details
#initialize(filepath, options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 |
# File 'lib/simnos/client.rb', line 15 def initialize(filepath, = {}) @filepath = filepath = end |
Instance Method Details
#apply ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simnos/client.rb', line 20 def apply Simnos.logger.info("Applying...#{@options[:dry_run] ? ' [dry-run]' : ''}") dsl = load_file(@filepath) dsl.snss.each do |region, sns| [:region] = region Simnos.logger.info("region: #{region}") aws_topics_by_name = client.topics traverse_topics(sns.topics, aws_topics_by_name) end end |
#export ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simnos/client.rb', line 32 def export Simnos.logger.info("Exporting...#{@options[:dry_run] ? ' [dry-run]' : ''}") topics_by_name = client.topics if [:with_subscriptions] topics_by_name.each do |name, topic| Simnos.logger.debug("exporting subscriptions of #{topic[:topic].topic_arn}") topic[:subscriptions] = client.subscriptions_by_topic(topic_arn: topic[:topic].topic_arn) end end region = client.region path = Pathname.new(@filepath) base_dir = path.parent if [:split] FileUtils.mkdir_p(base_dir) topics_by_name.each do |name, aws| Converter.new({name => aws}, region).convert do |dsl| sns_file = base_dir.join("#{name}.sns") Simnos.logger.info("Export #{sns_file}") open(sns_file, 'wb') do |f| f.puts MAGIC_COMMENT f.puts dsl end end end else Converter.new(topics_by_name, region).convert do |dsl| FileUtils.mkdir_p(base_dir) Simnos.logger.info("Export #{path}") open(path, 'wb') do |f| f.puts MAGIC_COMMENT f.puts dsl end end end end |