mongoid-shell 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 281b10f7bd8d03398017dd86286d9fb9f188738f
4
- data.tar.gz: e45e3e8df36e8df3dc6ccad7451e84580c69fd40
3
+ metadata.gz: b0e80be659912607683e05be144ad4456b51a999
4
+ data.tar.gz: 9d43a23815209ba7354f1fc22bc8a7f54286d382
5
5
  SHA512:
6
- metadata.gz: 01de62b1af19ff3d15b3deb906e534bb46124549a934ee9122bfcb885569b1a8a6aa653d3738cd9504812d40dc94b6485356a62cf383a8025494067808a8d049
7
- data.tar.gz: 3ae7256e0dfc0f4800b7c1c8087cf8cc9d2b1a9b7947f79d744f232a5aa14dca4f0de971ce9b5d1a0ed9ea323d67ad90cf89867f2c8f0d8bc00bc398660c25e3
6
+ metadata.gz: d7fb5e80531426776aa4828a30e9dd5d328dff0db4430e20e50f5498c8ad72a1146c5b493e688283ec95ef65fc648fbd6fae72db52ff2d15eac0200d8b332aed
7
+ data.tar.gz: 8a35c2256c55e8fa5c2ac3dcf2b998e7b8e32331b3f35e27fac021ffac1cf676419afd2ad42670443142465a2973a1294f4ccf81fcc53ef3bfb1344f03397ddf
@@ -1,3 +1,8 @@
1
+ ### 0.4.5 (9/7/2017)
2
+
3
+ * [#13](https://github.com/mongoid/mongoid-shell/issues/13): Support masking sensitive values with `to_s(mask_sensitive: true)` - [@dblock](https://github.com/dblock).
4
+ * [#14](https://github.com/mongoid/mongoid-shell/pull/14): Refactored arg definitions into `arg` and `option` - [@dblock](https://github.com/dblock).
5
+
1
6
  ### 0.4.4 (6/4/2017)
2
7
 
3
8
  * [#11](https://github.com/mongoid/mongoid-shell/pull/11): Compatibility with Mongoid 6 - [@jbach](https://github.com/jbach).
data/README.md CHANGED
@@ -43,6 +43,15 @@ mongodump = Mongoid::Shell::Commands::Mongodump.new(excludeCollection: %w(users
43
43
  system mongodump.to_s # mongodump --excludeCollection users --excludeCollection products
44
44
  ```
45
45
 
46
+ To use output in logs, pass the `mask_sensitive` option to `to_s`.
47
+
48
+ ``` ruby
49
+ > Mongoid::Shell::Commands::Mongo.new.to_s(mask_sensitive: true)
50
+ => "mongo 59.1.22.1:27017/mongoid --username user --password ********"
51
+
52
+ > Mongoid::Shell::Commands::Mongo.new.to_s(mask_sensitive: '(masked)')
53
+ => "mongo 59.1.22.1:27017/mongoid --username user --password (masked)"
54
+ ```
46
55
 
47
56
  Compatibility
48
57
  -------------
@@ -5,9 +5,31 @@ module Mongoid
5
5
  attr_accessor :session
6
6
 
7
7
  class << self
8
+ attr_accessor :args
9
+ @args = {}
10
+
11
+ def inherit_args(args)
12
+ @args ||= {}
13
+ @args.merge(args || {})
14
+ end
15
+
16
+ def inherited(sublass)
17
+ sublass.inherit_args(@args)
18
+ end
19
+
8
20
  def command_for(session)
9
21
  new(session: session)
10
22
  end
23
+
24
+ def arg(name, options = {})
25
+ attr_accessor name unless instance_methods.include?(name)
26
+ args[name] = { property: name }.merge(options)
27
+ end
28
+
29
+ def option(name, options = {})
30
+ attr_accessor name unless instance_methods.include?(name)
31
+ args[name] = { key: "--#{name}", property: name }.merge(options)
32
+ end
11
33
  end
12
34
 
13
35
  def initialize(options = nil)
@@ -23,24 +45,31 @@ module Mongoid
23
45
  self.class.name.downcase.split(':').last
24
46
  end
25
47
 
26
- def vargs(args = {})
27
- args.map do |key, property|
28
- value = send(property)
48
+ def vargs(options = {})
49
+ mask_sensitive = options[:mask_sensitive]
50
+ mask_sensitive = '********' if mask_sensitive && mask_sensitive.is_a?(TrueClass)
51
+ self.class.args.values.map do |arg|
52
+ key = arg[:key]
53
+ value = send(arg[:property])
29
54
  next unless value
30
55
  case value
31
56
  when Boolean, TrueClass then key
32
57
  when Array then value.map { |v| "#{key} #{v}" }.join(' ')
33
58
  else
34
- value = value.to_s
35
- # TODO: quote other special characters?
36
- value = '"' + value + '"' if value.include? ' '
37
- key[0] == '-' ? "#{key} #{value}" : value
59
+ if mask_sensitive && arg[:sensitive]
60
+ value = mask_sensitive
61
+ else
62
+ # TODO: quote other special characters?
63
+ value = value.to_s
64
+ value = '"' + value + '"' if value.include? ' '
65
+ end
66
+ key ? "#{key} #{value}" : value
38
67
  end
39
68
  end
40
69
  end
41
70
 
42
- def to_s
43
- [cmd, vargs].flatten.compact.join(' ')
71
+ def to_s(options = {})
72
+ [cmd, vargs(options)].flatten.compact.join(' ')
44
73
  end
45
74
 
46
75
  private
@@ -7,28 +7,19 @@ module Mongoid
7
7
  include Mongoid::Shell::Properties::Username
8
8
  include Mongoid::Shell::Properties::Password
9
9
 
10
- attr_accessor :eval, :nodb, :norc, :quiet, :ipv6
10
+ arg :host_port_and_db
11
11
 
12
- def initialize(attrs = {})
13
- super
14
- end
12
+ option :username
13
+ option :password, sensitive: true
14
+ option :eval
15
+ option :nodb
16
+ option :norc
17
+ option :quiet
18
+ option :ipv6
15
19
 
16
20
  def host_port_and_db
17
21
  [primary, db].compact.join('/')
18
22
  end
19
-
20
- def vargs
21
- super({
22
- 'db address' => :host_port_and_db,
23
- '--username' => :username,
24
- '--password' => :password,
25
- '--eval' => :eval,
26
- '--nodb' => :nodb,
27
- '--norc' => :norc,
28
- '--quiet' => :quiet,
29
- '--ipv6' => :ipv6
30
- })
31
- end
32
23
  end
33
24
  end
34
25
  end
@@ -7,33 +7,22 @@ module Mongoid
7
7
  include Mongoid::Shell::Properties::Username
8
8
  include Mongoid::Shell::Properties::Password
9
9
 
10
- attr_accessor :collection, :query, :out, :directoryperdb, :journal, :oplog, :repair, :forceTableScan, :dbpath, :ipv6, :excludeCollection,
11
- :excludeCollectionsWithPrefix
12
-
13
- def initialize(attrs = {})
14
- super
15
- end
16
-
17
- def vargs
18
- super({
19
- '--host' => :host,
20
- '--db' => :db,
21
- '--username' => :username,
22
- '--password' => :password,
23
- '--collection' => :collection,
24
- '--excludeCollection' => :excludeCollection,
25
- '--excludeCollectionsWithPrefix' => :excludeCollectionsWithPrefix,
26
- '--query' => :query,
27
- '--out' => :out,
28
- '--directoryperdb' => :directoryperdb,
29
- '--journal' => :journal,
30
- '--oplog' => :oplog,
31
- '--repair' => :repair,
32
- '--forceTableScan' => :forceTableScan,
33
- '--dbpath' => :dbpath,
34
- '--ipv6' => :ipv6
35
- })
36
- end
10
+ option :host
11
+ option :db
12
+ option :username
13
+ option :password, sensitive: true
14
+ option :collection
15
+ option :excludeCollection
16
+ option :excludeCollectionsWithPrefix
17
+ option :query
18
+ option :out
19
+ option :directoryperdb
20
+ option :journal
21
+ option :oplog
22
+ option :repair
23
+ option :forceTableScan
24
+ option :dbpath
25
+ option :ipv6
37
26
  end
38
27
  end
39
28
  end
@@ -7,62 +7,50 @@ module Mongoid
7
7
  include Mongoid::Shell::Properties::Username
8
8
  include Mongoid::Shell::Properties::Password
9
9
 
10
- attr_accessor :verbose, :quiet, :port, :ipv6, :ssl, :sslCAFile,
11
- :sslPEMKeyFile, :sslPEMKeyPassword, :sslCRLFile,
12
- :sslAllowInvalidCertificates, :sslAllowInvalidHostnames, :sslFIPSMode,
13
- :authenticationDatabase, :authenticationMechanism, :gssapiServiceName,
14
- :gssapiHostName, :collection, :fields, :fieldFile, :query, :csv,
15
- :type, :out, :jsonArray, :pretty, :slaveOk, :forceTableScan, :skip,
16
- :limit, :sort, :directoryperdb, :journal, :dbpath
10
+ # args
11
+ option :db
12
+ option :host
13
+ option :port
14
+ option :sslCAFile
15
+ option :sslPEMKeyFile
16
+ option :sslPEMKeyPassword, sensitive: true
17
+ option :sslCRLFile
18
+ option :username
19
+ option :password, sensitive: true
20
+ option :authenticationDatabase
21
+ option :authenticationMechanism
22
+ option :collection
23
+ option :fields
24
+ option :fieldFile
25
+ option :query
26
+ option :type
27
+ option :out
28
+ option :skip
29
+ option :limit
30
+ option :sort
17
31
 
18
- def initialize(attrs = {})
19
- super
20
- end
32
+ # boolean options
33
+ option :verbose
34
+ option :quiet
35
+ option :ipv6
36
+ option :ssl
37
+ option :sslAllowInvalidCertificates
38
+ option :sslAllowInvalidHostnames
39
+ option :sslFIPSMode
40
+ option :gssapiServiceName
41
+ option :gssapiHostName
42
+ option :jsonArray
43
+ option :pretty
44
+ option :slaveOk
45
+ option :forceTableScan
21
46
 
22
- def vargs
23
- super var_options.merge(boolean_options)
24
- end
47
+ # is deprecated from Mongo version 3.0.0, use type instead
48
+ option :csv
25
49
 
26
- private
27
-
28
- def var_options
29
- {
30
- '--db' => :db, '--host' => :host, '--port' => :port,
31
- '--sslCAFile' => :sslCAFile,
32
- '--sslPEMKeyFile' => :sslPEMKeyFile,
33
- '--sslPEMKeyPassword' => :sslPEMKeyPassword,
34
- '--sslCRLFile' => :sslCRLFile,
35
- '--username' => :username,
36
- '--password' => :password,
37
- '--authenticationDatabase' => :authenticationDatabase,
38
- '--authenticationMechanism' => :authenticationMechanism,
39
- '--collection' => :collection,
40
- '--fields' => :fields, '--fieldFile' => :fieldFile,
41
- '--query' => :query,
42
- '--type' => :type, '--out' => :out,
43
- '--skip' => :skip, '--limit' => :limit, '--sort' => :sort
44
- }
45
- end
46
-
47
- def boolean_options
48
- {
49
- '--verbose' => :verbose, '--quiet' => :quiet,
50
- '--ipv6' => :ipv6, '--ssl' => :ssl,
51
- '--sslAllowInvalidCertificates' => :sslAllowInvalidCertificates,
52
- '--sslAllowInvalidHostnames' => :sslAllowInvalidHostnames,
53
- '--sslFIPSMode' => :sslFIPSMode,
54
- '--gssapiServiceName' => :gssapiServiceName,
55
- '--gssapiHostName' => :gssapiHostName,
56
- '--jsonArray' => :jsonArray,
57
- '--pretty' => :pretty,
58
- '--slaveOk' => :slaveOk,
59
- '--forceTableScan' => :forceTableScan,
60
- '--csv' => :csv, # is deprecated from Mongo version 3.0.0, use type instead
61
- # these 3 below are deprecated from Mongo version 3.0.0
62
- '--directoryperdb' => :directoryperdb,
63
- '--journal' => :journal, '--dbpath' => :dbpath
64
- }
65
- end
50
+ # these 3 below are deprecated from Mongo version 3.0.0
51
+ option :directoryperdb
52
+ option :journal
53
+ option :dbpath
66
54
  end
67
55
  end
68
56
  end
@@ -7,67 +7,47 @@ module Mongoid
7
7
  include Mongoid::Shell::Properties::Username
8
8
  include Mongoid::Shell::Properties::Password
9
9
 
10
- attr_accessor :verbose, :quiet, :port, :ipv6, :ssl, :sslCAFile,
11
- :sslPEMKeyFile, :sslPEMKeyPassword, :sslCRLFile,
12
- :sslAllowInvalidCertificates, :sslAllowInvalidHostnames, :sslFIPSMode,
13
- :authenticationDatabase, :authenticationMechanism, :gssapiServiceName,
14
- :gssapiHostName, :collection, :fields, :directoryperdb, :journal, :dbpath,
15
- :fieldFile, :ignoreBlanks, :type, :file, :drop, :headerline, :upsert,
16
- :upsertFields, :stopOnError, :jsonArray, :maintainInsertionOrder,
17
- :numInsertionWorkers, :writeConcern
18
-
19
- def initialize(attrs = {})
20
- super
21
- end
22
-
23
- def vargs
24
- super({
25
-
26
- })
27
- end
28
-
29
- def vargs
30
- super var_options.merge(boolean_options)
31
- end
32
-
33
- private
34
-
35
- def var_options
36
- {
37
- '--db' => :db, '--host' => :host, '--port' => :port,
38
- '--sslCAFile' => :sslCAFile,
39
- '--sslPEMKeyFile' => :sslPEMKeyFile,
40
- '--sslPEMKeyPassword' => :sslPEMKeyPassword,
41
- '--sslCRLFile' => :sslCRLFile,
42
- '--username' => :username, '--password' => :password,
43
- '--authenticationDatabase' => :authenticationDatabase,
44
- '--authenticationMechanism' => :authenticationMechanism,
45
- '--collection' => :collection, '--fields' => :fields,
46
- '--fieldFile' => :fieldFile, '--type' => :type, '--file' => :file,
47
- '--upsertFields' => :upsertFields,
48
- '--maintainInsertionOrder' => :maintainInsertionOrder,
49
- '--numInsertionWorkers' => :numInsertionWorkers,
50
- '--writeConcern' => :writeConcern,
51
- # these 3 below are deprecated from Mongo version 3.0.0
52
- '--directoryperdb' => :directoryperdb,
53
- '--journal' => :journal, '--dbpath' => :dbpath
54
- }
55
- end
56
-
57
- def boolean_options
58
- {
59
- '--verbose' => :verbose, '--quiet' => :quiet,
60
- '--ipv6' => :ipv6, '--ssl' => :ssl,
61
- '--sslAllowInvalidCertificates' => :sslAllowInvalidCertificates,
62
- '--sslAllowInvalidHostnames' => :sslAllowInvalidHostnames,
63
- '--sslFIPSMode' => :sslFIPSMode,
64
- '--gssapiServiceName' => :gssapiServiceName,
65
- '--gssapiHostName' => :gssapiHostName,
66
- '--ignoreBlanks' => :ignoreBlanks, '--drop' => :drop,
67
- '--headerline' => :headerline, '--upsert' => :upsert,
68
- '--stopOnError' => :stopOnError, '--jsonArray' => :jsonArray
69
- }
70
- end
10
+ option :db
11
+ option :host
12
+ option :port
13
+ option :sslCAFile
14
+ option :sslPEMKeyFile
15
+ option :sslPEMKeyPassword, sensitive: true
16
+ option :sslCRLFile
17
+ option :username
18
+ option :password, sensitive: true
19
+ option :authenticationDatabase
20
+ option :authenticationMechanism
21
+ option :collection
22
+ option :fields
23
+ option :fieldFile
24
+ option :type
25
+ option :file
26
+ option :upsertFields
27
+ option :maintainInsertionOrder
28
+ option :numInsertionWorkers
29
+ option :writeConcern
30
+
31
+ # these 3 below are deprecated from Mongo version 3.0.0
32
+ option :directoryperdb
33
+ option :journal
34
+ option :dbpath
35
+
36
+ option :verbose
37
+ option :quiet
38
+ option :ipv6
39
+ option :ssl
40
+ option :sslAllowInvalidCertificates
41
+ option :sslAllowInvalidHostnames
42
+ option :sslFIPSMode
43
+ option :gssapiServiceName
44
+ option :gssapiHostName
45
+ option :ignoreBlanks
46
+ option :drop
47
+ option :headerline
48
+ option :upsert
49
+ option :stopOnError
50
+ option :jsonArray
71
51
  end
72
52
  end
73
53
  end
@@ -7,36 +7,27 @@ module Mongoid
7
7
  include Mongoid::Shell::Properties::Username
8
8
  include Mongoid::Shell::Properties::Password
9
9
 
10
- attr_accessor :host, :collection, :ipv6, :dbpath, :directoryperdb, :journal, :objcheck, :filter, :drop, :oplogReplay, :keepIndexVersion, :noIndexRestore, :restore
10
+ option :host
11
+ option :db
12
+ option :username
13
+ option :password, sensitive: true
14
+ option :collection
15
+ option :ipv6
16
+ option :dbpath
17
+ option :directoryperdb
18
+ option :journal
19
+ option :objcheck
20
+ option :filter
21
+ option :drop
22
+ option :oplogReplay
23
+ option :keepIndexVersion
24
+ option :noIndexRestore
11
25
 
12
- def initialize(attrs = {})
13
- super
14
- end
26
+ arg :restore
15
27
 
16
28
  def host
17
29
  @host || primary
18
30
  end
19
-
20
- def vargs
21
- super({
22
- '--host' => :host,
23
- '--db' => :db,
24
- '--username' => :username,
25
- '--password' => :password,
26
- '--collection' => :collection,
27
- '--ipv6' => :ipv6,
28
- '--dbpath' => :dbpath,
29
- '--directoryperdb' => :directoryperdb,
30
- '--journal' => :journal,
31
- '--objcheck' => :objcheck,
32
- '--filter' => :filter,
33
- '--drop' => :drop,
34
- '--oplogReplay' => :oplogReplay,
35
- '--keepIndexVersion' => :keepIndexVersion,
36
- '--noIndexRestore' => :noIndexRestore,
37
- 'directory or filename to restore from' => :restore
38
- })
39
- end
40
31
  end
41
32
  end
42
33
  end
@@ -7,24 +7,14 @@ module Mongoid
7
7
  include Mongoid::Shell::Properties::Username
8
8
  include Mongoid::Shell::Properties::Password
9
9
 
10
- attr_accessor :rowcount, :discover, :all, :http, :noheaders
11
-
12
- def initialize(attrs = {})
13
- super
14
- end
15
-
16
- def vargs
17
- super({
18
- '--host' => :host,
19
- '--username' => :username,
20
- '--password' => :password,
21
- '--rowcount' => :rowcount,
22
- '--discover' => :discover,
23
- '--noheaders' => :noheaders,
24
- '--http' => :http,
25
- '--all' => :all
26
- })
27
- end
10
+ option :host
11
+ option :username
12
+ option :password, sensitive: true
13
+ option :rowcount
14
+ option :discover
15
+ option :noheaders
16
+ option :http
17
+ option :all
28
18
  end
29
19
  end
30
20
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Shell
3
- VERSION = '0.4.4'.freeze
3
+ VERSION = '0.4.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-04 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid