strongmind-platform-sdk 3.19.8 → 3.19.10
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/Gemfile.lock +1 -1
- data/README.md +19 -0
- data/lib/platform_sdk/active_record/data_pipelineable.rb +5 -1
- data/lib/platform_sdk/identity/clients.rb +9 -6
- data/lib/platform_sdk/spec_support/shared_examples/data_pipelineable_examples.rb +10 -7
- data/lib/platform_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10187a8eb94f16ef74713d4ebc7050e2b26dd3765fd0833f27aa9c9f2ffbe620
|
4
|
+
data.tar.gz: 29525b19fec16e6369fe505b2597be11a7a065392c09197c8f39c199aca70196
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2d1bd26b0775c4317629bb9429de29ab1838cff997e0a343e9c2229aa95442701ccb545f5c047ffce0cad2701ab5887c1692d95f21e26f6e0d8c9fc753c9606
|
7
|
+
data.tar.gz: 137bd7142f18e0350d2a6441d16f06b7ff9e2c0831b22d48e8def53efc57007955affee28d141e4236eaa4f5a6c8e4c50a8e5a39921082062fa98b6509dd78d6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -153,6 +153,25 @@ class MyModel < ApplicationRecord
|
|
153
153
|
end
|
154
154
|
```
|
155
155
|
|
156
|
+
You can override the following methods in the model to customize the noun data:
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
class MyModel < ApplicationRecord
|
160
|
+
include PlatformSdk::ActiveRecord::DataPipelineable
|
161
|
+
|
162
|
+
def pipeline_excluded_attributes
|
163
|
+
[:column1, :column2]
|
164
|
+
end
|
165
|
+
|
166
|
+
def pipeline_additional_attributes
|
167
|
+
{
|
168
|
+
"foo": "important data",
|
169
|
+
"bar": "more important data"
|
170
|
+
}
|
171
|
+
end
|
172
|
+
end
|
173
|
+
```
|
174
|
+
|
156
175
|
### Configuration
|
157
176
|
You will need the following ENV variables set in your application to send data to the Data Pipeline (found in bitwarden):
|
158
177
|
* DATA_PIPELINE_HOST
|
@@ -31,6 +31,10 @@ module PlatformSdk
|
|
31
31
|
raise NotImplementedError, 'You must implement the pipeline_meta class method, an example value is { "source": "strongmind-central" }'
|
32
32
|
end
|
33
33
|
|
34
|
+
def pipeline_excluded_attributes
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
|
34
38
|
def pipeline_identifiers
|
35
39
|
{
|
36
40
|
"id": id
|
@@ -42,7 +46,7 @@ module PlatformSdk
|
|
42
46
|
|
43
47
|
data_hash.merge!(pipeline_additional_attributes)
|
44
48
|
|
45
|
-
data_hash
|
49
|
+
data_hash.except(*pipeline_excluded_attributes)
|
46
50
|
end
|
47
51
|
|
48
52
|
def pipeline_additional_attributes
|
@@ -8,7 +8,7 @@ module PlatformSdk
|
|
8
8
|
@auth = auth_client.nil? ? AuthClient.new(identity_base_url, client_id, client_secret) : auth_client
|
9
9
|
|
10
10
|
@conn = Faraday.new(identity_base_url) do |conn|
|
11
|
-
conn.request :authorization,
|
11
|
+
conn.request :authorization, 'Bearer', -> { @auth.auth_token }
|
12
12
|
conn.request :retry
|
13
13
|
conn.response :json
|
14
14
|
conn.adapter :net_http
|
@@ -50,12 +50,15 @@ module PlatformSdk
|
|
50
50
|
def post_payload(path, body)
|
51
51
|
with_rescue do
|
52
52
|
response = @conn.post(path, body)
|
53
|
-
response.body
|
53
|
+
response_body = response.body
|
54
|
+
return if response_body == ''
|
55
|
+
|
56
|
+
response_body.transform_keys!(&:to_sym)
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
60
|
def auth_token
|
58
|
-
@token = post_payload(
|
61
|
+
@token = post_payload('/connect/token', request_body) if expired?
|
59
62
|
|
60
63
|
@token[:access_token]
|
61
64
|
end
|
@@ -76,7 +79,7 @@ module PlatformSdk
|
|
76
79
|
end
|
77
80
|
|
78
81
|
def jwt_expiry_time(jwt)
|
79
|
-
Time.at(JWT.decode(jwt, nil, false)[0][
|
82
|
+
Time.at(JWT.decode(jwt, nil, false)[0]['exp'])
|
80
83
|
end
|
81
84
|
|
82
85
|
def refresh_session(session: {})
|
@@ -101,7 +104,7 @@ module PlatformSdk
|
|
101
104
|
def new_refresh_token(refresh_token)
|
102
105
|
raise ArgumentError if refresh_token.nil?
|
103
106
|
|
104
|
-
post_payload(
|
107
|
+
post_payload('/connect/token', request_body(grant_type: 'refresh_token', refresh_token:))
|
105
108
|
end
|
106
109
|
|
107
110
|
def raise_error_with_payload(exception_class, error)
|
@@ -117,7 +120,7 @@ module PlatformSdk
|
|
117
120
|
|
118
121
|
private
|
119
122
|
|
120
|
-
def request_body(grant_type:
|
123
|
+
def request_body(grant_type: 'client_credentials', refresh_token: nil)
|
121
124
|
return { grant_type:, client_id: @client_id, client_secret: @client_secret } if refresh_token.nil?
|
122
125
|
|
123
126
|
{ grant_type:, client_id: @client_id, client_secret: @client_secret, refresh_token: }
|
@@ -1,21 +1,24 @@
|
|
1
1
|
module PlatformSdk
|
2
2
|
module SpecSupport
|
3
|
-
RSpec.shared_examples "DataPipelineable" do
|
3
|
+
RSpec.shared_examples "DataPipelineable" do
|
4
|
+
let(:data) do
|
5
|
+
{ action: }
|
6
|
+
.merge(record.attributes.symbolize_keys)
|
7
|
+
.merge(record.pipeline_additional_attributes)
|
8
|
+
.except(*record.pipeline_excluded_attributes)
|
9
|
+
end
|
10
|
+
|
4
11
|
let(:pipeline_payload) do
|
5
12
|
{
|
6
13
|
"noun": described_class.pipeline_noun,
|
7
14
|
"identifiers": { "id": record.id },
|
8
15
|
"meta": described_class.pipeline_meta,
|
9
|
-
"data": data
|
16
|
+
"data": data,
|
10
17
|
"envelope_version": '1.0.0',
|
11
18
|
"message_timestamp": Time.current.utc.iso8601
|
12
19
|
}
|
13
20
|
end
|
14
|
-
|
15
|
-
{
|
16
|
-
action:
|
17
|
-
}.merge!(record.attributes.symbolize_keys)
|
18
|
-
end
|
21
|
+
|
19
22
|
let(:record) { build(described_class.to_s.underscore.to_sym) }
|
20
23
|
let(:data_pipeline_client) { double(PlatformSdk::DataPipeline::Client)}
|
21
24
|
|
data/lib/platform_sdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strongmind-platform-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.19.
|
4
|
+
version: 3.19.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|