Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Sep 4, 2024
1 parent 9afc4ed commit edacf4b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
18 changes: 18 additions & 0 deletions components/services/app/jobs/update_opensips_permission_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class UpdateOpenSIPSPermissionJob
attr_reader :source_ip, :group_id

def initialize(source_ip, options = {})
@source_ip = source_ip
@group_id = options.fetch("group_id", 0)
end

def call
OpenSIPSAddress.where(ip: source_ip, database_connection:).update(grp: group_id)
end

private

def database_connection
DatabaseConnections.find(:public_gateway)
end
end
8 changes: 4 additions & 4 deletions components/services/app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ class ApplicationRecord
class << self
attr_accessor :table_name

def exists?(database_connection:, **query)
where(database_connection:, **query).count.positive?
def exists?(**)
where(**).count.positive?
end

def where(database_connection:, **query)
table(database_connection:).where(query)
def where(database_connection:, **)
table(database_connection:).where(**)
end

private
Expand Down
21 changes: 21 additions & 0 deletions components/services/spec/requests/sqs_message_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@
expect(address.count).to eq(0)
end

it "updates an address message", :public_gateway do
create_address(ip: "165.57.32.1", grp: 2)

payload = build_sqs_message_event_payload(
event_source_arn: "arn:aws:sqs:us-east-2:123456789012:somleng-switch-permissions",
body: {
"job_class" => "UpdateOpenSIPSPermissionJob",
"job_args" => [ "165.57.32.1", { "group_id" => 1 } ]
}.to_json
)

invoke_lambda(payload:)

result = address.all
expect(result.count).to eq(1)
expect(result[0]).to include(
ip: "165.57.32.1",
grp: 1
)
end

it "adds a subscriber record", :client_gateway do
payload = build_sqs_message_event_payload(
event_source_arn: "arn:aws:sqs:us-east-2:123456789012:somleng-switch-permissions",
Expand Down
4 changes: 2 additions & 2 deletions components/services/spec/support/factory_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def create_load_balancer_target(dst_uri:, resources:)
client_gateway_database_connection.table(:load_balancer).insert(dst_uri:, resources:)
end

def create_address(ip:)
public_gateway_database_connection.table(:address).insert(ip:)
def create_address(**)
public_gateway_database_connection.table(:address).insert(**)
end

def create_rtpengine_target(socket:)
Expand Down

0 comments on commit edacf4b

Please sign in to comment.