zimbra_intercepting_proxy 0.0.4.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 4c252b4d3f6a2006058703ec346b5079e8643a85
4
- data.tar.gz: a3844422f82a76f3f58ea75870840de0a507da59
3
+ metadata.gz: b534962352a26c91cff6e4d3d26d4dc32b19e748
4
+ data.tar.gz: 31bcc78a7af08640193d35afb7ad6597c3a57de5
5
5
  SHA512:
6
- metadata.gz: 102e74a21d901310d8e40053a5bc1a5c72fda1489ad971c05d6eb701311dd9ae986f3c066edd5e4a88d0417c6366bcb51c64def3cf9e31cdaad5c733ea8dd8e6
7
- data.tar.gz: 9f6be220d1d03645118d5dd608c2062edb7585b807f64aa5c8cb211a4d6e2f344219399c99c42ca1eb5dcf46c43a822063b05fe20e7b57d603af319b812a44af
6
+ metadata.gz: f23053a8336cf6754cfca338692c294caa388fe209c88ddcd79540288bdf99b3ffb1df9a515545976291540e39455d188769b6f4f39dc4c5f2ffcdbadd96cce5
7
+ data.tar.gz: a3015c1dcdd6f7795b46549d9aeca17b0083ac07503900ef9b425590321d8f54e0a8f5e3050ef47d82717c49fb9f28812132d048914331877134a367a40a79fe
data/.gitignore CHANGED
@@ -13,6 +13,7 @@ pkg
13
13
  rdoc
14
14
  spec/reports
15
15
  test/tmp
16
+ test/fixtures/*.org
16
17
  test/version_tmp
17
18
  tmp
18
19
  *.bundle
data/README.md CHANGED
@@ -129,12 +129,21 @@ watson@example.com: "251b1902-2250-4477-bdd1-8a101f7e7e4e"
129
129
  sherlock@example.com: "7b562dd0-be97-0132-9a66-482a1423458f"
130
130
  ```
131
131
 
132
+ Updating the file does **not require** a restart.
133
+
132
134
  You can get the `zimbraId` with:
133
135
 
134
136
  ```
135
137
  $ zmprov ga watson@example.com zimbraId
136
138
  ```
137
139
 
140
+ ##### Error in Map File
141
+ If you have an error in your file, `ZIP` will return the on memory Map, this way we can keep the service up. In this event you should see this on `STDOUT`:
142
+
143
+ ```shel
144
+ ERROR Yaml File: (./test/fixtures/users.yml): could not find expected ':' while scanning a simple key at line 7
145
+ ```
146
+
138
147
  ## Thanks
139
148
 
140
149
  * To the Zimbra folks for a great product, and
@@ -13,6 +13,7 @@ require "zimbra_intercepting_proxy/request"
13
13
  require "zimbra_intercepting_proxy/server"
14
14
  require "zimbra_intercepting_proxy/debug"
15
15
  require "zimbra_intercepting_proxy/connection"
16
+ require "zimbra_intercepting_proxy/yamler"
16
17
 
17
18
  module ZimbraInterceptingProxy
18
19
 
@@ -3,6 +3,8 @@ module ZimbraInterceptingProxy
3
3
  class User
4
4
  attr_accessor :email, :zimbraId
5
5
 
6
+ @@db = {}
7
+
6
8
  # user_identifier can be an email address, zimbraId UUID or just the
7
9
  # local part of an email address, like user in user@example.com
8
10
  def initialize(user_identifier)
@@ -34,12 +36,16 @@ module ZimbraInterceptingProxy
34
36
  !zimbraId.nil?
35
37
  end
36
38
 
39
+ # Return the old DB if the YAML file has error
37
40
  def self.load_migrated_users
38
- YAML.load_file ZimbraInterceptingProxy::Config.migrated_users_file
41
+ data = ZimbraInterceptingProxy::Yamler.db
42
+ return @@db unless data
43
+ @@db = data
39
44
  end
40
45
 
41
46
  def self.DB
42
47
  load_migrated_users
48
+ @@db
43
49
  end
44
50
 
45
51
  private
@@ -1,3 +1,3 @@
1
1
  module ZimbraInterceptingProxy
2
- VERSION = "0.0.4.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,18 @@
1
+ module ZimbraInterceptingProxy
2
+
3
+ module Yamler
4
+ require 'pp'
5
+
6
+ def self.db
7
+ begin
8
+ YAML.load_file ZimbraInterceptingProxy::Config.migrated_users_file
9
+ rescue Psych::SyntaxError => e
10
+ puts "ERROR Yaml File: #{e}"
11
+ return false
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -3,4 +3,4 @@ max@example.com: "7b562c60-be97-0132-9a66-482a1423458f"
3
3
  moliery@example.com: "7b562ce0-be97-0132-9a66-482a1423458f"
4
4
  watson@example.com: "251b1902-2250-4477-bdd1-8a101f7e7e4e"
5
5
  sherlock@example.com: "7b562dd0-be97-0132-9a66-482a1423458f"
6
- pbruna@itlinux.cl: "cfd6e914-4f00-440c-9a57-e1a9327128b9"
6
+ pbruna@itlinux.cl: "cfd6e914-4f00-440c-9a57-e1a9327128b9"
data/test/test_helper.rb CHANGED
@@ -9,4 +9,21 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # spec-like progr
9
9
  ZimbraInterceptingProxy::Config.domain="example.com"
10
10
  ZimbraInterceptingProxy::Config.migrated_users_file="./test/fixtures/users.yml"
11
11
  ZimbraInterceptingProxy::Config.old_backend = "old-mailbox.example.com"
12
- ZimbraInterceptingProxy::Config.new_backend = "new-mailbox.zboxapp.com"
12
+ ZimbraInterceptingProxy::Config.new_backend = "new-mailbox.zboxapp.com"
13
+
14
+ def add_error_line
15
+ f = File.open ZimbraInterceptingProxy::Config.migrated_users_file, "a"
16
+ f.puts "juan :94949494-9494949-040404"
17
+ f.close
18
+ end
19
+
20
+ def restore_map_file
21
+ backup_file = "./test/fixtures/users.yml.org"
22
+ FileUtils.cp(backup_file, ZimbraInterceptingProxy::Config.migrated_users_file)
23
+ FileUtils.rm "./test/fixtures/users.yml.org"
24
+ end
25
+
26
+ def backup_map_file
27
+ backup_file = "./test/fixtures/users.yml.org"
28
+ FileUtils.cp(ZimbraInterceptingProxy::Config.migrated_users_file, backup_file)
29
+ end
data/test/test_user.rb CHANGED
@@ -57,4 +57,15 @@ class User < Minitest::Test
57
57
  assert(!u.migrated?, "Failure message.")
58
58
  end
59
59
 
60
+
61
+ def test_return_old_db_if_yamler_db_is_false
62
+ backup_map_file # backup users.yml
63
+ yaml_1 = ZimbraInterceptingProxy::User.DB.inspect
64
+ add_error_line
65
+ yaml_2 = ZimbraInterceptingProxy::User.DB.inspect
66
+ restore_map_file
67
+ assert_equal(Digest::MD5.digest(yaml_1), Digest::MD5.digest(yaml_2))
68
+ end
69
+
70
+
60
71
  end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+ require 'digest'
3
+
4
+ class Yamler < Minitest::Test
5
+
6
+ def setup
7
+ backup_map_file
8
+ end
9
+
10
+ def teardown
11
+ restore_map_file
12
+ end
13
+
14
+ def test_yamler_db_must_return_the_yaml_file_hash
15
+ db = ZimbraInterceptingProxy::Yamler.db
16
+ assert_equal("251b1902-2250-4477-bdd1-8a101f7e7e4e", db["watson@example.com"])
17
+ end
18
+
19
+ def test_return_false_if_updated_files_has_error
20
+ add_error_line
21
+ assert(!ZimbraInterceptingProxy::Yamler.db, "Failure message.")
22
+ end
23
+
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zimbra_intercepting_proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio Bruna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-proxy
@@ -159,6 +159,7 @@ files:
159
159
  - lib/zimbra_intercepting_proxy/server.rb
160
160
  - lib/zimbra_intercepting_proxy/user.rb
161
161
  - lib/zimbra_intercepting_proxy/version.rb
162
+ - lib/zimbra_intercepting_proxy/yamler.rb
162
163
  - test/fixtures/auth_80.txt
163
164
  - test/fixtures/route_7072.txt
164
165
  - test/fixtures/users.yml
@@ -167,6 +168,7 @@ files:
167
168
  - test/test_helper.rb
168
169
  - test/test_request.rb
169
170
  - test/test_user.rb
171
+ - test/test_yamler.rb
170
172
  - zimbra_intercepting_proxy.gemspec
171
173
  homepage: https://github.com/pbruna/zimbra_intercepting_proxy
172
174
  licenses:
@@ -201,4 +203,5 @@ test_files:
201
203
  - test/test_helper.rb
202
204
  - test/test_request.rb
203
205
  - test/test_user.rb
206
+ - test/test_yamler.rb
204
207
  has_rdoc: