lib/simnos/dsl/subscription.rb in simnos-0.1.1.beta1 vs lib/simnos/dsl/subscription.rb in simnos-0.1.1.beta2

- old
+ new

@@ -4,11 +4,11 @@ class DSL class Subscription include Simnos::TemplateHelper def create - Simnos.logger.info("Create Topic(#{@aws_topic[:topic].topic_arn.split(':').last}) Subscription. protocol: #{protocol.inspect}, endpoint: #{endpoint.inspect}#{@options[:dry_run] ? ' [dry-run]' : ''}") + Simnos.logger.info("Create Topic(#{@aws_topic[:topic].topic_arn.split(':').last}) Subscription. protocol: #{protocol.inspect}, endpoint: #{masked_endpoint.inspect}#{@options[:dry_run] ? ' [dry-run]' : ''}") return if @options[:dry_run] client.subscribe( topic_arn: @aws_topic[:topic].topic_arn, protocol: protocol, @@ -27,10 +27,31 @@ @topic = topic @protocol = protocol @endpoint = endpoint end - attr_reader :topic, :protocol, :endpoint + attr_reader :topic, :protocol + + # We have to mask endpoint because SNS returns masked endpoint from API + def masked_endpoint + if URI.extract(@endpoint, ['http', 'https']).empty? + return endpoint + end + uri = URI.parse(endpoint) + if md = uri.userinfo&.match(/(.*):(.*)/) + uri.userinfo = "#{md[1]}:****" + end + uri.to_s + end + + def endpoint + secret_expander = @options[:secret_expander] + if secret_expander + secret_expander.expand(@endpoint) + else + @endpoint + end + end private def client @client ||= Simnos::ClientWrapper.new(@context)