~singpolyma/sgx-jmp

b47b7d0d0188f4ba1a55739499907746c02565b1 — Stephen Paul Weber 2 months ago acd8226 + 18258dd
Merge branch 'fwd-cleanup'

* fwd-cleanup:
  Try to classify URI before saving, even if timeout.zero?
  v1 is dead and everyone has been moved
  Allow finishing adming command
3 files changed, 14 insertions(+), 33 deletions(-)

M .rubocop.yml
M lib/bwmsgsv2_repo.rb
M lib/customer_fwd.rb
M .rubocop.yml => .rubocop.yml +3 -0
@@ 55,6 55,9 @@ Layout/LineLength:
  Exclude:
    - Gemfile

Layout/EndAlignment:
  EnforcedStyleAlignWith: start_of_line

Layout/SpaceAroundEqualsInParameterDefault:
  EnforcedStyle: no_space


M lib/bwmsgsv2_repo.rb => lib/bwmsgsv2_repo.rb +1 -11
@@ 50,21 50,11 @@ class Bwmsgsv2Repo
				"catapult_fwd_timeout-#{sgx.from_jid}",
				customer_fwd.timeout.to_i
			)
		]).then do
			set_default_location(tel) if customer_fwd.v2_safe?
		end
		])
	end

protected

	def set_default_location(tel)
		# Migrate location if needed
		BandwidthIris::SipPeer.new(
			site_id: CONFIG[:bandwidth_site],
			id: CONFIG[:bandwidth_peer]
		).move_tns([tel])
	end

	def set_or_delete(k, v)
		if v.nil?
			REDIS.del(k)

M lib/customer_fwd.rb => lib/customer_fwd.rb +10 -22
@@ 7,14 7,18 @@ require "uri"
class CustomerFwd
	def self.for(uri:, timeout:)
		timeout = Timeout.new(timeout)
		return None.new(uri: uri, timeout: timeout) if !uri || timeout.zero?

		if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/
			uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}"
		fwd = if uri
			if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/
				uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}"
			end

			URIS.fetch(uri.split(":", 2).first.to_sym) {
				raise "Unknown forward URI: #{uri}"
			}.new(uri: uri, timeout: timeout)
		end
		URIS.fetch(uri.split(":", 2).first.to_sym) {
			raise "Unknown forward URI: #{uri}"
		}.new(uri: uri, timeout: timeout)

		fwd && !timeout.zero? ? fwd : None.new(uri: uri, timeout: timeout)
	end

	class Timeout


@@ 57,15 61,7 @@ class CustomerFwd
		BANDWIDTH_VOICE.create_call(account, body: request).data.call_id
	end

	def v2_safe?
		false
	end

	class Tel < CustomerFwd
		def v2_safe?
			true
		end

		def initialize(values)
			super
			raise "Bad tel format: #{uri}" unless uri.match?(/\Atel:\+1\d{10}\Z/)


@@ 77,20 73,12 @@ class CustomerFwd
	end

	class SIP < CustomerFwd
		def v2_safe?
			uri.end_with?(CONFIG[:sip][:realm])
		end

		def to
			uri
		end
	end

	class XMPP < CustomerFwd
		def v2_safe?
			true
		end

		def to
			jid = uri.sub(/^xmpp:/, "")
			"sip:#{ERB::Util.url_encode(jid)}@sip.cheogram.com"