cyclone_lariat 0.3.9 → 0.3.10

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: e81df0b814b28eff97a38a58e1d3573ef09efc594242da8b9768ed781eb1f989
4
- data.tar.gz: ef8441b399c937518506bacc0514a1fbb68cde9c0d92e99d619edf3bfaee9611
3
+ metadata.gz: db8b83a45f403749ab3ab2503f22e85af53cce8fc3267a63eb31df0246d30683
4
+ data.tar.gz: 31ed6ee400d6778d90adf90ef997cc577df5564b78238cdc36b8067ff9fcaff9
5
5
  SHA512:
6
- metadata.gz: 216f064daa35c0eb8599b368364ee116c0184e1ee7bd2ad94e39b06ce324d5f958c21fca460f2b368db34fcca287bb23db34af03c14718a676618213765ca150
7
- data.tar.gz: 947a143ea181f60a450dba792091f3a122c88d6929638272292370bbaa8a5fe0270ecf6ad4d3ba01b560660478987dc9388879327100efa8426717be9cf75b9a
6
+ metadata.gz: f73b11ffa6189231a1ebd71dcb7db455fbc092aaa00e740b4b1092006dd4db38550ddbb94ccc0266dc1bf4f467d481110a92061344fb1a6fa22e92ef48995b4b
7
+ data.tar.gz: d06087c237bbc3946c7e91772a987edf47b787ccd0f8e1c6e0f341f32fa6c7965b1546dcc7e188967baafaac19dd140ddca0d1cdbafb82ce68ab736d965271ef
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ 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
+
7
17
  ## [0.3.8] - 2022-09-05
8
18
  Added
9
19
  - Added configuration options see README.md
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cyclone_lariat (0.3.9)
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.626.0)
17
- aws-sdk-core (3.140.0)
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.54.0)
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.1)
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
@@ -38,12 +38,13 @@ received at all.
38
38
  ```ruby
39
39
  # 'config/initializers/cyclone_lariat.rb'
40
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
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
47
48
  end
48
49
  ```
49
50
 
@@ -14,13 +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
- 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)
18
18
  @key = key
19
19
  @secret_key = secret_key
20
20
  @region = region
21
21
  @version = version
22
22
  @publisher = publisher
23
23
  @instance = instance
24
+ @client_id = client_id
24
25
  end
25
26
 
26
27
  def event(type, data: {}, version: self.version, uuid: SecureRandom.uuid)
@@ -76,15 +77,19 @@ module CycloneLariat
76
77
  end
77
78
 
78
79
  def key
79
- @key ||= CycloneLariat.key
80
+ @key ||= CycloneLariat.aws_key
80
81
  end
81
82
 
82
83
  def secret_key
83
- @secret_key ||= CycloneLariat.secret_key
84
+ @secret_key ||= CycloneLariat.aws_secret_key
84
85
  end
85
86
 
86
87
  def region
87
- @region ||= CycloneLariat.default_region
88
+ @region ||= CycloneLariat.aws_default_region
89
+ end
90
+
91
+ def client_id
92
+ @client_id ||= CycloneLariat.aws_client_id
88
93
  end
89
94
 
90
95
  private
@@ -4,7 +4,8 @@ module CycloneLariat
4
4
  class << self
5
5
  DEFAULT_VERSION = 1
6
6
 
7
- attr_accessor :key, :secret_key, :publisher, :default_region, :default_instance
7
+ attr_accessor :aws_key, :aws_secret_key, :publisher, :aws_default_region, :default_instance,
8
+ :aws_client_id
8
9
  attr_writer :default_version
9
10
 
10
11
  def default_version
@@ -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 ||= [instance, msg.kind, SNS_SUFFIX, publisher, msg.type].join('-')
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 topic_arn(topic_name)
35
- topics_store.add_topics(aws_client)
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 topics_store
49
- ListTopicsStore.instance
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CycloneLariat
4
- VERSION = '0.3.9'
4
+ VERSION = '0.3.10'
5
5
  end
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.9
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-10-05 00:00:00.000000000 Z
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
@@ -272,7 +272,6 @@ files:
272
272
  - lib/cyclone_lariat/configure.rb
273
273
  - lib/cyclone_lariat/errors.rb
274
274
  - lib/cyclone_lariat/event.rb
275
- - lib/cyclone_lariat/list_topics_store.rb
276
275
  - lib/cyclone_lariat/messages_mapper.rb
277
276
  - lib/cyclone_lariat/messages_repo.rb
278
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