diff --git a/config-schema.dhall b/config-schema.dhall index 553d672962c716fa2c995a23a19f22bb7ea7d518..fd5ab67b2964c0bca619510e27e1b9d654f2381e 100644 --- a/config-schema.dhall +++ b/config-schema.dhall @@ -11,14 +11,6 @@ , private_key : Text , public_key : Text } -, catapult : - { application_id : Text - , domain : Text - , secret : Text - , sip_host : Text - , token : Text - , user : Text - } , component : { jid : Text, secret : Text } , credit_card_url : forall (jid : Text) -> forall (customer_id : Text) -> Text , creds : { account : Text, password : Text, username : Text } diff --git a/config.dhall.sample b/config.dhall.sample index f07da0763a3d073b22ecda39dd17992445d8aff9..3e19598df5cd8ad7565ccb03d4938dae6ef9dfd9 100644 --- a/config.dhall.sample +++ b/config.dhall.sample @@ -19,14 +19,6 @@ in username = "dashboard user", password = "dashboard password" }, - catapult = { - user = "", - token = "", - secret = "", - application_id = "", - domain = "", - sip_host = "" - }, web_register = { to = "cheogram", from = "jmp-register@localhost" diff --git a/lib/bandwidth_tn_order.rb b/lib/bandwidth_tn_order.rb index 2753f64434591e1ac8935c8cd30712107826ec4d..bf2093f00dcbcf2417f8b93d1016cb1c6022ce18 100644 --- a/lib/bandwidth_tn_order.rb +++ b/lib/bandwidth_tn_order.rb @@ -4,8 +4,6 @@ require "forwardable" require "ruby-bandwidth-iris" Faraday.default_adapter = :em_synchrony -require_relative "./catapult" - class BandwidthTNOrder def self.get(id) EMPromise.resolve(nil).then do @@ -77,32 +75,7 @@ class BandwidthTNOrder end def poll - catapult_import.then do |http| - raise "Catapult import failed" unless http.response_header.status == 201 - - self - end - end - - protected - - # After buying, import to catapult and set v1 voice app - def catapult_import - CATAPULT.import( - number: tel, - provider: dashboard_provider - ) - end - - def dashboard_provider - { - providerName: "bandwidth-dashboard", - properties: { - accountId: CONFIG[:creds][:account], - userName: CONFIG[:creds][:username], - password: CONFIG[:creds][:password] - } - } + EMPromise.resolve(self) end end diff --git a/lib/catapult.rb b/lib/catapult.rb deleted file mode 100644 index 4317ef176d1b68cf4ba0d2af0d2af3df37bf7f3f..0000000000000000000000000000000000000000 --- a/lib/catapult.rb +++ /dev/null @@ -1,99 +0,0 @@ -# frozen_string_literal: true - -require "value_semantics/monkey_patched" - -class Catapult - value_semantics do - user String - token String - secret String - application_id String - domain String - sip_host String - end - - def import(body) - post( - "phoneNumbers", - body: { applicationId: application_id }.merge(body) - ) - end - - def create_endpoint(body) - post( - "domains/#{@domain}/endpoints", - body: { applicationId: @application_id }.merge(body) - ).then do |http| - unless http.response_header.status == 201 - raise "Create new SIP account failed" - end - - http.response_header["location"] - end - end - - def endpoint_list(page=0) - get( - "domains/#{@domain}/endpoints", - query: { size: 1000, page: page } - ).then do |http| - next [] if http.response_header.status == 404 - raise "Could not list endpoints" if http.response_header.status != 200 - - JSON.parse(http.response) - end - end - - def endpoint_find(name, page=0) - endpoint_list(page).then do |list| - next if list.empty? - - if (found = list.find { |e| e["name"] == name }) - found.merge("url" => CATAPULT.mkurl( - "domains/#{found['domainId']}/endpoints/#{found['id']}" - )) - else - endpoint_find(name, page + 1) - end - end - end - - def post(path, body:, head: {}) - EM::HttpRequest.new( - mkurl(path), tls: { verify_peer: true } - ).apost( - head: catapult_headers.merge(head), - body: body.to_json - ) - end - - def delete(path, head: {}) - EM::HttpRequest.new( - mkurl(path), tls: { verify_peer: true } - ).adelete(head: catapult_headers.merge(head)) - end - - def get(path, head: {}, **kwargs) - EM::HttpRequest.new( - mkurl(path), tls: { verify_peer: true } - ).aget(head: catapult_headers.merge(head), **kwargs) - end - - def mkurl(path) - base = "https://api.catapult.inetwork.com/v1/users/#{@user}/" - return path if path.start_with?(base) - - "#{base}#{path}" - end - -protected - - def catapult_headers - { - "Authorization" => [@token, @secret], - "Content-Type" => "application/json" - } - end -end - -CATAPULT = Catapult.new(**CONFIG[:catapult]) diff --git a/test/data/catapult_import_body.json b/test/data/catapult_import_body.json deleted file mode 100644 index cda7e963e49384a2e57406f1e805203a00295426..0000000000000000000000000000000000000000 --- a/test/data/catapult_import_body.json +++ /dev/null @@ -1 +0,0 @@ -{"applicationId":"catapult_app","number":"+15555550000","provider":{"providerName":"bandwidth-dashboard","properties":{"accountId":"test_bw_account","userName":"test_bw_user","password":"test_bw_password"}}} diff --git a/test/test_bandwidth_tn_order.rb b/test/test_bandwidth_tn_order.rb index f3bd27c24619cba976ba632f77c97ba1cf8fdf35..da03a3b0b1f13f4115792b42cd4ec7199a32f96c 100644 --- a/test/test_bandwidth_tn_order.rb +++ b/test/test_bandwidth_tn_order.rb @@ -60,16 +60,6 @@ class BandwidthTNOrderTest < Minitest::Test RESPONSE - stub_request( - :post, - "https://api.catapult.inetwork.com/v1/users/catapult_user/phoneNumbers" - ).with( - body: File.open("#{__dir__}/data/catapult_import_body.json").read.chomp, - headers: { - "Authorization" => "Basic Y2F0YXB1bHRfdG9rZW46Y2F0YXB1bHRfc2VjcmV0", - "Content-Type" => "application/json" - } - ).to_return(status: 201) @order.poll.sync assert_requested req end @@ -86,18 +76,7 @@ class BandwidthTNOrderTest < Minitest::Test end def test_poll - req = stub_request( - :post, - "https://api.catapult.inetwork.com/v1/users/catapult_user/phoneNumbers" - ).with( - body: File.open("#{__dir__}/data/catapult_import_body.json").read.chomp, - headers: { - "Authorization" => "Basic Y2F0YXB1bHRfdG9rZW46Y2F0YXB1bHRfc2VjcmV0", - "Content-Type" => "application/json" - } - ).to_return(status: 201) assert_equal @order, @order.poll.sync - assert_requested req end em :test_poll end diff --git a/test/test_helper.rb b/test/test_helper.rb index 2a5ebd45aa55a1b583d10c6503d24fbd490040f3..3fda227d414caa2a0c8bc9aa2e8f351d931950ef 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -64,14 +64,6 @@ CONFIG = { username: "test_bw_user", password: "test_bw_password" }, - catapult: { - user: "catapult_user", - token: "catapult_token", - secret: "catapult_secret", - domain: "catapult_domain", - sip_host: "host.bwapp.io.example.com", - application_id: "catapult_app" - }, activation_amount: 1, plans: [ { diff --git a/test/test_registration.rb b/test/test_registration.rb index 8c7a5090c425ebc769b22832b2ee61710837c196..f76cb4dfb2bf92365aa6f210dead795d551680bb 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -689,16 +689,6 @@ class RegistrationTest < Minitest::Test RESPONSE - stub_request( - :post, - "https://api.catapult.inetwork.com/v1/users/catapult_user/phoneNumbers" - ).with( - body: File.open("#{__dir__}/data/catapult_import_body.json").read.chomp, - headers: { - "Authorization" => "Basic Y2F0YXB1bHRfdG9rZW46Y2F0YXB1bHRfc2VjcmV0", - "Content-Type" => "application/json" - } - ).to_return(status: 201) stub_request( :post, "https://dashboard.bandwidth.com/v1.0/accounts//sites//sippeers//movetns"