Skip to content

Commit f9093a1

Browse files
Merge pull request #35 from godaddy/asherah_upgrade
Upgrade to use asherah-cobhan v0.4.30
2 parents 19f8b7f + 32505af commit f9093a1

File tree

9 files changed

+44
-21
lines changed

9 files changed

+44
-21
lines changed

CHANGELOG.md

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

3+
## [0.5.0] - 2023-10-16
4+
5+
- Upgrade to use asherah-cobhan v0.4.30
6+
- Expose `test-debug-static` kms type and `test-debug-memory` metastore type to skip warnings in tests
7+
- Check initialized flag on setup/shutdown and raise appropriate errors
8+
39
## [0.4.10] - 2023-08-10
410

511
- Upgrade to use asherah-cobhan v0.4.25

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Asherah.configure do |config|
4545
end
4646
```
4747

48+
See [config.rb](lib/asherah/config.rb) for all evailable configuration options.
49+
4850
Encrypt some data for a `partition_id`
4951

5052
```ruby

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.25
2-
libasherah-arm64.so: 573d4ac89dc54be952b428e4caa52f00861d67fdd94baf2deb0b37a1e40ea5d1
3-
libasherah-x64.so: 9a976b425edcaa27be84314414747c3d4abc22571c9ae8170f476822c2380716
4-
libasherah-arm64.dylib: 73f60860303af81de5f042d50ef755bbac34bae9f966d654036a259161e03f81
5-
libasherah-x64.dylib: a0e0c5c69278602cd19889df9b86795baf957cdaa4635c413c81d06b59572ec4
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

lib/asherah.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def set_env(env = {})
4444
# @yield [Config]
4545
# @return [void]
4646
def configure
47+
raise Asherah::Error::AlreadyInitialized if @initialized
48+
4749
config = Config.new
4850
yield config
4951
config.validate!
@@ -53,6 +55,7 @@ def configure
5355

5456
result = SetupJson(config_buffer)
5557
Error.check_result!(result, 'SetupJson failed')
58+
@initialized = true
5659
end
5760

5861
# Encrypts data for a given partition_id and returns DataRowRecord in JSON format.
@@ -104,7 +107,10 @@ def decrypt(partition_id, json)
104107

105108
# Stop the Asherah instance
106109
def shutdown
110+
raise Asherah::Error::NotInitialized unless @initialized
111+
107112
Shutdown()
113+
@initialized = false
108114
end
109115

110116
private

lib/asherah/config.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class Config
4343
verbose: :Verbose
4444
}.freeze
4545

46-
KMS_TYPES = ['static', 'aws'].freeze
47-
METASTORE_TYPES = ['rdbms', 'dynamodb', 'memory'].freeze
46+
KMS_TYPES = ['static', 'aws', 'test-debug-static'].freeze
47+
METASTORE_TYPES = ['rdbms', 'dynamodb', 'memory', 'test-debug-memory'].freeze
4848

4949
attr_accessor(*MAPPING.keys)
5050

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.4.10'
4+
VERSION = '0.5.0'
55
end

spec/asherah_spec.rb

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

@@ -48,14 +48,22 @@
4848
expect(Asherah.decrypt(partition_id, json)).to eq(data)
4949
end
5050

51-
it 'raises error when already configured' do
51+
it 'raises error on configure when already configured' do
5252
expect {
5353
Asherah.configure do |config|
5454
base_config.call(config)
5555
end
56-
}.to raise_error(Asherah::Error::AlreadyInitialized) do |e|
57-
expect(e.message).to eq('SetupJson failed (-101)')
58-
end
56+
}.to raise_error(Asherah::Error::AlreadyInitialized)
57+
end
58+
59+
it 'raises error on shutdown when not initialized' do
60+
Asherah.shutdown # Before each work-around
61+
62+
expect {
63+
Asherah.shutdown
64+
}.to raise_error(Asherah::Error::NotInitialized)
65+
66+
Asherah.configure { |config| base_config.call(config) } # After each work-around
5967
end
6068

6169
it 'can set environment variables' do

spec/config_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
config.kms = 'other'
5656
end
5757
}.to raise_error(Asherah::Error::ConfigError) do |e|
58-
expect(e.message).to eq('config.kms must be one of these: static, aws')
58+
expect(e.message).to eq('config.kms must be one of these: static, aws, test-debug-static')
5959
end
6060
end
6161
end
@@ -79,7 +79,7 @@
7979
config.metastore = 'other'
8080
end
8181
}.to raise_error(Asherah::Error::ConfigError) do |e|
82-
expect(e.message).to eq('config.metastore must be one of these: rdbms, dynamodb, memory')
82+
expect(e.message).to eq('config.metastore must be one of these: rdbms, dynamodb, memory, test-debug-memory')
8383
end
8484
end
8585
end

spec/kms_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
RSpec.describe 'Asherah KMS integration' do
44
let(:partition_id) { 'user_1' }
55

6-
after :each do
7-
Asherah.shutdown
8-
end
9-
106
it 'encrypts and decrypts using KMS' do
11-
kms_key_arn = ENV.fetch('KMS_KEY_ARN') { skip 'KMS_KEY_ARN env var is not set' }
7+
kms_key_arn = ENV.fetch('KMS_KEY_ARN') do
8+
@disable_shutdown = true
9+
skip 'KMS_KEY_ARN env var is not set'
10+
end
1211

1312
Asherah.configure do |config|
1413
config.service_name = 'gem'
@@ -23,5 +22,7 @@
2322
data = 'test'
2423
json = Asherah.encrypt(partition_id, data)
2524
expect(Asherah.decrypt(partition_id, json)).to eq(data)
25+
ensure
26+
Asherah.shutdown unless @disable_shutdown
2627
end
2728
end

0 commit comments

Comments
 (0)