cyclone_lariat 0.3.7 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 982f0e0a32ade340ac840ee2d55f77c44e362efa90be1269a68a0a95b4077aca
4
- data.tar.gz: a9111db53d68391b0cc06f84edae37b8b3b4713a9e3817bd85dfb502666ea128
3
+ metadata.gz: e81df0b814b28eff97a38a58e1d3573ef09efc594242da8b9768ed781eb1f989
4
+ data.tar.gz: ef8441b399c937518506bacc0514a1fbb68cde9c0d92e99d619edf3bfaee9611
5
5
  SHA512:
6
- metadata.gz: 8db237a3ad94e569bb3e64faf57a6d0e18bc2333e478e46281d33aae51126ecea543d52ed316547b2ab0c0223337e4b9c44cf47bfe8661cdba7ece8676bb765d
7
- data.tar.gz: 5ea0b7ac666233ffead54de6df93a9757426bfba9cec467898f5ec50f4077eb360968369a9929ef9f87a4b1e29ba5a9cbfbae34c9f90f96445c6016217f36525
6
+ metadata.gz: 216f064daa35c0eb8599b368364ee116c0184e1ee7bd2ad94e39b06ce324d5f958c21fca460f2b368db34fcca287bb23db34af03c14718a676618213765ca150
7
+ data.tar.gz: 947a143ea181f60a450dba792091f3a122c88d6929638272292370bbaa8a5fe0270ecf6ad4d3ba01b560660478987dc9388879327100efa8426717be9cf75b9a
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ 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.8] - 2022-09-05
8
+ Added
9
+ - Added configuration options see README.md
10
+
11
+ ## [0.3.8] - 2022-09-05
12
+ Changed
13
+ - Added pagination to sns topics list for receiving all topics
14
+ - Added list topics store for reduce unnecessary requests to aws
15
+
7
16
  ## [0.3.7] - 2022-02-10
8
17
  Changed
9
18
  - Add exception when received broken JSON
@@ -40,8 +49,8 @@ Added
40
49
 
41
50
  ## [0.2.2] - 2021-06-08
42
51
  Changed
43
- - Fix save to database
44
- - Rename error to client error
52
+ - Fix save to database
53
+ - Rename error to client error
45
54
 
46
55
  ## [0.2.1] - 2021-06-02
47
56
  - Fix can load from database if error_details is nil
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cyclone_lariat (0.3.6)
4
+ cyclone_lariat (0.3.9)
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.553.0)
17
- aws-sdk-core (3.126.0)
16
+ aws-partitions (1.626.0)
17
+ aws-sdk-core (3.140.0)
18
18
  aws-eventstream (~> 1, >= 1.0.2)
19
19
  aws-partitions (~> 1, >= 1.525.0)
20
20
  aws-sigv4 (~> 1.1)
21
- jmespath (~> 1.0)
22
- aws-sdk-sns (1.51.0)
23
- aws-sdk-core (~> 3, >= 3.126.0)
21
+ jmespath (~> 1, >= 1.6.1)
22
+ aws-sdk-sns (1.54.0)
23
+ aws-sdk-core (~> 3, >= 3.127.0)
24
24
  aws-sigv4 (~> 1.1)
25
- aws-sdk-sqs (1.50.0)
26
- aws-sdk-core (~> 3, >= 3.126.0)
25
+ aws-sdk-sqs (1.51.1)
26
+ aws-sdk-core (~> 3, >= 3.127.0)
27
27
  aws-sigv4 (~> 1.1)
28
- aws-sigv4 (1.4.0)
28
+ aws-sigv4 (1.5.1)
29
29
  aws-eventstream (~> 1, >= 1.0.2)
30
30
  byebug (11.1.3)
31
31
  coderay (1.1.3)
@@ -38,7 +38,7 @@ GEM
38
38
  diff-lcs (1.5.0)
39
39
  docile (1.3.5)
40
40
  hashdiff (1.0.1)
41
- jmespath (1.5.0)
41
+ jmespath (1.6.1)
42
42
  luna_park (0.11.1)
43
43
  method_source (1.0.0)
44
44
  parallel (1.20.1)
data/README.md CHANGED
@@ -34,6 +34,19 @@ 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.key = # aws key
43
+ cl.secret_key = # aws secret
44
+ cl.default_region = # aws default region
45
+ cl.publisher = 'auth' # name of your publishers, usually name of your application
46
+ cl.default_instance = APP_INSTANCE # stage, production, test
47
+ end
48
+ ```
49
+
37
50
  ## SnsClient
38
51
  You can use client directly
39
52
 
@@ -14,9 +14,6 @@ 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
- DEFAULT_VERSION = 1
18
- DEFAULT_INSTANCE = :prod
19
-
20
17
  def initialize(key:, secret_key:, region:, version: nil, publisher: nil, instance: nil)
21
18
  @key = key
22
19
  @secret_key = secret_key
@@ -54,15 +51,15 @@ module CycloneLariat
54
51
 
55
52
  class << self
56
53
  def version(version = nil)
57
- version.nil? ? @version || DEFAULT_VERSION : @version = version
54
+ version.nil? ? @version || CycloneLariat.default_version : @version = version
58
55
  end
59
56
 
60
57
  def instance(instance = nil)
61
- instance.nil? ? @instance || DEFAULT_INSTANCE : @instance = instance
58
+ instance.nil? ? @instance || CycloneLariat.default_instance || (raise 'You should define instance') : @instance = instance
62
59
  end
63
60
 
64
61
  def publisher(publisher = nil)
65
- publisher.nil? ? @publisher || (raise 'You should define publisher') : @publisher = publisher
62
+ publisher.nil? ? @publisher || CycloneLariat.publisher || (raise 'You should define publisher') : @publisher = publisher
66
63
  end
67
64
  end
68
65
 
@@ -78,9 +75,19 @@ module CycloneLariat
78
75
  @instance ||= self.class.instance
79
76
  end
80
77
 
81
- private
78
+ def key
79
+ @key ||= CycloneLariat.key
80
+ end
81
+
82
+ def secret_key
83
+ @secret_key ||= CycloneLariat.secret_key
84
+ end
85
+
86
+ def region
87
+ @region ||= CycloneLariat.default_region
88
+ end
82
89
 
83
- attr_reader :key, :secret_key, :region
90
+ private
84
91
 
85
92
  def aws_client
86
93
  @aws_client ||= aws_client_class.new(credentials: aws_credentials, region: region)
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CycloneLariat
4
+ class << self
5
+ DEFAULT_VERSION = 1
6
+
7
+ attr_accessor :key, :secret_key, :publisher, :default_region, :default_instance
8
+ attr_writer :default_version
9
+
10
+ def default_version
11
+ @default_version ||= DEFAULT_VERSION
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,45 @@
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'aws-sdk-sns'
4
4
  require_relative 'abstract/client'
5
+ require_relative 'list_topics_store'
5
6
 
6
7
  module CycloneLariat
7
8
  class SnsClient < Abstract::Client
@@ -31,11 +32,21 @@ module CycloneLariat
31
32
  private
32
33
 
33
34
  def topic_arn(topic_name)
34
- list = aws_client.list_topics.topics
35
- topic = list.find { |t| t.topic_arn.match?(topic_name) }
36
- raise Errors::TopicNotFound.new(expected_topic: topic_name, existed_topics: list.map(&:topic_arn)) if topic.nil?
35
+ topics_store.add_topics(aws_client)
36
+ topic_arn = topics_store.topic_arn(topic_name)
37
37
 
38
- topic.topic_arn
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
46
+ end
47
+
48
+ def topics_store
49
+ ListTopicsStore.instance
39
50
  end
40
51
  end
41
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CycloneLariat
4
- VERSION = '0.3.7'
4
+ VERSION = '0.3.9'
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'cyclone_lariat/configure'
3
4
  require_relative 'cyclone_lariat/sns_client'
4
5
  require_relative 'cyclone_lariat/errors'
5
6
  require_relative 'cyclone_lariat/event'
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.7
4
+ version: 0.3.9
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-02-10 00:00:00.000000000 Z
12
+ date: 2022-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-sns
@@ -269,8 +269,10 @@ 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
275
+ - lib/cyclone_lariat/list_topics_store.rb
274
276
  - lib/cyclone_lariat/messages_mapper.rb
275
277
  - lib/cyclone_lariat/messages_repo.rb
276
278
  - lib/cyclone_lariat/middleware.rb