cyclone_lariat 0.3.8 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +5 -5
- data/README.md +14 -0
- data/lib/cyclone_lariat/abstract/client.rb +21 -9
- data/lib/cyclone_lariat/configure.rb +15 -0
- data/lib/cyclone_lariat/errors.rb +0 -4
- data/lib/cyclone_lariat/sns_client.rb +7 -21
- data/lib/cyclone_lariat/sqs_client.rb +0 -2
- data/lib/cyclone_lariat/version.rb +1 -1
- data/lib/cyclone_lariat.rb +1 -0
- metadata +3 -3
- data/lib/cyclone_lariat/list_topics_store.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8b83a45f403749ab3ab2503f22e85af53cce8fc3267a63eb31df0246d30683
|
4
|
+
data.tar.gz: 31ed6ee400d6778d90adf90ef997cc577df5564b78238cdc36b8067ff9fcaff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73b11ffa6189231a1ebd71dcb7db455fbc092aaa00e740b4b1092006dd4db38550ddbb94ccc0266dc1bf4f467d481110a92061344fb1a6fa22e92ef48995b4b
|
7
|
+
data.tar.gz: d06087c237bbc3946c7e91772a987edf47b787ccd0f8e1c6e0f341f32fa6c7965b1546dcc7e188967baafaac19dd140ddca0d1cdbafb82ce68ab736d965271ef
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.3.10] - 2022-10-05
|
8
|
+
Added
|
9
|
+
- Added aws_client_od options
|
10
|
+
Changed:
|
11
|
+
- Renamed all AWS options with prefix _aws
|
12
|
+
|
13
|
+
## [0.3.9] - 2022-10-05 Depricated
|
14
|
+
Added
|
15
|
+
- Added configuration options see README.md
|
16
|
+
|
17
|
+
## [0.3.8] - 2022-09-05
|
18
|
+
Added
|
19
|
+
- Added configuration options see README.md
|
20
|
+
|
7
21
|
## [0.3.8] - 2022-09-05
|
8
22
|
Changed
|
9
23
|
- Added pagination to sns topics list for receiving all topics
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cyclone_lariat (0.3.
|
4
|
+
cyclone_lariat (0.3.10)
|
5
5
|
aws-sdk-sns
|
6
6
|
aws-sdk-sqs
|
7
7
|
luna_park (~> 0.11)
|
@@ -13,19 +13,19 @@ GEM
|
|
13
13
|
public_suffix (>= 2.0.2, < 5.0)
|
14
14
|
ast (2.4.2)
|
15
15
|
aws-eventstream (1.2.0)
|
16
|
-
aws-partitions (1.
|
17
|
-
aws-sdk-core (3.
|
16
|
+
aws-partitions (1.641.0)
|
17
|
+
aws-sdk-core (3.158.0)
|
18
18
|
aws-eventstream (~> 1, >= 1.0.2)
|
19
19
|
aws-partitions (~> 1, >= 1.525.0)
|
20
20
|
aws-sigv4 (~> 1.1)
|
21
21
|
jmespath (~> 1, >= 1.6.1)
|
22
|
-
aws-sdk-sns (1.
|
22
|
+
aws-sdk-sns (1.55.0)
|
23
23
|
aws-sdk-core (~> 3, >= 3.127.0)
|
24
24
|
aws-sigv4 (~> 1.1)
|
25
25
|
aws-sdk-sqs (1.51.1)
|
26
26
|
aws-sdk-core (~> 3, >= 3.127.0)
|
27
27
|
aws-sigv4 (~> 1.1)
|
28
|
-
aws-sigv4 (1.5.
|
28
|
+
aws-sigv4 (1.5.2)
|
29
29
|
aws-eventstream (~> 1, >= 1.0.2)
|
30
30
|
byebug (11.1.3)
|
31
31
|
coderay (1.1.3)
|
data/README.md
CHANGED
@@ -34,6 +34,20 @@ name where the change took place plus the verb past-participle. An event happens
|
|
34
34
|
A command can emit any number of events. The sender of the event does not care who receives it or whether it has been
|
35
35
|
received at all.
|
36
36
|
|
37
|
+
## Configure
|
38
|
+
```ruby
|
39
|
+
# 'config/initializers/cyclone_lariat.rb'
|
40
|
+
CycloneLariat.tap do |cl|
|
41
|
+
cl.default_version = 1 # api version default is 1
|
42
|
+
cl.aws_key = # aws key
|
43
|
+
cl.aws_secret_key = # aws secret
|
44
|
+
cl.aws_client_id = # aws client id
|
45
|
+
cl.aws_default_region = # aws default region
|
46
|
+
cl.publisher = 'auth' # name of your publishers, usually name of your application
|
47
|
+
cl.default_instance = APP_INSTANCE # stage, production, test
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
37
51
|
## SnsClient
|
38
52
|
You can use client directly
|
39
53
|
|
@@ -14,16 +14,14 @@ module CycloneLariat
|
|
14
14
|
dependency(:aws_client_class) { raise ArgumentError, 'Client class should be defined' }
|
15
15
|
dependency(:aws_credentials_class) { Aws::Credentials }
|
16
16
|
|
17
|
-
|
18
|
-
DEFAULT_INSTANCE = :prod
|
19
|
-
|
20
|
-
def initialize(key:, secret_key:, region:, version: nil, publisher: nil, instance: nil)
|
17
|
+
def initialize(key: nil, secret_key: nil, region: nil, version: nil, publisher: nil, instance: nil, client_id: nil)
|
21
18
|
@key = key
|
22
19
|
@secret_key = secret_key
|
23
20
|
@region = region
|
24
21
|
@version = version
|
25
22
|
@publisher = publisher
|
26
23
|
@instance = instance
|
24
|
+
@client_id = client_id
|
27
25
|
end
|
28
26
|
|
29
27
|
def event(type, data: {}, version: self.version, uuid: SecureRandom.uuid)
|
@@ -54,15 +52,15 @@ module CycloneLariat
|
|
54
52
|
|
55
53
|
class << self
|
56
54
|
def version(version = nil)
|
57
|
-
version.nil? ? @version ||
|
55
|
+
version.nil? ? @version || CycloneLariat.default_version : @version = version
|
58
56
|
end
|
59
57
|
|
60
58
|
def instance(instance = nil)
|
61
|
-
instance.nil? ? @instance ||
|
59
|
+
instance.nil? ? @instance || CycloneLariat.default_instance || (raise 'You should define instance') : @instance = instance
|
62
60
|
end
|
63
61
|
|
64
62
|
def publisher(publisher = nil)
|
65
|
-
publisher.nil? ? @publisher || (raise 'You should define publisher') : @publisher = publisher
|
63
|
+
publisher.nil? ? @publisher || CycloneLariat.publisher || (raise 'You should define publisher') : @publisher = publisher
|
66
64
|
end
|
67
65
|
end
|
68
66
|
|
@@ -78,9 +76,23 @@ module CycloneLariat
|
|
78
76
|
@instance ||= self.class.instance
|
79
77
|
end
|
80
78
|
|
81
|
-
|
79
|
+
def key
|
80
|
+
@key ||= CycloneLariat.aws_key
|
81
|
+
end
|
82
|
+
|
83
|
+
def secret_key
|
84
|
+
@secret_key ||= CycloneLariat.aws_secret_key
|
85
|
+
end
|
82
86
|
|
83
|
-
|
87
|
+
def region
|
88
|
+
@region ||= CycloneLariat.aws_default_region
|
89
|
+
end
|
90
|
+
|
91
|
+
def client_id
|
92
|
+
@client_id ||= CycloneLariat.aws_client_id
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
84
96
|
|
85
97
|
def aws_client
|
86
98
|
@aws_client ||= aws_client_class.new(credentials: aws_credentials, region: region)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CycloneLariat
|
4
|
+
class << self
|
5
|
+
DEFAULT_VERSION = 1
|
6
|
+
|
7
|
+
attr_accessor :aws_key, :aws_secret_key, :publisher, :aws_default_region, :default_instance,
|
8
|
+
:aws_client_id
|
9
|
+
attr_writer :default_version
|
10
|
+
|
11
|
+
def default_version
|
12
|
+
@default_version ||= DEFAULT_VERSION
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -9,10 +9,6 @@ module CycloneLariat
|
|
9
9
|
message 'Received message is empty'
|
10
10
|
end
|
11
11
|
|
12
|
-
class TopicNotFound < LunaPark::Errors::System
|
13
|
-
message { |d| "Could not found topic: `#{d[:expected_topic]}`" }
|
14
|
-
end
|
15
|
-
|
16
12
|
class ClientError < LunaPark::Errors::Business
|
17
13
|
attr_writer :message, :details
|
18
14
|
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'aws-sdk-sns'
|
4
4
|
require_relative 'abstract/client'
|
5
|
-
require_relative 'list_topics_store'
|
6
5
|
|
7
6
|
module CycloneLariat
|
8
7
|
class SnsClient < Abstract::Client
|
@@ -13,12 +12,9 @@ module CycloneLariat
|
|
13
12
|
SNS_SUFFIX = :fanout
|
14
13
|
|
15
14
|
def publish(msg, topic: nil)
|
16
|
-
topic ||=
|
17
|
-
|
18
|
-
aws_client.publish(
|
19
|
-
topic_arn: topic_arn(topic),
|
20
|
-
message: msg.to_json
|
21
|
-
)
|
15
|
+
topic ||= get_topic(msg.kind, msg.type)
|
16
|
+
arn = get_arn(topic)
|
17
|
+
aws_client.publish(topic_arn: arn, message: msg.to_json)
|
22
18
|
end
|
23
19
|
|
24
20
|
def publish_event(type, data: {}, version: self.version, uuid: SecureRandom.uuid, topic: nil)
|
@@ -31,22 +27,12 @@ module CycloneLariat
|
|
31
27
|
|
32
28
|
private
|
33
29
|
|
34
|
-
def
|
35
|
-
|
36
|
-
topic_arn = topics_store.topic_arn(topic_name)
|
37
|
-
|
38
|
-
if topic_arn.nil?
|
39
|
-
raise Errors::TopicNotFound.new(
|
40
|
-
expected_topic: topic_name,
|
41
|
-
existed_topics: topics_store.list
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
topic_arn
|
30
|
+
def get_arn(topic)
|
31
|
+
['arn', 'aws', 'sns', region, client_id, topic].join ':'
|
46
32
|
end
|
47
33
|
|
48
|
-
def
|
49
|
-
|
34
|
+
def get_topic(kind, type)
|
35
|
+
[instance, kind, SNS_SUFFIX, publisher, type].join '-'
|
50
36
|
end
|
51
37
|
end
|
52
38
|
end
|
@@ -34,8 +34,6 @@ module CycloneLariat
|
|
34
34
|
|
35
35
|
def url(topic_name)
|
36
36
|
aws_client.get_queue_url(queue_name: topic_name).queue_url
|
37
|
-
rescue Aws::SQS::Errors::NonExistentQueue => _e
|
38
|
-
raise Errors::TopicNotFound.new(expected_topic: topic_name, existed_topics: aws_client.list_queues)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
data/lib/cyclone_lariat.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyclone_lariat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kudrin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-10-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk-sns
|
@@ -269,9 +269,9 @@ files:
|
|
269
269
|
- lib/cyclone_lariat/abstract/client.rb
|
270
270
|
- lib/cyclone_lariat/abstract/message.rb
|
271
271
|
- lib/cyclone_lariat/command.rb
|
272
|
+
- lib/cyclone_lariat/configure.rb
|
272
273
|
- lib/cyclone_lariat/errors.rb
|
273
274
|
- lib/cyclone_lariat/event.rb
|
274
|
-
- lib/cyclone_lariat/list_topics_store.rb
|
275
275
|
- lib/cyclone_lariat/messages_mapper.rb
|
276
276
|
- lib/cyclone_lariat/messages_repo.rb
|
277
277
|
- lib/cyclone_lariat/middleware.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'singleton'
|
4
|
-
|
5
|
-
module CycloneLariat
|
6
|
-
class ListTopicsStore
|
7
|
-
include Singleton
|
8
|
-
|
9
|
-
def topic_arn(topic_name)
|
10
|
-
@topics[topic_name.to_sym]
|
11
|
-
end
|
12
|
-
|
13
|
-
def list
|
14
|
-
@topics.keys
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_topics(aws_client)
|
18
|
-
@topics ||= {}
|
19
|
-
@aws_client = aws_client
|
20
|
-
fetch
|
21
|
-
end
|
22
|
-
|
23
|
-
def clear_store!
|
24
|
-
@topics = {}
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def fetch
|
30
|
-
return unless @topics.empty?
|
31
|
-
|
32
|
-
@next_token = ''
|
33
|
-
topics_from_aws until @next_token.nil?
|
34
|
-
end
|
35
|
-
|
36
|
-
def topics_from_aws
|
37
|
-
result = @aws_client.list_topics(next_token: @next_token)
|
38
|
-
@next_token = result.next_token
|
39
|
-
result.topics.each do |topic|
|
40
|
-
topic_name = topic.topic_arn.split(':').last
|
41
|
-
@topics[topic_name.to_sym] = topic.topic_arn
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|