mongolly 0.2.9 → 0.2.10

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: 697b8dc29e9aa15f0d51614ffd5627bcf67c6bf9
4
- data.tar.gz: 82095fdcee43fcd4bad769b70b79cacecd2b1210
3
+ metadata.gz: 0e5dfd7e55a93db2f0ab03b50b7676d97b25a212
4
+ data.tar.gz: 26304958d35572763588aeb6521f6f86037caa9f
5
5
  SHA512:
6
- metadata.gz: 8b6c010ff0096ce2febec13f8c850507ef7628852cd96a7356660cf0c6e06457f51c644f3ea5394d66cea0a8b6e3129dbc41f6c6de0d0aaa0ea7c218545d126b
7
- data.tar.gz: 43ef7d581b4a28513a17a77893ac0f0ecc432c3499231c7c170ef4a08e0258967969696a9ea39219cbf46b2dca2145cdbfa1e78c224527e2a7ef90dffa59c98e
6
+ metadata.gz: 19cfd8db4e216c2789aeb4e4099ab7c1e6e7812631ee2c0f64b032cf0537cd9b871f9188b286d89f98258dab9e362c5fdfdb87f43c16172c1e5893a6ee8fba48
7
+ data.tar.gz: d9538c0a1fcd46158a1bee43a662174191347f8f0661316a896b3916326382095a411508fdb327682a87e1317009b794fab0b4d8f1dd92959cf93f6c25f98869
@@ -6,19 +6,12 @@ require 'mongolly'
6
6
 
7
7
  module Mongolly
8
8
  class Runner < Thor
9
-
10
- CONFIG_PATH = File.expand_path '~/.mongolly'
11
-
12
- def initialize(*args)
13
- super
14
- @config = read_config
15
- exit unless @config && valid_config?
16
- end
9
+ class_option :config, :type => :string, aliases: '-c', default: '~/.mongolly', desc: 'Path to config file'
17
10
 
18
11
  desc "backup", "Snapshots the Database EBS Volumes"
19
12
  method_option :dry_run, type: :boolean, desc: 'Step through command without changes'
20
13
  def backup
21
- Shepherd.new({dry_run: options[:dry_run]}.merge(@config)).backup
14
+ Shepherd.new({dry_run: options[:dry_run]}.merge(config)).backup
22
15
  end
23
16
 
24
17
  desc "clean", "Removes old Database EBS Snapshots"
@@ -26,13 +19,31 @@ module Mongolly
26
19
  method_option :dry_run, type: :boolean, desc: 'Step through command without changes'
27
20
  def clean
28
21
  age = Time.parse(options[:age])
29
- Shepherd.new({dry_run: options[:dry_run]}.merge(@config)).cleanup(age)
22
+ Shepherd.new({dry_run: options[:dry_run]}.merge(config)).cleanup(age)
30
23
  end
31
24
 
32
25
  private
33
- def seed_config
34
- return true if File.exists? CONFIG_PATH
26
+ def config
27
+ @config ||= read_config
28
+ end
29
+
30
+ def read_config
31
+ unless File.exists? config_path
32
+ seed_config
33
+ exit 1
34
+ end
35
+
36
+ begin
37
+ cfg = YAML::load( File.read( config_path ) )
38
+ rescue e
39
+ puts " ** Unable to read config at #{config_path}"
40
+ raise e
41
+ end
35
42
 
43
+ validated_config cfg
44
+ end
45
+
46
+ def seed_config
36
47
  empty_config = {
37
48
  database: [],
38
49
  db_username: nil,
@@ -47,35 +58,26 @@ module Mongolly
47
58
  config_server_ssh_keypath: nil
48
59
  }
49
60
 
50
- File.open( CONFIG_PATH, "w" ) do |f|
61
+ File.open( config_path, "w" ) do |f|
51
62
  f.write( empty_config.to_yaml )
52
63
  end
53
64
 
54
- puts " ** An empty configuration file has been written to #{CONFIG_PATH}."
65
+ puts " ** An empty configuration file has been written to #{config_path}."
55
66
  puts " ** you must now edit this configuration file with your AWS Credentials,"
56
67
  puts " ** MongoDB Connection Details, and the array of volume IDs that you wish"
57
68
  puts " ** to snapshot"
58
-
59
- return false
60
- end
61
-
62
- def read_config
63
- return false unless seed_config
64
- begin
65
- return YAML::load( File.read( CONFIG_PATH ) )
66
- rescue e
67
- puts " ** Unable to read config at #{CONFIG_PATH}"
68
- raise e
69
- end
70
69
  end
71
70
 
72
- def valid_config?
71
+ def validated_config(cfg)
73
72
  %w(database access_key_id secret_access_key).each do |arg|
74
- raise ArgumentError.new("#{arg} cannot be empty") if @config[arg.to_sym].to_s.strip.empty?
73
+ raise ArgumentError.new("#{arg} cannot be empty") if cfg[arg.to_sym].to_s.strip.empty?
75
74
  end
76
- return true
75
+ cfg
77
76
  end
78
77
 
78
+ def config_path
79
+ config_path ||= File.expand_path(options[:config])
80
+ end
79
81
  end
80
82
  end
81
83
 
@@ -195,7 +195,7 @@ protected
195
195
 
196
196
  def replica_set_connection(hosts, options)
197
197
  db = Mongo::MongoReplicaSetClient.new(hosts)
198
- db['admin'].authenticate(options[:db_username], options[:db_password])
198
+ db['admin'].authenticate(options[:db_username], options[:db_password]) if options[:db_username]
199
199
  return db
200
200
  end
201
201
 
@@ -1,3 +1,3 @@
1
1
  module Mongolly
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongolly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Saffitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor