gitlab-mail_room 0.0.24 → 0.0.25

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: 0e4c047999e1f2e3d77862ea0e65f146fe92c89de4d0367892649d518de8ad66
4
- data.tar.gz: 36000daee0622b345eea3be14143652ce335ea9441ab012a4088d0038b7bef8c
3
+ metadata.gz: b38092bd49b7554fc1f14f45b250737db77a58ce851e78ac9c3eb89c17424881
4
+ data.tar.gz: 04a4a167905034fcab7ee3c095991103b2bb5f92ff414c0cb6ca360017ae6f3b
5
5
  SHA512:
6
- metadata.gz: 9693c9ee292e8e45025d251c720d4bda9f80b121aa0524c6c2bad0924b5ec731fcb017f91641c27adf2c7a3321a59345d1f0b80177bbde998ac5b42bc080a13d
7
- data.tar.gz: d8c733b9eaef28122e6b2533e1e5fca6a0aba6581b07be93189f498f38ad4845ef624016258c339a2e6cd8ac56e7eb2fbe3c52a9724d5d9363deb58ed1d8d431
6
+ metadata.gz: 9d09917cbc928d36ea820d06957ad9bc3d47726017abdb307dc734e2b6ef4203dc95866e0821821b461bc86384c7670ad187b3cae0d31e2294501a762d4a9ea9
7
+ data.tar.gz: acea6980fe10c44333325ffd57cd78007302abf5d58e8a11c12e70a0b0aaf61bcea627b14b31bc24dcfe68f938d50a15ba91e60130aeeafbe7fb079b38dddfad
@@ -31,7 +31,7 @@ jobs:
31
31
  - '3.0'
32
32
  - '2.7'
33
33
  steps:
34
- - uses: actions/checkout@v3
34
+ - uses: actions/checkout@v4
35
35
  - name: Set up Ruby ${{ matrix.ruby-version }}
36
36
  uses: ruby/setup-ruby@v1
37
37
  with:
@@ -43,7 +43,7 @@ jobs:
43
43
  rubocop:
44
44
  runs-on: ubuntu-latest
45
45
  steps:
46
- - uses: actions/checkout@v3
46
+ - uses: actions/checkout@v4
47
47
  - name: Set up Ruby ${{ matrix.ruby-version }}
48
48
  uses: ruby/setup-ruby@v1
49
49
  with:
data/.gitlab-ci.yml CHANGED
@@ -10,11 +10,10 @@ services:
10
10
  paths:
11
11
  - vendor/ruby
12
12
  variables:
13
- REDIS_URL: redis://redis:6379/0
13
+ REDIS_URL: redis://redis:6379
14
14
  before_script:
15
15
  - apt update && apt install -y libicu-dev
16
16
  - ruby -v # Print out ruby version for debugging
17
- - gem install bundler --no-document # Bundler is not installed with the image
18
17
  - bundle config set --local path 'vendor'
19
18
  - bundle install -j $(nproc)
20
19
  script:
@@ -23,8 +22,8 @@ services:
23
22
  rspec:
24
23
  parallel:
25
24
  matrix:
26
- - RUBY_VERSION: [ "2.6", "2.7", "3.0", "3.1", "3.2" ]
25
+ - RUBY_VERSION: [ "3.0", "3.1", "3.2" ]
27
26
  <<: *test
28
27
 
29
28
  include:
30
- - template: Security/Dependency-Scanning.gitlab-ci.yml
29
+ - template: Security/Dependency-Scanning.gitlab-ci.yml
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.5
1
+ 3.2
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.2.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## mail_room 0.11.1 ##
2
+
3
+ https://github.com/tpitale/mail_room/compare/v0.11.0...v0.11.1
4
+
5
+ ## mail_room 0.11.0 ##
6
+
7
+ https://github.com/tpitale/mail_room/compare/v0.10.1...v0.11.0
8
+
1
9
  ## mail_room 0.10.1 ##
2
10
 
3
11
  * Fix db attribute on redis URL PR#130 - @jarkaK
data/README.md CHANGED
@@ -489,13 +489,3 @@ respectively and MailRoom will log there.
489
489
  4. Push to the branch (`git push origin my-new-feature`)
490
490
  5. Create new Pull Request
491
491
  6. If accepted, ask for commit rights
492
-
493
- ## TODO ##
494
-
495
- 1. specs, this is just a (working) proof of concept √
496
- 2. finish code for POSTing to callback with auth √
497
- 3. accept mailbox configuration for one account directly on the commandline; or ask for it
498
- 4. add example rails endpoint, with auth examples
499
- 5. add example configs for upstart/init.d √
500
- 6. log to stdout √
501
- 7. add a development mode that opens in letter_opener by ryanb √
@@ -3,11 +3,13 @@ require "redis"
3
3
  module MailRoom
4
4
  module Arbitration
5
5
  class Redis
6
- Options = Struct.new(:redis_url, :namespace, :sentinels) do
6
+ Options = Struct.new(:redis_url, :namespace, :sentinels, :sentinel_username, :sentinel_password) do
7
7
  def initialize(mailbox)
8
8
  redis_url = mailbox.arbitration_options[:redis_url] || "redis://localhost:6379"
9
9
  namespace = mailbox.arbitration_options[:namespace]
10
10
  sentinels = mailbox.arbitration_options[:sentinels]
11
+ sentinel_username = mailbox.arbitration_options[:sentinel_username]
12
+ sentinel_password = mailbox.arbitration_options[:sentinel_password]
11
13
 
12
14
  if namespace
13
15
  warn <<~MSG
@@ -16,7 +18,7 @@ module MailRoom
16
18
  MSG
17
19
  end
18
20
 
19
- super(redis_url, namespace, sentinels)
21
+ super(redis_url, namespace, sentinels, sentinel_username, sentinel_password)
20
22
  end
21
23
  end
22
24
 
@@ -48,6 +50,8 @@ module MailRoom
48
50
  sentinels = options.sentinels
49
51
  redis_options = { url: options.redis_url }
50
52
  redis_options[:sentinels] = sentinels if sentinels
53
+ redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
54
+ redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
51
55
 
52
56
  redis = ::Redis.new(redis_options)
53
57
 
@@ -71,7 +71,7 @@ module MailRoom
71
71
  connection = Faraday.new
72
72
 
73
73
  if @delivery_options.token_auth?
74
- connection.token_auth @delivery_options.token
74
+ config_token_auth(connection)
75
75
  elsif @delivery_options.basic_auth?
76
76
  config_basic_auth(connection)
77
77
  end
@@ -101,6 +101,18 @@ module MailRoom
101
101
  request.headers[@delivery_options.jwt.header] = @delivery_options.jwt.token
102
102
  end
103
103
 
104
+ def config_token_auth(connection)
105
+ # connection.token_auth was removed in Faraday v2 in favor of connection.request(:authorization, 'Token', token)
106
+ if defined?(connection.token_auth)
107
+ connection.token_auth @delivery_options.token
108
+ else
109
+ connection.request(
110
+ :authorization, 'Token',
111
+ @delivery_options.token
112
+ )
113
+ end
114
+ end
115
+
104
116
  def config_basic_auth(connection)
105
117
  if defined?(connection.basic_auth)
106
118
  connection.basic_auth(
@@ -8,12 +8,14 @@ module MailRoom
8
8
  # Sidekiq Delivery method
9
9
  # @author Douwe Maan
10
10
  class Sidekiq
11
- Options = Struct.new(:redis_url, :namespace, :sentinels, :queue, :worker, :logger, :redis_db) do
11
+ Options = Struct.new(:redis_url, :namespace, :sentinels, :queue, :worker, :logger, :redis_db, :sentinel_username, :sentinel_password) do
12
12
  def initialize(mailbox)
13
13
  redis_url = mailbox.delivery_options[:redis_url] || "redis://localhost:6379"
14
14
  redis_db = mailbox.delivery_options[:redis_db] || 0
15
15
  namespace = mailbox.delivery_options[:namespace]
16
16
  sentinels = mailbox.delivery_options[:sentinels]
17
+ sentinel_username = mailbox.delivery_options[:sentinel_username]
18
+ sentinel_password = mailbox.delivery_options[:sentinel_password]
17
19
  queue = mailbox.delivery_options[:queue] || "default"
18
20
  worker = mailbox.delivery_options[:worker]
19
21
  logger = mailbox.logger
@@ -25,7 +27,7 @@ module MailRoom
25
27
  MSG
26
28
  end
27
29
 
28
- super(redis_url, namespace, sentinels, queue, worker, logger, redis_db)
30
+ super(redis_url, namespace, sentinels, queue, worker, logger, redis_db, sentinel_username, sentinel_password)
29
31
  end
30
32
  end
31
33
 
@@ -55,6 +57,8 @@ module MailRoom
55
57
  sentinels = options.sentinels
56
58
  redis_options = { url: options.redis_url, db: options.redis_db }
57
59
  redis_options[:sentinels] = sentinels if sentinels
60
+ redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
61
+ redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
58
62
 
59
63
  redis = ::Redis.new(redis_options)
60
64
 
@@ -1,4 +1,4 @@
1
1
  module MailRoom
2
2
  # Current version of gitlab-mail_room gem
3
- VERSION = "0.0.24"
3
+ VERSION = "0.0.25"
4
4
  end
data/mail_room.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["tpitale@gmail.com"]
11
11
  gem.description = %q{mail_room will proxy email (gmail) from IMAP to a delivery method}
12
12
  gem.summary = %q{mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or letter_opener}
13
- gem.homepage = "http://github.com/tpitale/mail_room"
13
+ gem.homepage = "https://gitlab.com/gitlab-org/ruby/gems/gitlab-mail_room"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -20,13 +20,13 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency "net-imap", ">= 0.2.1"
21
21
  gem.add_dependency "oauth2", [">= 1.4.4", "< 3"]
22
22
  gem.add_dependency "jwt", ">= 2.0"
23
- gem.add_dependency "redis", [">= 4", "< 6"]
23
+ gem.add_dependency "redis", [">= 5", "< 6"]
24
24
  gem.add_dependency "redis-namespace", '>= 1.8.2'
25
25
 
26
26
  gem.add_development_dependency "rake"
27
27
  gem.add_development_dependency "rspec", "~> 3.9"
28
28
  gem.add_development_dependency "rubocop", "~> 1.11"
29
- gem.add_development_dependency "mocha", "~> 1.11"
29
+ gem.add_development_dependency "mocha", "~> 2.0"
30
30
  gem.add_development_dependency "simplecov"
31
31
  gem.add_development_dependency "webrick", "~> 1.6"
32
32
 
@@ -11,21 +11,12 @@ describe MailRoom::Arbitration::Redis do
11
11
  )
12
12
  }
13
13
  let(:options) { described_class::Options.new(mailbox) }
14
- let(:redis5) { Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0') }
15
14
  subject { described_class.new(options) }
16
15
 
17
16
  # Private, but we don't care.
18
17
  let(:redis) { subject.send(:client) }
19
18
  let(:raw_client) { redis._client }
20
19
 
21
- let(:server_url) do
22
- if redis5
23
- raw_client.config.server_url
24
- else
25
- raw_client.options[:url]
26
- end
27
- end
28
-
29
20
  describe '#deliver?' do
30
21
  context "when called the first time" do
31
22
  after do
@@ -89,7 +80,7 @@ describe MailRoom::Arbitration::Redis do
89
80
 
90
81
  context 'redis client connection params' do
91
82
  context 'when only url is present' do
92
- let(:redis_url) { ENV.fetch('REDIS_URL', 'redis://localhost:6379/0') }
83
+ let(:redis_url) { ENV.fetch('REDIS_URL', 'redis://localhost:6379') }
93
84
  let(:mailbox) {
94
85
  build_mailbox(
95
86
  arbitration_options: {
@@ -105,7 +96,7 @@ describe MailRoom::Arbitration::Redis do
105
96
  it 'client has same specified url' do
106
97
  subject.deliver?(123)
107
98
 
108
- expect(server_url).to eq redis_url
99
+ expect(raw_client.config.server_url).to eq redis_url
109
100
  end
110
101
 
111
102
  it 'client is a instance of Redis class' do
@@ -144,17 +135,37 @@ describe MailRoom::Arbitration::Redis do
144
135
  )
145
136
  }
146
137
 
138
+ before { ::RedisClient::SentinelConfig.any_instance.stubs(:resolve_master).returns(RedisClient::Config.new(**sentinels.first)) }
139
+
147
140
  it 'client has same specified sentinel params' do
148
- if redis5
141
+ expect(raw_client.config).to be_a RedisClient::SentinelConfig
142
+ expect(raw_client.config.name).to eq('sentinel-master')
143
+ expect(raw_client.config.host).to eq('10.0.0.1')
144
+ expect(raw_client.config.password).to eq('mypassword')
145
+ expect(raw_client.config.sentinels.map(&:server_url)).to eq(["redis://10.0.0.1:26379"])
146
+ end
147
+
148
+ context 'with separate Sentinel username and password' do
149
+ let(:sentinel_username) { 'my-sentinel-user' }
150
+ let(:sentinel_password) { 'my-sentinel-pass' }
151
+ let(:mailbox) {
152
+ build_mailbox(
153
+ arbitration_options: {
154
+ redis_url: redis_url,
155
+ sentinels: sentinels,
156
+ sentinel_username: sentinel_username,
157
+ sentinel_password: sentinel_password
158
+ }
159
+ )
160
+ }
161
+
162
+ it 'client uses Sentinel username and password' do
163
+ expect(raw_client.config).to be_a RedisClient::SentinelConfig
149
164
  expect(raw_client.config.password).to eq('mypassword')
150
- client_sentinels = raw_client.config.sentinels
151
- expect(client_sentinels.length).to eq(sentinels.length)
152
- expect(client_sentinels[0].host).to eq('10.0.0.1')
153
- expect(client_sentinels[0].port).to eq(26379) # rubocop:disable Style/NumericLiterals
154
- else
155
- expect(raw_client.options[:host]).to eq('sentinel-master')
156
- expect(raw_client.options[:password]).to eq('mypassword')
157
- expect(raw_client.options[:sentinels]).to eq(sentinels)
165
+
166
+ sentinels = raw_client.config.sentinels
167
+ expect(sentinels.map(&:username).uniq).to eq([sentinel_username])
168
+ expect(sentinels.map(&:password).uniq).to eq([sentinel_password])
158
169
  end
159
170
  end
160
171
  end
@@ -6,17 +6,9 @@ describe MailRoom::Delivery::Sidekiq do
6
6
  let(:redis) { subject.send(:client) }
7
7
  let(:raw_client) { redis._client }
8
8
  let(:options) { MailRoom::Delivery::Sidekiq::Options.new(mailbox) }
9
- let(:redis5) { Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0') }
10
- let(:server_url) do
11
- if redis5
12
- raw_client.config.server_url
13
- else
14
- raw_client.options[:url]
15
- end
16
- end
17
9
 
18
10
  describe '#options' do
19
- let(:redis_url) { 'redis://localhost' }
11
+ let(:redis_url) { 'redis://localhost:6379' }
20
12
  let(:redis_options) { { redis_url: redis_url } }
21
13
 
22
14
  context 'when only redis_url is specified' do
@@ -28,10 +20,8 @@ describe MailRoom::Delivery::Sidekiq do
28
20
  }
29
21
 
30
22
  context 'with simple redis url' do
31
- let(:expected_url) { redis5 ? "#{redis_url}:6379/0" : redis_url }
32
-
33
23
  it 'client has same specified redis_url' do
34
- expect(raw_client.server_url).to eq(expected_url)
24
+ expect(raw_client.config.server_url).to eq(redis_url)
35
25
  end
36
26
 
37
27
  it 'client is a instance of RedisNamespace class' do
@@ -45,19 +35,17 @@ describe MailRoom::Delivery::Sidekiq do
45
35
  end
46
36
 
47
37
  context 'with redis_db specified in options' do
48
- let(:expected_url) { redis5 ? "#{redis_url}:6379/4" : redis_url }
49
-
50
38
  before do
51
39
  redis_options[:redis_db] = 4
52
40
  end
53
41
 
54
42
  it 'client has correct redis_url' do
55
- expect(raw_client.server_url).to eq(expected_url)
43
+ expect(raw_client.config.server_url).to eq("#{redis_url}/4")
56
44
  end
57
45
 
58
46
  it 'connection has correct values' do
59
- expect(redis.connection[:host]).to eq('localhost')
60
- expect(redis.connection[:db]).to eq(4)
47
+ expect(raw_client.config.host).to eq('localhost')
48
+ expect(raw_client.config.db).to eq(4)
61
49
  end
62
50
  end
63
51
  end
@@ -96,17 +84,39 @@ describe MailRoom::Delivery::Sidekiq do
96
84
  )
97
85
  }
98
86
 
87
+ before { ::RedisClient::SentinelConfig.any_instance.stubs(:resolve_master).returns(RedisClient::Config.new(**sentinels.first)) }
88
+
99
89
  it 'client has same specified sentinel params' do
100
- if redis5
90
+ expect(raw_client.config).to be_a RedisClient::SentinelConfig
91
+ expect(raw_client.config.host).to eq('10.0.0.1')
92
+ expect(raw_client.config.name).to eq('sentinel-master')
93
+ expect(raw_client.config.password).to eq('mypassword')
94
+ expect(raw_client.config.sentinels.map(&:server_url)).to eq(["redis://10.0.0.1:26379"])
95
+ end
96
+
97
+ context 'with separate Sentinel username and password' do
98
+ let(:sentinel_username) { 'my-sentinel-user' }
99
+ let(:sentinel_password) { 'my-sentinel-pass' }
100
+ let(:mailbox) {
101
+ build_mailbox(
102
+ delivery_method: :sidekiq,
103
+ delivery_options: {
104
+ redis_url: redis_url,
105
+ sentinels: sentinels,
106
+ sentinel_username: sentinel_username,
107
+ sentinel_password: sentinel_password
108
+ }
109
+ )
110
+ }
111
+
112
+ it 'client uses Sentinel username and password' do
113
+ expect(raw_client.config).to be_a RedisClient::SentinelConfig
101
114
  expect(raw_client.config.password).to eq('mypassword')
102
- client_sentinels = raw_client.config.sentinels
103
- expect(client_sentinels.length).to eq(sentinels.length)
104
- expect(client_sentinels[0].host).to eq('10.0.0.1')
105
- expect(client_sentinels[0].port).to eq(26379) # rubocop:disable Style/NumericLiterals
106
- else
107
- expect(raw_client.options[:host]).to eq('sentinel-master')
108
- expect(raw_client.options[:password]).to eq('mypassword')
109
- expect(raw_client.options[:sentinels]).to eq(sentinels)
115
+
116
+ sentinels = raw_client.config.sentinels
117
+
118
+ expect(sentinels.map(&:username).uniq).to eq([sentinel_username])
119
+ expect(sentinels.map(&:password).uniq).to eq([sentinel_password])
110
120
  end
111
121
  end
112
122
  end
@@ -34,12 +34,14 @@ describe MailRoom::HealthCheck do
34
34
 
35
35
  describe '#run' do
36
36
  it 'sets running to true' do
37
- server = stub(start: true)
37
+ server = stub(start: true, shutdown: true)
38
38
  subject.stubs(:create_server).returns(server)
39
39
 
40
40
  subject.run
41
41
 
42
42
  expect(subject.running).to be true
43
+
44
+ subject.quit
43
45
  end
44
46
  end
45
47
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-mail_room
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-08 00:00:00.000000000 Z
11
+ date: 2024-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-imap
@@ -64,7 +64,7 @@ dependencies:
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '4'
67
+ version: '5'
68
68
  - - "<"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '6'
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: '4'
77
+ version: '5'
78
78
  - - "<"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '6'
@@ -140,14 +140,14 @@ dependencies:
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '1.11'
143
+ version: '2.0'
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '1.11'
150
+ version: '2.0'
151
151
  - !ruby/object:Gem::Dependency
152
152
  name: simplecov
153
153
  requirement: !ruby/object:Gem::Requirement
@@ -277,6 +277,7 @@ files:
277
277
  - ".rubocop.yml"
278
278
  - ".rubocop_todo.yml"
279
279
  - ".ruby-version"
280
+ - ".tool-versions"
280
281
  - CHANGELOG.md
281
282
  - CODE_OF_CONDUCT.md
282
283
  - CONTRIBUTING.md
@@ -337,7 +338,7 @@ files:
337
338
  - spec/lib/message_spec.rb
338
339
  - spec/lib/microsoft_graph/connection_spec.rb
339
340
  - spec/spec_helper.rb
340
- homepage: http://github.com/tpitale/mail_room
341
+ homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-mail_room
341
342
  licenses: []
342
343
  metadata: {}
343
344
  post_install_message:
@@ -355,7 +356,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
355
356
  - !ruby/object:Gem::Version
356
357
  version: '0'
357
358
  requirements: []
358
- rubygems_version: 3.4.22
359
+ rubygems_version: 3.5.4
359
360
  signing_key:
360
361
  specification_version: 4
361
362
  summary: mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or