certmeister-dynamodb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/certmeister/dynamodb/store.rb +80 -0
- data/lib/certmeister/dynamodb/version.rb +9 -0
- data/spec/certmeister/dynamodb/store_spec.rb +48 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f1d8d1d810d0e325a9ed43a1a2ca2a91b656f2e
|
4
|
+
data.tar.gz: 4478b3e3c1ace15a6b5d4dca8f8e9406360b7548
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24211e9823b94aefc0207946de3d80d3b913c34e2ceb60bed9d8da40e6b6ccda34c5c3c422e1210a871c968fcc2b324269c2d49261ba2c750d317bf0e9eb766b
|
7
|
+
data.tar.gz: 5fe1c4ca7f44e91b7b711b88f7086f77c12a319244227845456f96ba374be322b51249ee507ee2a1d07e735b35b30bc1d3989b2c255840150970a88f1843e0ee
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'aws-sdk-core'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module Certmeister
|
5
|
+
|
6
|
+
module DynamoDB
|
7
|
+
|
8
|
+
class Store
|
9
|
+
|
10
|
+
def initialize(table_name, options = {}, provision = {})
|
11
|
+
@table_name = table_name
|
12
|
+
@db = Aws::DynamoDB::Client.new(options)
|
13
|
+
if !provision.empty?
|
14
|
+
do_provisioning(provision)
|
15
|
+
end
|
16
|
+
@healthy = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def store(cn, pem)
|
20
|
+
now = Time.now
|
21
|
+
@db.put_item(table_name: @table_name, item: {cn: cn, pem: pem})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch(cn)
|
25
|
+
if item = @db.get_item(table_name: @table_name, key: {cn: cn}).item
|
26
|
+
item["pem"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove(cn)
|
31
|
+
deleted = @db.delete_item(table_name: @table_name, key: {cn: cn}, return_values: "ALL_OLD").attributes
|
32
|
+
!!deleted
|
33
|
+
end
|
34
|
+
|
35
|
+
def health_check
|
36
|
+
@healthy
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def break!
|
42
|
+
@healthy = false
|
43
|
+
end
|
44
|
+
|
45
|
+
def do_provisioning(provisioned_throughput)
|
46
|
+
begin
|
47
|
+
@db.create_table(
|
48
|
+
table_name: @table_name,
|
49
|
+
attribute_definitions: [
|
50
|
+
{
|
51
|
+
attribute_name: "cn",
|
52
|
+
attribute_type: "S",
|
53
|
+
}
|
54
|
+
],
|
55
|
+
key_schema: [
|
56
|
+
{
|
57
|
+
attribute_name: "cn",
|
58
|
+
key_type: "HASH",
|
59
|
+
}
|
60
|
+
],
|
61
|
+
provisioned_throughput: provisioned_throughput,
|
62
|
+
# {
|
63
|
+
# read_capacity_units: 10,
|
64
|
+
# write_capacity_units: 5
|
65
|
+
# }
|
66
|
+
)
|
67
|
+
while @db.describe_table(table_name: @table_name).table.table_status == "CREATING"
|
68
|
+
$stderr.puts "Waiting for table #{table_name} to be created"
|
69
|
+
sleep 1
|
70
|
+
end
|
71
|
+
rescue Aws::DynamoDB::Errors::ResourceInUseException
|
72
|
+
# Already exists
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'certmeister/test/memory_store_interface'
|
3
|
+
|
4
|
+
require 'certmeister/dynamodb/store'
|
5
|
+
|
6
|
+
describe Certmeister::DynamoDB::Store do
|
7
|
+
|
8
|
+
TABLE_NAME = "CertmeisterCertificatesTest"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
include Certmeister::Test::MemoryStoreInterface
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
Certmeister::DynamoDB::Store.new(
|
16
|
+
TABLE_NAME,
|
17
|
+
{region: 'us-east-1', endpoint: ENV['DYNAMODB_ENDPOINT'] || 'http://localhost:8000' },
|
18
|
+
{read_capacity_units: 10, write_capacity_units: 5}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
it_behaves_like_a_certmeister_store
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def dynamodb_cleanup
|
27
|
+
ddb_options = {region: 'us-east-1', endpoint: ENV['DYNAMODB_ENDPOINT'] || 'http://localhost:8000'}
|
28
|
+
db = Aws::DynamoDB::Client.new(ddb_options)
|
29
|
+
begin
|
30
|
+
db.delete_table(table_name: TABLE_NAME)
|
31
|
+
while db.describe_table(table_name: TABLE_NAME).table.table_status == "DELETING"
|
32
|
+
$stderr.puts "Waiting for table #{TABLE_NAME} to be deleted"
|
33
|
+
sleep 1
|
34
|
+
end
|
35
|
+
rescue Aws::DynamoDB::Errors::ResourceNotFoundException
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
dynamodb_cleanup
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:each) do
|
44
|
+
dynamodb_cleanup
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: certmeister-dynamodb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sheldon Hearn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: certmeister
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
description: This gem provides a DynamoDB store for use in certmeister, the conditional
|
84
|
+
autosigning certificate authority.
|
85
|
+
email:
|
86
|
+
- sheldonh@starjuice.net
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- lib/certmeister/dynamodb/store.rb
|
92
|
+
- lib/certmeister/dynamodb/version.rb
|
93
|
+
- spec/certmeister/dynamodb/store_spec.rb
|
94
|
+
homepage: https://github.com/sheldonh/certmeister-dynamodb
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.4.5
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: DynamoDB store for certmeister
|
118
|
+
test_files:
|
119
|
+
- spec/certmeister/dynamodb/store_spec.rb
|