spackle-ruby 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/spackle/stores/dynamodb.rb +54 -38
- data/spackle.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18048e2400b535e381a4cf3130d671c5489df5453834133fb2a577ad0a175cb1
|
4
|
+
data.tar.gz: 7c98ce5a2d61102e20d079e000002b3f2faa4704efdb39638dedf6f61d491d48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa08056244492c4697b5f36f43d2acd2c64c943a7597a36d2406115f6e0426ee9ebd3f823ddc75c4050f9bf671b56b4d8f17726fc0d9a1d60668ce20918ba2ba
|
7
|
+
data.tar.gz: 779445743a20139ac77fcc9e1b8022bd4ac2bf75350cb5feb7ada99c6d5d278459e507a9c27f51110b700e8d4b8844773ad9213fe770b20b6f1aa6a373d64216
|
@@ -6,30 +6,48 @@ require 'logger'
|
|
6
6
|
module Spackle
|
7
7
|
class DynamoDBStore < BaseStore
|
8
8
|
@client = nil
|
9
|
-
@
|
9
|
+
@credentials = nil
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@client = client || bootstrap_client
|
11
|
+
def initialize()
|
12
|
+
@client = bootstrap_client
|
14
13
|
end
|
15
14
|
|
16
15
|
def get_customer_data(id)
|
17
16
|
result = get_item(id)
|
18
17
|
|
19
18
|
if result.nil? or result.item.nil?
|
20
|
-
|
19
|
+
return fetch_state_from_api(id)
|
21
20
|
end
|
22
21
|
|
23
22
|
JSON.parse(result.item['State'])
|
24
23
|
end
|
25
24
|
|
25
|
+
def fetch_state_from_api(id)
|
26
|
+
Util.log_warn("Customer #{id} not found in DynamoDB. Fetching from API...")
|
27
|
+
uri = URI(Spackle.api_base + '/customers/' + id + '/state')
|
28
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
https.use_ssl = true
|
30
|
+
|
31
|
+
request = Net::HTTP::Get.new(uri.path)
|
32
|
+
request['Authorization'] = 'Bearer ' + Spackle.api_key
|
33
|
+
|
34
|
+
response = https.request(request)
|
35
|
+
if response.code != '200'
|
36
|
+
puts response.code
|
37
|
+
puts response.body
|
38
|
+
raise SpackleError.new "Customer #{id} not found"
|
39
|
+
end
|
40
|
+
|
41
|
+
JSON.parse(response.body)
|
42
|
+
end
|
43
|
+
|
26
44
|
private
|
27
45
|
|
28
46
|
def get_item(id)
|
29
47
|
return @client.get_item({
|
30
|
-
table_name: @
|
48
|
+
table_name: @credentials.session['adapter']['table_name'],
|
31
49
|
key: {
|
32
|
-
AccountId: @
|
50
|
+
AccountId: @credentials.session['adapter']['identity_id'],
|
33
51
|
CustomerId: "#{id}:#{Spackle.version}"
|
34
52
|
}
|
35
53
|
})
|
@@ -44,58 +62,56 @@ module Spackle
|
|
44
62
|
raise SpackleError.new 'API key not set'
|
45
63
|
end
|
46
64
|
|
47
|
-
|
48
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
49
|
-
https.use_ssl = true
|
50
|
-
|
51
|
-
request = Net::HTTP::Post.new(uri.path)
|
52
|
-
request['Authorization'] = 'Bearer ' + Spackle.api_key
|
53
|
-
|
54
|
-
response = https.request(request)
|
55
|
-
data = JSON.parse(response.body)
|
56
|
-
Util.log_debug("Created session: #{data}")
|
57
|
-
|
58
|
-
@store_config = data['adapter']
|
59
|
-
credentials = SpackleCredentials.new(
|
60
|
-
@store_config['role_arn'],
|
61
|
-
@store_config['token'],
|
62
|
-
@store_config['region'],
|
63
|
-
)
|
64
|
-
|
65
|
+
@credentials = SpackleAWSCredentials.new
|
65
66
|
Aws::DynamoDB::Client.new(
|
66
|
-
region: @
|
67
|
-
credentials: credentials,
|
67
|
+
region: @credentials.session['adapter']['region'],
|
68
|
+
credentials: @credentials,
|
68
69
|
)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
class
|
73
|
+
class SpackleAWSCredentials
|
73
74
|
include Aws::CredentialProvider
|
74
75
|
include Aws::RefreshingCredentials
|
75
76
|
|
76
|
-
@
|
77
|
-
@
|
78
|
-
@token = nil
|
77
|
+
@client = nil
|
78
|
+
@session = {}
|
79
79
|
|
80
|
-
def initialize(
|
81
|
-
@
|
82
|
-
@role_arn = role_arn
|
83
|
-
@token = token
|
80
|
+
def initialize()
|
81
|
+
@session = create_session
|
84
82
|
@client = Aws::STS::Client.new(
|
85
|
-
region: @region,
|
83
|
+
region: @session['adapter']['region'],
|
86
84
|
credentials: false,
|
87
85
|
)
|
88
86
|
super()
|
89
87
|
end
|
90
88
|
|
89
|
+
def session
|
90
|
+
@session
|
91
|
+
end
|
92
|
+
|
91
93
|
private
|
92
94
|
|
95
|
+
def create_session
|
96
|
+
uri = URI(Spackle.api_base + '/sessions')
|
97
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
98
|
+
https.use_ssl = true
|
99
|
+
|
100
|
+
request = Net::HTTP::Post.new(uri.path)
|
101
|
+
request['Authorization'] = 'Bearer ' + Spackle.api_key
|
102
|
+
|
103
|
+
response = https.request(request)
|
104
|
+
data = JSON.parse(response.body)
|
105
|
+
Util.log_debug("Created session: #{data}")
|
106
|
+
data
|
107
|
+
end
|
108
|
+
|
93
109
|
def refresh
|
94
110
|
Util.log_debug('Refreshing DynamoDB credentials...')
|
95
111
|
c = @client.assume_role_with_web_identity({
|
96
|
-
role_arn: @role_arn,
|
112
|
+
role_arn: @session['adapter']['role_arn'],
|
97
113
|
role_session_name: Base64.strict_encode64(SecureRandom.uuid),
|
98
|
-
web_identity_token: @token
|
114
|
+
web_identity_token: @session['adapter']['token'],
|
99
115
|
}).credentials
|
100
116
|
@credentials = Aws::Credentials.new(
|
101
117
|
c.access_key_id,
|
data/spackle.gemspec
CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "spackle-ruby"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.12"
|
6
6
|
s.summary = "Spackle Ruby gem"
|
7
7
|
s.description = "Spackle is the easiest way to integrate your Ruby app with Stripe Billing. " \
|
8
8
|
"See https://www.spackle.so for details."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spackle-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spackle
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -112,7 +112,7 @@ metadata:
|
|
112
112
|
github_repo: ssh://github.com/spackleso/spackle-ruby
|
113
113
|
homepage_uri: https://docs.spackle.so/ruby
|
114
114
|
source_code_uri: https://github.com/spackleso/spackle-ruby
|
115
|
-
post_install_message:
|
115
|
+
post_install_message:
|
116
116
|
rdoc_options: []
|
117
117
|
require_paths:
|
118
118
|
- lib
|
@@ -127,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
131
|
-
signing_key:
|
130
|
+
rubygems_version: 3.4.10
|
131
|
+
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Spackle Ruby gem
|
134
134
|
test_files: []
|