Skip to content

Commit 0f687cc

Browse files
authored
Merge pull request #36 from godaddy/postgres
Add sql_metastore_db_type config option to support PostgresSQL
2 parents f9093a1 + 0f0b58b commit 0f687cc

File tree

5 files changed

+88
-27
lines changed

5 files changed

+88
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## [Unreleased]
22

3+
## [0.5.1] - 2023-10-25
4+
5+
- Add `sql_metastore_db_type` config option to support PostgresSQL adapter for Asherah
6+
- Upgrade to use asherah-cobhan v0.4.31
7+
38
## [0.5.0] - 2023-10-16
49

510
- Upgrade to use asherah-cobhan v0.4.30

ext/asherah/checksums.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
version: v0.4.30
2-
libasherah-arm64.so: cb0985cd8f5d2c2ceac0e874e3f5b1276a9b2145c6274f9c7ccf80ddd7a5f469
3-
libasherah-x64.so: a91d0703a569941a38c3fdd6c1320904b47e3592fa9b9164f43704e5f4a1dda9
4-
libasherah-arm64.dylib: 8bac6d3a2a255553e7d1460f9e56a81d4ee7055e7f44f8f1a65cb6d584eabf6e
5-
libasherah-x64.dylib: b264dc01ac6ac4ae6ae9dad8cab1f69ed887cca3e4ea0798ea572b444578e2c8
1+
version: v0.4.31
2+
libasherah-arm64.so: 5fef00afadf6557a41c4c1a6f7e6fc29670898f6b530c7f7bce7b4a2b128bec8
3+
libasherah-x64.so: 1ccf9dae397b4e375715e0260455108838d7f9fc85768875aeb0cfda826768c6
4+
libasherah-arm64.dylib: 48ed5d7e992383910c78f5e1933d6aa42bb551b26e959d4c27d41627b6a10132
5+
libasherah-x64.dylib: 18183fb5fb56423a5a61b162d14316c88a5f8e2b63ac004b686a29825a8f1045

lib/asherah/config.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Asherah
99
# @attr [String] metastore, The type of metastore for persisting keys (rdbms, dynamodb, memory)
1010
# @attr [String] connection_string, The database connection string (required when metastore is rdbms)
1111
# @attr [String] replica_read_consistency, For Aurora sessions using write forwarding (eventual, global, session)
12+
# @attr [String] sql_metastore_db_type, Which SQL driver to use (mysql, postgres, oracle), defaults to mysql
1213
# @attr [String] dynamo_db_endpoint, An optional endpoint URL (for dynamodb metastore)
1314
# @attr [String] dynamo_db_region, The AWS region for DynamoDB requests (for dynamodb metastore)
1415
# @attr [String] dynamo_db_table_name, The table name for DynamoDB (for dynamodb metastore)
@@ -29,6 +30,7 @@ class Config
2930
metastore: :Metastore,
3031
connection_string: :ConnectionString,
3132
replica_read_consistency: :ReplicaReadConsistency,
33+
sql_metastore_db_type: :SQLMetastoreDBType,
3234
dynamo_db_endpoint: :DynamoDBEndpoint,
3335
dynamo_db_region: :DynamoDBRegion,
3436
dynamo_db_table_name: :DynamoDBTableName,
@@ -45,6 +47,7 @@ class Config
4547

4648
KMS_TYPES = ['static', 'aws', 'test-debug-static'].freeze
4749
METASTORE_TYPES = ['rdbms', 'dynamodb', 'memory', 'test-debug-memory'].freeze
50+
SQL_METASTORE_DB_TYPES = ['mysql', 'postgres', 'oracle'].freeze
4851

4952
attr_accessor(*MAPPING.keys)
5053

@@ -53,6 +56,7 @@ def validate!
5356
validate_product_id
5457
validate_kms
5558
validate_metastore
59+
validate_sql_metastore_db_type
5660
validate_kms_attributes
5761
end
5862

@@ -91,6 +95,15 @@ def validate_metastore
9195
end
9296
end
9397

98+
def validate_sql_metastore_db_type
99+
return if sql_metastore_db_type.nil?
100+
101+
unless SQL_METASTORE_DB_TYPES.include?(sql_metastore_db_type)
102+
raise Error::ConfigError,
103+
"config.sql_metastore_db_type must be one of these: #{SQL_METASTORE_DB_TYPES.join(', ')}"
104+
end
105+
end
106+
94107
def validate_kms_attributes
95108
if kms == 'aws'
96109
raise Error::ConfigError, 'config.region_map not set' if region_map.nil?

lib/asherah/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Asherah
4-
VERSION = '0.5.0'
4+
VERSION = '0.5.1'
55
end

spec/config_spec.rb

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
lambda do |config|
66
config.service_name = 'gem'
77
config.product_id = 'sable'
8-
config.kms = 'static'
9-
config.metastore = 'memory'
8+
config.kms = 'test-debug-static'
9+
config.metastore = 'test-debug-memory'
1010
end
1111
}
1212

@@ -37,6 +37,16 @@
3737
end
3838

3939
describe '#validate_kms' do
40+
it 'accepts valid sql_metastore_db_type value' do
41+
expect {
42+
Asherah.configure do |config|
43+
base_config.call(config)
44+
config.kms = 'test-debug-static'
45+
end
46+
}.not_to raise_error
47+
Asherah.shutdown
48+
end
49+
4050
it 'raises an error when kms not set' do
4151
expect {
4252
Asherah.configure do |config|
@@ -60,63 +70,96 @@
6070
end
6171
end
6272

63-
describe '#validate_metastore' do
64-
it 'raises an error when metastore not set' do
73+
describe '#validate_kms_attributes' do
74+
it 'raises an error when region_map not set' do
6575
expect {
6676
Asherah.configure do |config|
6777
base_config.call(config)
68-
config.metastore = nil
78+
config.kms = 'aws'
6979
end
7080
}.to raise_error(Asherah::Error::ConfigError) do |e|
71-
expect(e.message).to eq('config.metastore not set')
81+
expect(e.message).to eq('config.region_map not set')
7282
end
7383
end
7484

75-
it 'raises an error when metastore is invalid' do
85+
it 'raises an error when preferred_region is not a hash' do
7686
expect {
7787
Asherah.configure do |config|
7888
base_config.call(config)
79-
config.metastore = 'other'
89+
config.kms = 'aws'
90+
config.region_map = 'us-west-2=arn'
8091
end
8192
}.to raise_error(Asherah::Error::ConfigError) do |e|
82-
expect(e.message).to eq('config.metastore must be one of these: rdbms, dynamodb, memory, test-debug-memory')
93+
expect(e.message).to eq('config.region_map must be a Hash')
8394
end
8495
end
85-
end
8696

87-
describe '#validate_kms_attributes' do
88-
it 'raises an error when region_map not set' do
97+
it 'raises an error when preferred_region not set' do
8998
expect {
9099
Asherah.configure do |config|
91100
base_config.call(config)
92101
config.kms = 'aws'
102+
config.region_map = { 'us-west-2' => 'arn' }
93103
end
94104
}.to raise_error(Asherah::Error::ConfigError) do |e|
95-
expect(e.message).to eq('config.region_map not set')
105+
expect(e.message).to eq('config.preferred_region not set')
96106
end
97107
end
108+
end
98109

99-
it 'raises an error when preferred_region is not a hash' do
110+
describe '#validate_metastore' do
111+
it 'accepts valid metastore value' do
100112
expect {
101113
Asherah.configure do |config|
102114
base_config.call(config)
103-
config.kms = 'aws'
104-
config.region_map = 'us-west-2=arn'
115+
config.metastore = 'test-debug-memory'
116+
end
117+
}.not_to raise_error
118+
Asherah.shutdown
119+
end
120+
121+
it 'raises an error when metastore not set' do
122+
expect {
123+
Asherah.configure do |config|
124+
base_config.call(config)
125+
config.metastore = nil
105126
end
106127
}.to raise_error(Asherah::Error::ConfigError) do |e|
107-
expect(e.message).to eq('config.region_map must be a Hash')
128+
expect(e.message).to eq('config.metastore not set')
108129
end
109130
end
110131

111-
it 'raises an error when preferred_region not set' do
132+
it 'raises an error when metastore is invalid' do
112133
expect {
113134
Asherah.configure do |config|
114135
base_config.call(config)
115-
config.kms = 'aws'
116-
config.region_map = { 'us-west-2' => 'arn' }
136+
config.metastore = 'other'
117137
end
118138
}.to raise_error(Asherah::Error::ConfigError) do |e|
119-
expect(e.message).to eq('config.preferred_region not set')
139+
expect(e.message).to eq('config.metastore must be one of these: rdbms, dynamodb, memory, test-debug-memory')
140+
end
141+
end
142+
end
143+
144+
describe '#validate_sql_metastore_db_type' do
145+
it 'accepts valid sql_metastore_db_type value' do
146+
expect {
147+
Asherah.configure do |config|
148+
base_config.call(config)
149+
config.sql_metastore_db_type = 'postgres'
150+
end
151+
}.not_to raise_error
152+
Asherah.shutdown
153+
end
154+
155+
it 'raises an error when sql_metastore_db_type is invalid' do
156+
expect {
157+
Asherah.configure do |config|
158+
base_config.call(config)
159+
config.sql_metastore_db_type = 'other'
160+
end
161+
}.to raise_error(Asherah::Error::ConfigError) do |e|
162+
expect(e.message).to eq('config.sql_metastore_db_type must be one of these: mysql, postgres, oracle')
120163
end
121164
end
122165
end

0 commit comments

Comments
 (0)