mongo-db-utils 0.1.5 → 0.1.6

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: 5ebca148c29c6c312df7459863527b52e53c2347
4
- data.tar.gz: f61231bfa2e9d579aec99f55d3ff0c42158f804f
3
+ metadata.gz: 415c2d49fcbcad5aa3e835eb0b5fe88c880e8cfe
4
+ data.tar.gz: 93218696727910919cd569d0658fa1f2fe8f6a65
5
5
  SHA512:
6
- metadata.gz: dc1e86cc61d9ee1a748c508f8875fab63774e7583a1683fdbc78c1c66c5aed0670625da5e867f5198ad507fa807272244f4961c575b0ac5d2f38d552efb82041
7
- data.tar.gz: 9467a8f2f6c08b93324842b881fd7a8418246b66c889cfca24e5db1bb72482cfd913ce9303323cf8933200b75e8c483badb6d2b6fb53ee9514e93636ccf0fd19
6
+ metadata.gz: d6b92ba1baa0e548c2f845370e2a909602897ff216e6bb6366803c7535f286a22783be2cc9557a6816751bc9e74da2ebc137f3320214a4538bc5d9c91100ea49
7
+ data.tar.gz: a56d22c2bc234e4e9c9c2cadab2a27b019228a4ac577b620a1462e2cfd584ac6f3848f59ab4e8cd1447c8446102edc75cd923923a22e561ac1446faebbb326ba
data/.gitignore CHANGED
@@ -1,7 +1,10 @@
1
1
  *.gem
2
+ *.iml
2
3
  *.rbc
3
4
  .bundle
4
5
  .config
6
+ .idea
7
+ .tmp_path
5
8
  .yardoc
6
9
  Gemfile.lock
7
10
  InstalledFiles
@@ -14,5 +17,4 @@ rdoc
14
17
  spec/reports
15
18
  test/tmp
16
19
  test/version_tmp
17
- tmp
18
- .tmp_path
20
+ tmp
@@ -15,21 +15,31 @@ module MongoDbUtils
15
15
  class BaseCmd
16
16
 
17
17
  def initialize(cmd_name, host_and_port, db, username = "", password = "")
18
- @options = build_base_options(host_and_port, db, username, password)
18
+ @unsafeOptions = build_base_options(host_and_port, db, username, password)
19
+ @optionsWithoutCredentials = build_base_options(host_and_port, db, username.empty? ? '':'****', password.empty? ? '':'****')
19
20
  @cmd_name = cmd_name
20
21
  end
21
22
 
22
23
  def run
23
24
  puts "[#{self.class}] run: #{cmd}"
24
- output = `#{cmd}`
25
+ output = `#{executableCmd}`
25
26
  raise ToolsException.new("#{cmd}", output) unless $?.to_i == 0
26
27
  end
27
28
 
28
29
  def cmd
29
- "#{@cmd_name} #{options_string(@options)}"
30
+ "#{@cmd_name} #{options_string(@optionsWithoutCredentials)}"
31
+ end
32
+
33
+ def executableCmd
34
+ "#{@cmd_name} #{options_string(@unsafeOptions)}"
30
35
  end
31
36
 
32
37
  private
38
+
39
+ def addOption(option)
40
+ @unsafeOptions << option
41
+ @optionsWithoutCredentials << option
42
+ end
33
43
 
34
44
  def o(key,value)
35
45
  Option.new(key,value)
@@ -55,29 +65,33 @@ module MongoDbUtils
55
65
  class Dump < BaseCmd
56
66
  def initialize(host_and_port,db,output,username = "", password = "")
57
67
  super("mongodump", host_and_port, db, username, password)
58
- @options << o("-o", output)
68
+ addOption(o("-o", output))
59
69
  end
60
70
  end
61
71
 
62
72
  class Restore < BaseCmd
63
73
  def initialize(host_and_port,db,source_folder,username = "", password = "")
64
74
  super("mongorestore", host_and_port, db, username, password)
65
- @options << "--drop"
75
+ addOption("--drop")
66
76
  @source_folder = source_folder
67
77
  end
68
78
 
69
79
  def cmd
70
80
  "#{super} #{@source_folder}"
71
81
  end
82
+
83
+ def executableCmd
84
+ "#{super} #{@source_folder}"
85
+ end
72
86
  end
73
87
 
74
88
  class Import < BaseCmd
75
89
  def initialize(host_and_port, db, collection, file, username = "", password = "", opts = {})
76
90
  super("mongoimport", host_and_port, db, username, password)
77
- @options << o("-c", collection)
78
- @options << o("--file", file)
79
- @options << "--jsonArray" if opts[:json_array]
80
- @options << "--drop" if opts[:drop]
91
+ addOption(o("-c", collection))
92
+ addOption(o("--file", file))
93
+ addOption("--jsonArray") if opts[:json_array]
94
+ addOption("--drop") if opts[:drop]
81
95
  end
82
96
  end
83
97
 
@@ -85,10 +99,10 @@ module MongoDbUtils
85
99
 
86
100
  def initialize(host_and_port, db, collection, query, output, username = "", password = "", opts = {})
87
101
  super("mongoexport", host_and_port, db, username, password)
88
- @options << o("-c", collection)
89
- @options << o("-o", output)
90
- @options << o("--query", "'#{query}'")
91
- @options << "--jsonArray" if opts[:json_array]
102
+ addOption(o("-c", collection))
103
+ addOption(o("-o", output))
104
+ addOption(o("--query", "'#{query}'"))
105
+ addOption("--jsonArray") if opts[:json_array]
92
106
  end
93
107
  end
94
108
 
@@ -1,4 +1,4 @@
1
1
  module MongoDbUtils
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  READY_FOR_USE = "(prod version)"
4
4
  end
@@ -4,64 +4,98 @@ include MongoDbUtils::Tools
4
4
 
5
5
  describe Dump do
6
6
 
7
+ it "should safely work with single uris" do
8
+ Dump.new("host:port", "db", "out", "user", "pass").cmd.should eql "mongodump -h host:port -db db -u **** -p **** -o out"
9
+ end
10
+
7
11
  it "should work with single uris" do
8
- Dump.new("host:port", "db", "out", "user", "pass").cmd.should eql "mongodump -h host:port -db db -u user -p pass -o out"
12
+ Dump.new("host:port", "db", "out", "user", "pass").executableCmd.should eql "mongodump -h host:port -db db -u user -p pass -o out"
9
13
  end
14
+
10
15
  it "should work with single uris - no user/pass" do
11
- Dump.new("host:port", "db", "out").cmd.should eql "mongodump -h host:port -db db -o out"
16
+ Dump.new("host:port", "db", "out").executableCmd.should eql "mongodump -h host:port -db db -o out"
17
+ end
18
+
19
+ it "should safely work with replica set uris" do
20
+ expected = "mongodump -h setname/host1:port1,host2:port2 -db db -u **** -p **** -o out"
21
+ Dump.new("setname/host1:port1,host2:port2","db", "out", "user", "pass").cmd.should eql expected
12
22
  end
13
23
 
14
24
  it "should work with replica set uris" do
15
25
  expected = "mongodump -h setname/host1:port1,host2:port2 -db db -u user -p pass -o out"
16
- Dump.new("setname/host1:port1,host2:port2","db", "out", "user", "pass").cmd.should eql expected
26
+ Dump.new("setname/host1:port1,host2:port2","db", "out", "user", "pass").executableCmd.should eql expected
17
27
  end
28
+
18
29
  end
19
30
 
20
31
  describe Restore do
21
32
 
22
- it "should work with single uris" do
23
- Restore.new("host:port", "db", "source", "user", "pass").cmd.should eql "mongorestore -h host:port -db db -u user -p pass --drop source"
33
+ it "should safely work with single uris" do
34
+ Restore.new("host:port", "db", "source", "user", "pass").cmd.should eql "mongorestore -h host:port -db db -u **** -p **** --drop source"
24
35
  end
25
36
 
26
37
  it "should work with single uris" do
27
- Restore.new("host:port", "db", "source").cmd.should eql "mongorestore -h host:port -db db --drop source"
38
+ Restore.new("host:port", "db", "source", "user", "pass").executableCmd.should eql "mongorestore -h host:port -db db -u user -p pass --drop source"
39
+ end
40
+
41
+ it "should safely work with replica set uris" do
42
+ expected = "mongorestore -h setname/host1:port1,host2:port2 -db db -u **** -p **** --drop source"
43
+ Restore.new("setname/host1:port1,host2:port2","db", "source", "user", "pass").cmd.should eql expected
28
44
  end
29
45
 
30
46
  it "should work with replica set uris" do
31
47
  expected = "mongorestore -h setname/host1:port1,host2:port2 -db db -u user -p pass --drop source"
32
- Restore.new("setname/host1:port1,host2:port2","db", "source", "user", "pass").cmd.should eql expected
48
+ Restore.new("setname/host1:port1,host2:port2","db", "source", "user", "pass").executableCmd.should eql expected
33
49
  end
34
50
  end
35
51
 
36
52
  describe Import do
37
53
 
54
+ it "should safely work with single uris - with user/pass" do
55
+ Import.new("host:port", "db", "coll", "myfile.json", "user", "pass").cmd.should eql "mongoimport -h host:port -db db -u **** -p **** -c coll --file myfile.json"
56
+ end
57
+
38
58
  it "should work with single uris - with user/pass" do
39
- Import.new("host:port", "db", "coll", "myfile.json", "user", "pass").cmd.should eql "mongoimport -h host:port -db db -u user -p pass -c coll --file myfile.json"
59
+ Import.new("host:port", "db", "coll", "myfile.json", "user", "pass").executableCmd.should eql "mongoimport -h host:port -db db -u user -p pass -c coll --file myfile.json"
40
60
  end
41
61
 
42
62
  it "should work with single uris - no user/pass" do
43
- Import.new("host:port", "db", "coll", "myfile.json").cmd.should eql "mongoimport -h host:port -db db -c coll --file myfile.json"
63
+ Import.new("host:port", "db", "coll", "myfile.json").executableCmd.should eql "mongoimport -h host:port -db db -c coll --file myfile.json"
64
+ end
65
+
66
+ it "should safely work with replica set uris" do
67
+ expected = "mongoimport -h setname/host1:port1,host2:port2 -db db -u **** -p **** -c coll --file myfile.json --jsonArray"
68
+ Import.new("setname/host1:port1,host2:port2","db", "coll", "myfile.json", "user", "pass", { :json_array => true} ).cmd.should eql expected
44
69
  end
45
70
 
46
71
  it "should work with replica set uris" do
47
72
  expected = "mongoimport -h setname/host1:port1,host2:port2 -db db -u user -p pass -c coll --file myfile.json --jsonArray"
48
- Import.new("setname/host1:port1,host2:port2","db", "coll", "myfile.json", "user", "pass", { :json_array => true} ).cmd.should eql expected
73
+ Import.new("setname/host1:port1,host2:port2","db", "coll", "myfile.json", "user", "pass", { :json_array => true} ).executableCmd.should eql expected
49
74
  end
50
75
  end
51
76
 
52
77
  describe Export do
53
78
 
79
+ it "should safely work with single uris - with user/pass" do
80
+ Export.new("host:port", "db", "coll", "{query}", "myfile.json", "user", "pass").cmd.should eql "mongoexport -h host:port -db db -u **** -p **** -c coll -o myfile.json --query '{query}'"
81
+ end
82
+
54
83
  it "should work with single uris - with user/pass" do
55
- Export.new("host:port", "db", "coll", "{query}", "myfile.json", "user", "pass").cmd.should eql "mongoexport -h host:port -db db -u user -p pass -c coll -o myfile.json --query '{query}'"
84
+ Export.new("host:port", "db", "coll", "{query}", "myfile.json", "user", "pass").executableCmd.should eql "mongoexport -h host:port -db db -u user -p pass -c coll -o myfile.json --query '{query}'"
56
85
  end
57
86
 
58
87
  it "should work with single uris - no user/pass" do
59
- Export.new("host:port", "db", "coll", "{query}", "myfile.json").cmd.should eql "mongoexport -h host:port -db db -c coll -o myfile.json --query '{query}'"
88
+ Export.new("host:port", "db", "coll", "{query}", "myfile.json").executableCmd.should eql "mongoexport -h host:port -db db -c coll -o myfile.json --query '{query}'"
89
+ end
90
+
91
+ it "should safely work with replica set uris" do
92
+ expected = "mongoexport -h setname/host1:port1,host2:port2 -db db -u **** -p **** -c coll -o myfile.json --query '{query}' --jsonArray"
93
+ Export.new("setname/host1:port1,host2:port2","db", "coll", "{query}", "myfile.json", "user", "pass", { :json_array => true} ).cmd.should eql expected
60
94
  end
61
95
 
62
96
  it "should work with replica set uris" do
63
97
  expected = "mongoexport -h setname/host1:port1,host2:port2 -db db -u user -p pass -c coll -o myfile.json --query '{query}' --jsonArray"
64
- Export.new("setname/host1:port1,host2:port2","db", "coll", "{query}", "myfile.json", "user", "pass", { :json_array => true} ).cmd.should eql expected
98
+ Export.new("setname/host1:port1,host2:port2","db", "coll", "{query}", "myfile.json", "user", "pass", { :json_array => true} ).executableCmd.should eql expected
65
99
  end
66
100
  end
67
101
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo-db-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - edeustace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-15 00:00:00.000000000 Z
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec