class Simnos::DSL::Topic::Result
Constants
- ATTRIBUTES
- CREATE_KEYS
- MODIFY_ATTRS
- MODIFY_ATTRS_HASH
Public Class Methods
new(context)
click to toggle source
# File lib/simnos/dsl/topic.rb, line 14 def initialize(context) @context = context @options = context.options @subscriptions = [] end
Public Instance Methods
attrs_updated?()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 47 def attrs_updated? to_h end
aws(aws_topic)
click to toggle source
# File lib/simnos/dsl/topic.rb, line 42 def aws(aws_topic) @aws_topic = aws_topic self end
client()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 130 def client @client ||= Simnos::ClientWrapper.new(@context) end
create()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 29 def create Simnos.logger.info("Create Topic #{name}.#{@options[:dry_run] ? ' [dry-run]' : ''}".colorize(:green)) return { topic: Hashie::Mash.new(topic_arn: 'not yet created') } if @options[:dry_run] resp = client.create_topic(name: name) # save topic_arn topic_arn = resp.topic_arn { topic: resp, attrs: client.topic_attrs(topic_arn: resp.topic_arn) } end
create_option()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 25 def create_option to_h.select { |k, _| CREATE_KEYS.include?(k) } end
modify()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 51 def modify modify_attrs modify_attrs_hash end
modify_attr(dsl_val, attr_name)
click to toggle source
# File lib/simnos/dsl/topic.rb, line 68 def modify_attr(dsl_val, attr_name) aws_val = @aws_topic[:attrs].attributes[attr_name] return if dsl_val == aws_val Simnos.logger.debug('--- aws ---') Simnos.logger.debug(@aws_topic[:attrs].attributes.pretty_inspect) Simnos.logger.debug('--- dsl ---') Simnos.logger.debug(dsl_val) Simnos.logger.info("Modify Topic `#{name}` #{attr_name} attributes.#{@options[:dry_run] ? ' [dry-run]' : ''}".colorize(:blue)) dsl_attrs = { attribute_name: attr_name, attribute_value: dsl_val, } diff = Simnos::Utils.diff({ attribute_name: attr_name, attribute_value: aws_val, }, dsl_attrs, color: @options[:color], ) Simnos.logger.info("<diff>\n#{diff}") return if @options[:dry_run] client.set_topic_attributes(dsl_attrs.merge(topic_arn: @aws_topic[:topic].topic_arn)) end
modify_attr_hash(dsl_val, attr_name)
click to toggle source
# File lib/simnos/dsl/topic.rb, line 93 def modify_attr_hash(dsl_val, attr_name) aws_val = JSON.parse(@aws_topic[:attrs].attributes[attr_name]) return if Simnos::Utils.normalize_hash(dsl_val) == Simnos::Utils.normalize_hash(aws_val) Simnos.logger.info("Modify Topic `#{name}` #{attr_name} attributes.#{@options[:dry_run] ? ' [dry-run]' : ''}".colorize(:blue)) dsl_attrs = { attribute_name: attr_name, attribute_value: dsl_val, } diff = Simnos::Utils.diff({ attribute_name: attr_name, attribute_value: aws_val, }, dsl_attrs, color: @options[:color], ) Simnos.logger.info("<diff>\n#{diff}") return if @options[:dry_run] dsl_attrs.merge!(topic_arn: @aws_topic[:topic].topic_arn) dsl_attrs[:attribute_value] = dsl_attrs[:attribute_value].to_json if attr_name == 'Policy' client.set_topic_attributes(dsl_attrs) elsif attr_name == 'EffectiveDeliveryPolicy' dsl_attrs[:attribute_name] = 'DeliveryPolicy' client.set_topic_attributes(dsl_attrs) end end
modify_attrs()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 62 def modify_attrs MODIFY_ATTRS.each do |prop_name, attr_name| modify_attr(send(prop_name), attr_name) end end
modify_attrs_hash()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 124 def modify_attrs_hash MODIFY_ATTRS_HASH.each do |prop_name, attr_name| modify_attr_hash(send(prop_name), attr_name) end end
to_h()
click to toggle source
# File lib/simnos/dsl/topic.rb, line 20 def to_h Hash[ATTRIBUTES.sort.map { |name| [name, public_send(name)] }] end