delivery_boy 1.0.1 → 1.2.0

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: 13839750d8addd8784d886e3b8a4056cbc74af2656ff5424a63ba8a4ca6f4a86
4
- data.tar.gz: 931c327dc9db84ba9526518b6a3a59f467ffa1268d0569197e6b242d19f89ef3
3
+ metadata.gz: 68b4c9faf508180a345d2b9009b4ba48ba7892e71cb7c652931111a7fb35733d
4
+ data.tar.gz: 598ce8b8497f179daf5608fb16ae7f33c2c7fbd9bbe704f251f425c4f919d970
5
5
  SHA512:
6
- metadata.gz: b5bb98ab0ff079b8bdfccfa8217f59bdef0bad956602485da3339edcf155553ce25ded599bd78b58a8715b693ec3d4bda06bb48ed81e7c8073b3a28d398e0a29
7
- data.tar.gz: cfecd1aa7996a29db2520abc8a5240ea23d423a4bc1458a52c7190170605ce39e2ba778c75b03127e2a692463cd8f06130a415b1f4c8a047c989ace2d43f8bfb
6
+ metadata.gz: d0502bffd4dd32445d92fc6f3899e6d1c1bd450ee93402202d0a0cb069be3f824c6dfb650c4d649fbc7ba79b616898e3ea4a9fe945df89fd495450d5b507b77b
7
+ data.tar.gz: 2156cc7f694f9b8e20683699bf12357504774e8e74b66dfe140ba8b692d322de55ab7bbdffa437705dff0e2a49fd6dcff7b2c3d44d2d2935ee2bc72696f85754
@@ -0,0 +1,47 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ "main" ]
13
+ pull_request:
14
+ branches: [ "main" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
26
+
27
+ steps:
28
+ - name: Run Confluent Platform (Confluent Server)
29
+ uses: zendesk/cp-all-in-one-action@v0.2.1
30
+ with:
31
+ service: broker
32
+
33
+ - uses: zendesk/checkout@v3
34
+
35
+ - name: Set up Ruby
36
+ uses: zendesk/setup-ruby@v1
37
+ with:
38
+ ruby-version: ${{ matrix.ruby-version }}
39
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
40
+
41
+ - name: Wait for broker to boot
42
+ run: 'while ! nc -z localhost 9092; do echo -n "."; sleep 0.1; done'
43
+
44
+ - name: Run tests
45
+ run: bundle exec rake
46
+ env:
47
+ DELIVERY_BOY_BROKERS: localhost:9092
@@ -0,0 +1,12 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ tags: v*
6
+
7
+ jobs:
8
+ call-workflow:
9
+ uses: zendesk/gw/.github/workflows/ruby-gem-publication.yml@main
10
+ secrets:
11
+ RUBY_GEMS_API_KEY: ${{ secrets.RUBY_GEMS_API_KEY }}
12
+ RUBY_GEMS_TOTP_DEVICE: ${{ secrets.RUBY_GEMS_TOTP_DEVICE }}
@@ -0,0 +1,27 @@
1
+ # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
2
+ #
3
+ # You can adjust the behavior by modifying this file.
4
+ # For more information, see:
5
+ # https://github.com/actions/stale
6
+ name: Mark stale issues and pull requests
7
+
8
+ on:
9
+ schedule:
10
+ - cron: '40 6 * * *'
11
+
12
+ jobs:
13
+ stale:
14
+
15
+ runs-on: ubuntu-latest
16
+ permissions:
17
+ issues: write
18
+ pull-requests: write
19
+
20
+ steps:
21
+ - uses: actions/stale@v5
22
+ with:
23
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
24
+ stale-issue-message: 'This issue has been marked as stale due to a lack of activity. It will be closed in 7 days unless there is new activity.'
25
+ stale-pr-message: 'This PR has been marked as stale due to a lack of activity. It will be closed in 7 days unless there is new activity.'
26
+ stale-issue-label: 'no-issue-activity'
27
+ stale-pr-label: 'no-pr-activity'
data/CHANGELOG CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## v1.2.0
6
+
7
+ * Test with Ruby 3.1 & 3.2
8
+ * Add config support for AWS MSK IAM auth (#66)
9
+
10
+ ## v1.1.0
11
+
12
+ * Support for `ssl_client_cert_key_password` in the configuration (#52)
13
+ * Add `DeliveryBoy.buffer_size` to return the number of messages in the buffer
14
+ * Add `DeliveryBoy::Fake#clear_buffer` and `DeliveryBoy::Fake#buffer_size` to
15
+ support the public API when using the test helper.
16
+ * Support for `sasl_oauth_token_provider` in the configuration. (#55)
17
+
3
18
  ## v1.0.1
4
19
 
5
20
  * Require ruby-kafka v1.0 or higher.
data/README.md CHANGED
@@ -66,7 +66,7 @@ A third method is to produce messages first (without delivering the messages to
66
66
  class CommentsController < ApplicationController
67
67
  def create
68
68
  @comment = Comment.create!(params)
69
-
69
+
70
70
  event = {
71
71
  name: "comment_created",
72
72
  data: {
@@ -74,13 +74,13 @@ A third method is to produce messages first (without delivering the messages to
74
74
  user_id: current_user.id
75
75
  }
76
76
  }
77
-
77
+
78
78
  # This will queue the two messages in the internal buffer.
79
79
  DeliveryBoy.produce(comment.to_json, topic: "comments")
80
80
  DeliveryBoy.produce(event.to_json, topic: "activity")
81
-
81
+
82
82
  # This will deliver all messages in the buffer to Kafka.
83
- # This call is blocking.
83
+ # This call is blocking.
84
84
  DeliveryBoy.deliver_messages
85
85
  end
86
86
  end
@@ -220,11 +220,15 @@ A PEM encoded client cert to use with an SSL connection. Must be used in combina
220
220
 
221
221
  A PEM encoded client cert key to use with an SSL connection. Must be used in combination with `ssl_client_cert`.
222
222
 
223
+ ##### `ssl_client_cert_key_password`
224
+
225
+ The password required to read the ssl_client_cert_key. Must be used in combination with ssl_client_cert_key.
226
+
223
227
  #### SASL Authentication and authorization
224
228
 
225
229
  See [ruby-kafka](https://github.com/zendesk/ruby-kafka#authentication-using-sasl) for more information.
226
230
 
227
- Use either `sasl_gssapi_*` _or_ `sasl_plain_*`, not both.
231
+ Use it through `GSSAPI`, `PLAIN` _or_ `OAUTHBEARER`.
228
232
 
229
233
  ##### `sasl_gssapi_principal`
230
234
 
@@ -246,6 +250,63 @@ The username used to authenticate.
246
250
 
247
251
  The password used to authenticate.
248
252
 
253
+ ##### `sasl_oauth_token_provider`
254
+
255
+ A instance of a class which implements the `token` method.
256
+ As described in [ruby-kafka](https://github.com/zendesk/ruby-kafka/tree/c3e90bc355fad1e27b9af1048966ff08d3d5735b#oauthbearer)
257
+
258
+ ```ruby
259
+ class TokenProvider
260
+ def token
261
+ "oauth-token"
262
+ end
263
+ end
264
+
265
+ DeliveryBoy.configure do |config|
266
+ config.sasl_oauth_token_provider = TokenProvider.new
267
+ config.ssl_ca_certs_from_system = true
268
+ end
269
+ ```
270
+ #### AWS MSK IAM Authentication and Authorization
271
+
272
+ ##### sasl_aws_msk_iam_access_key_id
273
+
274
+ The AWS IAM access key. Required.
275
+
276
+ ##### sasl_aws_msk_iam_secret_key_id
277
+
278
+ The AWS IAM secret access key. Required.
279
+
280
+ ##### sasl_aws_msk_iam_aws_region
281
+
282
+ The AWS region. Required.
283
+
284
+ ##### sasl_aws_msk_iam_session_token
285
+
286
+ The session token. This value can be optional.
287
+
288
+ ###### Examples
289
+
290
+ Using a role arn and web identity token to generate temporary credentials:
291
+
292
+ ```ruby
293
+ require "aws-sdk-core"
294
+ require "delivery_boy"
295
+
296
+ role = Aws::AssumeRoleWebIdentityCredentials.new(
297
+ role_arn: ENV["AWS_ROLE_ARN"],
298
+ web_identity_token_file: ENV["AWS_WEB_IDENTITY_TOKEN_FILE"]
299
+ )
300
+
301
+ DeliveryBoy.configure do |c|
302
+ c.sasl_aws_msk_iam_access_key_id = role.credentials.access_key_id
303
+ c.sasl_aws_msk_iam_secret_key_id = role.credentials.secret_access_key
304
+ c.sasl_aws_msk_iam_session_token = role.credentials.session_token
305
+ c.sasl_aws_msk_iam_aws_region = ENV["AWS_REGION"]
306
+ c.ssl_ca_certs_from_system = true
307
+ end
308
+ ```
309
+
249
310
  ### Testing
250
311
 
251
312
  DeliveryBoy provides a test mode out of the box. When this mode is enabled, messages will be stored in memory rather than being sent to Kafka. If you use RSpec, enabling test mode is as easy as adding this to your spec helper:
data/delivery_boy.gemspec CHANGED
@@ -20,10 +20,9 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_runtime_dependency "ruby-kafka", "~> 1.0"
24
- spec.add_runtime_dependency "king_konf", "~> 0.3"
23
+ spec.add_runtime_dependency "ruby-kafka", "~> 1.5"
24
+ spec.add_runtime_dependency "king_konf", "~> 1.0"
25
25
 
26
- spec.add_development_dependency "bundler", "~> 1.15"
27
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rake", "~> 13.0"
28
27
  spec.add_development_dependency "rspec", "~> 3.0"
29
28
  end
@@ -20,7 +20,7 @@ module DeliveryBoy
20
20
 
21
21
  # Delivery
22
22
  integer :ack_timeout, default: 5
23
- integer :delivery_interval, default: 10
23
+ float :delivery_interval, default: 10
24
24
  integer :delivery_threshold, default: 100
25
25
  integer :max_retries, default: 2
26
26
  integer :required_acks, default: -1
@@ -38,6 +38,7 @@ module DeliveryBoy
38
38
  string :ssl_ca_cert_file_path
39
39
  string :ssl_client_cert, default: nil
40
40
  string :ssl_client_cert_key, default: nil
41
+ string :ssl_client_cert_key_password, default: nil
41
42
  boolean :ssl_ca_certs_from_system, default: false
42
43
  boolean :ssl_verify_hostname, default: true
43
44
 
@@ -52,6 +53,15 @@ module DeliveryBoy
52
53
  string :sasl_scram_mechanism
53
54
  boolean :sasl_over_ssl, default: true
54
55
 
56
+ # SASL OAUTHBEARER
57
+ attr_accessor :sasl_oauth_token_provider
58
+
59
+ # AWS IAM authentication
60
+ string :sasl_aws_msk_iam_access_key_id
61
+ string :sasl_aws_msk_iam_secret_key_id
62
+ string :sasl_aws_msk_iam_aws_region
63
+ string :sasl_aws_msk_iam_session_token, default: nil
64
+
55
65
  # Datadog monitoring
56
66
  boolean :datadog_enabled
57
67
  string :datadog_host
@@ -51,6 +51,18 @@ module DeliveryBoy
51
51
  clear
52
52
  end
53
53
 
54
+ def clear_buffer
55
+ @delivery_lock.synchronize do
56
+ @buffer.clear
57
+ end
58
+ end
59
+
60
+ def buffer_size
61
+ @delivery_lock.synchronize do
62
+ @buffer.values.flatten.size
63
+ end
64
+ end
65
+
54
66
  # Clear all messages stored in memory.
55
67
  def clear
56
68
  @delivery_lock.synchronize do
@@ -40,6 +40,10 @@ module DeliveryBoy
40
40
  sync_producer.clear_buffer
41
41
  end
42
42
 
43
+ def buffer_size
44
+ sync_producer.buffer_size
45
+ end
46
+
43
47
  private
44
48
 
45
49
  attr_reader :config, :logger
@@ -80,6 +84,7 @@ module DeliveryBoy
80
84
  ssl_ca_cert_file_path: config.ssl_ca_cert_file_path,
81
85
  ssl_client_cert: config.ssl_client_cert,
82
86
  ssl_client_cert_key: config.ssl_client_cert_key,
87
+ ssl_client_cert_key_password: config.ssl_client_cert_key_password,
83
88
  ssl_ca_certs_from_system: config.ssl_ca_certs_from_system,
84
89
  ssl_verify_hostname: config.ssl_verify_hostname,
85
90
  sasl_gssapi_principal: config.sasl_gssapi_principal,
@@ -90,7 +95,12 @@ module DeliveryBoy
90
95
  sasl_scram_username: config.sasl_scram_username,
91
96
  sasl_scram_password: config.sasl_scram_password,
92
97
  sasl_scram_mechanism: config.sasl_scram_mechanism,
93
- sasl_over_ssl: config.sasl_over_ssl
98
+ sasl_over_ssl: config.sasl_over_ssl,
99
+ sasl_oauth_token_provider: config.sasl_oauth_token_provider,
100
+ sasl_aws_msk_iam_access_key_id: config.sasl_aws_msk_iam_access_key_id,
101
+ sasl_aws_msk_iam_secret_key_id: config.sasl_aws_msk_iam_secret_key_id,
102
+ sasl_aws_msk_iam_session_token: config.sasl_aws_msk_iam_session_token,
103
+ sasl_aws_msk_iam_aws_region: config.sasl_aws_msk_iam_aws_region
94
104
  )
95
105
  end
96
106
 
@@ -1,3 +1,3 @@
1
1
  module DeliveryBoy
2
- VERSION = "1.0.1"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/delivery_boy.rb CHANGED
@@ -4,6 +4,7 @@ require "delivery_boy/version"
4
4
  require "delivery_boy/instance"
5
5
  require "delivery_boy/fake"
6
6
  require "delivery_boy/config"
7
+ require "delivery_boy/config_error"
7
8
  require "delivery_boy/railtie" if defined?(Rails::Railtie)
8
9
 
9
10
  module DeliveryBoy
@@ -85,6 +86,11 @@ module DeliveryBoy
85
86
  instance.clear_buffer
86
87
  end
87
88
 
89
+ # Return the number of messages in the buffer
90
+ def buffer_size
91
+ instance.buffer_size
92
+ end
93
+
88
94
  # Shut down DeliveryBoy.
89
95
  #
90
96
  # Automatically called when the process exits.
@@ -116,6 +122,10 @@ module DeliveryBoy
116
122
  raise ConfigError, e.message
117
123
  end
118
124
 
125
+ def clear_config!
126
+ @config = nil
127
+ end
128
+
119
129
  # Configure DeliveryBoy in a block.
120
130
  #
121
131
  # DeliveryBoy.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delivery_boy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-09 00:00:00.000000000 Z
11
+ date: 2024-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-kafka
@@ -16,56 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: king_konf
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.3'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.15'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.15'
40
+ version: '1.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '10.0'
47
+ version: '13.0'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '10.0'
54
+ version: '13.0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -87,10 +73,11 @@ executables: []
87
73
  extensions: []
88
74
  extra_rdoc_files: []
89
75
  files:
90
- - ".circleci/config.yml"
76
+ - ".github/workflows/ci.yml"
77
+ - ".github/workflows/publish.yml"
78
+ - ".github/workflows/stale.yml"
91
79
  - ".gitignore"
92
80
  - ".rspec"
93
- - ".travis.yml"
94
81
  - CHANGELOG
95
82
  - Gemfile
96
83
  - LICENSE.txt
@@ -130,8 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
117
  - !ruby/object:Gem::Version
131
118
  version: '0'
132
119
  requirements: []
133
- rubyforge_project:
134
- rubygems_version: 2.7.6
120
+ rubygems_version: 3.5.3
135
121
  signing_key:
136
122
  specification_version: 4
137
123
  summary: A simple way to produce messages to Kafka from Ruby applications
data/.circleci/config.yml DELETED
@@ -1,33 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.5.1-node
6
- environment:
7
- LOG_LEVEL: DEBUG
8
- - image: wurstmeister/zookeeper
9
- - image: wurstmeister/kafka:2.11-2.0.0
10
- environment:
11
- KAFKA_ADVERTISED_HOST_NAME: localhost
12
- KAFKA_ADVERTISED_PORT: 9092
13
- KAFKA_PORT: 9092
14
- KAFKA_ZOOKEEPER_CONNECT: localhost:2181
15
- KAFKA_DELETE_TOPIC_ENABLE: true
16
- - image: wurstmeister/kafka:2.11-2.0.0
17
- environment:
18
- KAFKA_ADVERTISED_HOST_NAME: localhost
19
- KAFKA_ADVERTISED_PORT: 9093
20
- KAFKA_PORT: 9093
21
- KAFKA_ZOOKEEPER_CONNECT: localhost:2181
22
- KAFKA_DELETE_TOPIC_ENABLE: true
23
- - image: wurstmeister/kafka:2.11-2.0.0
24
- environment:
25
- KAFKA_ADVERTISED_HOST_NAME: localhost
26
- KAFKA_ADVERTISED_PORT: 9094
27
- KAFKA_PORT: 9094
28
- KAFKA_ZOOKEEPER_CONNECT: localhost:2181
29
- KAFKA_DELETE_TOPIC_ENABLE: true
30
- steps:
31
- - checkout
32
- - run: bundle install --path vendor/bundle
33
- - run: bundle exec rspec
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.3
5
- before_install: gem install bundler -v 1.15.3