Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Sep 3, 2024
1 parent 0b73496 commit 14c3b0c
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 40 deletions.
3 changes: 3 additions & 0 deletions components/services/config/app_settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
default: &default
region_data: "<%= ENV.fetch('REGION_DATA', '{}') %>"
stub_regions: false

production: &production
<<: *default
Expand All @@ -9,6 +11,7 @@ staging:

development: &development
<<: *default
stub_regions: true

test:
<<: *development
5 changes: 4 additions & 1 deletion components/services/config/initializers/somleng_regions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require "json"

SomlengRegions.configure do |config|
config.region_data = ENV.fetch("REGION_DATA")
config.region_data = JSON.parse(AppSettings.fetch(:region_data))
config.stub_regions = AppSettings.fetch(:stub_regions)
end
21 changes: 18 additions & 3 deletions components/services/lib/somleng_regions.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
require_relative "somleng_regions/region"

module SomlengRegions
class << self
MOCK_REGIONS = [
Region.new(
identifier: "ap-southeast-1",
alias: "hydrogen",
group_id: 1,
human_name: "South East Asia (Singapore)"
),
Region.new(
identifier: "us-east-1",
alias: "helium",
group_id: 2,
human_name: "North America (Virginia, US)"
)
]

def configure
yield(configuration)
configuration
Expand All @@ -11,12 +28,10 @@ def configuration
alias config configuration

def regions
@regions ||= Collection.new(Parser.new.parse(configuration.region_data))
@regions ||= Collection.new(configuration.stub_regions ? MOCK_REGIONS : configuration.region_data.map { |region| Region.new(region) })
end
end
end

require_relative "somleng_regions/configuration"
require_relative "somleng_regions/parser"
require_relative "somleng_regions/collection"
require_relative "somleng_regions/region"
4 changes: 4 additions & 0 deletions components/services/lib/somleng_regions/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def initialize(regions)
@regions = regions
end

def all
regions

Check warning on line 12 in components/services/lib/somleng_regions/collection.rb

View check run for this annotation

Codecov / codecov/patch

components/services/lib/somleng_regions/collection.rb#L12

Added line #L12 was not covered by tests
end

def find_by(attributes)
regions.find do |region|
attributes.all? { |key, value| region[key] == value }
Expand Down
2 changes: 1 addition & 1 deletion components/services/lib/somleng_regions/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SomlengRegions
class Configuration
attr_accessor :region_data
attr_accessor :region_data, :stub_regions
end
end
7 changes: 0 additions & 7 deletions components/services/lib/somleng_regions/parser.rb

This file was deleted.

15 changes: 0 additions & 15 deletions components/services/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@
ENV["PUBLIC_GATEWAY_DB_NAME"] = "opensips_public_gateway_test"
ENV["CLIENT_GATEWAY_DB_NAME"] = "opensips_client_gateway_test"
ENV["MEDIA_PROXY_NG_PORT"] = "2223"
ENV["REGION_DATA"] = [
{
"alias" => "hydrogen",
"identifier" => "ap-southeast-1",
"human_name" => "Asia",
"group_id" => 1
},
{
"alias" => "helium",
"identifier" => "us-east-1",
"human_name" => "North America",
"group_id" => 2
}
].to_json


require_relative "../app"

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/modules/services/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "aws_iam_policy" "custom_policy" {
"${var.freeswitch_event_socket_password_parameter.arn}",
"${aws_ssm_parameter.application_master_key.arn}",
"${var.db_password_parameter.arn}",
"${var.region_data_parameter.arn}"
"${data.aws_ssm_parameter.region_data.arn}"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/modules/services/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ resource "aws_lambda_function" "this" {
MEDIA_PROXY_NG_PORT = var.media_proxy_ng_port
DB_PASSWORD_SSM_PARAMETER_NAME = var.db_password_parameter.name
APP_MASTER_KEY_SSM_PARAMETER_NAME = aws_ssm_parameter.application_master_key.name
REGION_DATA_SSM_PARAMETER_NAME = var.region_data_parameter.name
REGION_DATA_SSM_PARAMETER_NAME = data.aws_ssm_parameter.region_data.name
APP_ENV = var.app_environment
DB_HOST = var.db_host
DB_PORT = var.db_port
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/modules/services/ssm.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
data "aws_ssm_parameter" "region_data" {
name = "somleng.${var.app_environment}.region_data"
}

resource "aws_ssm_parameter" "application_master_key" {
name = "somleng-switch-services.${var.app_environment}.application_master_key"
type = "SecureString"
Expand Down
1 change: 0 additions & 1 deletion infrastructure/modules/services/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ variable "switch_group" {}
variable "media_proxy_group" {}
variable "client_gateway_group" {}
variable "db_password_parameter" {}
variable "region_data_parameter" {}
variable "freeswitch_event_socket_password_parameter" {}
variable "db_security_group" {}
variable "freeswitch_event_socket_port" {}
Expand Down
1 change: 0 additions & 1 deletion infrastructure/production/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module "services" {

db_password_parameter = data.terraform_remote_state.core_infrastructure.outputs.db_master_password_parameter
freeswitch_event_socket_password_parameter = data.aws_ssm_parameter.freeswitch_event_socket_password
region_data_parameter = data.aws_ssm_parameter.region_data

db_security_group = data.terraform_remote_state.core_infrastructure.outputs.db_security_group
db_username = data.terraform_remote_state.core_infrastructure.outputs.db_cluster.master_username
Expand Down
4 changes: 0 additions & 4 deletions infrastructure/production/ssm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ data "aws_ssm_parameter" "somleng_services_password" {
data "aws_ssm_parameter" "freeswitch_event_socket_password" {
name = "somleng-switch.production.freeswitch_event_socket_password"
}

data "aws_ssm_parameter" "region_data" {
name = "somleng.production.region_data"
}
1 change: 0 additions & 1 deletion infrastructure/staging/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module "services" {

db_password_parameter = data.terraform_remote_state.core_infrastructure.outputs.db_master_password_parameter
freeswitch_event_socket_password_parameter = data.aws_ssm_parameter.freeswitch_event_socket_password
region_data_parameter = data.aws_ssm_parameter.region_data

db_security_group = data.terraform_remote_state.core_infrastructure.outputs.db_security_group
db_username = data.terraform_remote_state.core_infrastructure.outputs.db_cluster.master_username
Expand Down
4 changes: 0 additions & 4 deletions infrastructure/staging/ssm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ data "aws_ssm_parameter" "somleng_services_password" {
data "aws_ssm_parameter" "freeswitch_event_socket_password" {
name = "somleng-switch.staging.freeswitch_event_socket_password"
}

data "aws_ssm_parameter" "region_data" {
name = "somleng.staging.region_data"
}

0 comments on commit 14c3b0c

Please sign in to comment.