saws 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/saws.rb +17 -5
  2. data/lib/saws/base.rb +2 -2
  3. data/lib/saws/cli.rb +8 -7
  4. metadata +4 -4
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'fog'
3
3
  require 'trollop'
4
+ require 'logger'
4
5
  require 'active_support/core_ext/object/blank'
5
6
  require 'active_support/core_ext/object/try'
6
7
  require 'active_support/core_ext/hash/slice'
@@ -8,7 +9,6 @@ require 'active_support/core_ext/hash/except'
8
9
  require 'active_support/core_ext/hash/keys'
9
10
  require 'active_support/core_ext/hash/reverse_merge'
10
11
  require 'active_support/core_ext/hash/indifferent_access'
11
- require 'active_support/core_ext/string/inflections'
12
12
 
13
13
  module SAWS
14
14
  extend self
@@ -17,11 +17,23 @@ module SAWS
17
17
  autoload 'Base', 'saws/base'
18
18
  autoload 'RDS', 'saws/rds'
19
19
 
20
+ def logger
21
+ @logger ||= case CLI.options[:log_file]
22
+ when "STDOUT"
23
+ Logger.new STDOUT
24
+ when String
25
+ Logger.new CLI.options[:log_file]
26
+ end
27
+ end
28
+
20
29
  def connection_options
21
- @connection_options ||= CLI.options.slice(:region).merge(
22
- :aws_access_key_id => CLI.options["aws-access-key-id"],
23
- :aws_secret_access_key => CLI.options["aws-secret-access-key"]
24
- ).symbolize_keys
30
+ @connection_options ||= CLI.options.slice(:region, :aws_access_key_id, :aws_secret_access_key)
31
+ end
32
+
33
+ def log(message)
34
+ logger.info message if logger
25
35
  end
26
36
 
37
+ # Load options
38
+ CLI.options
27
39
  end
@@ -4,13 +4,13 @@ class SAWS::Base
4
4
 
5
5
  def proxy(klass = nil)
6
6
  @_proxy = klass if klass
7
- @_proxy ||= "Fog::AWS::#{name.demodulize}".constantize
7
+ @_proxy ||= eval("Fog::AWS::#{name.split('::').last}")
8
8
  end
9
9
 
10
10
  end
11
11
 
12
12
  def initialize(options = {})
13
- @proxy = self.class.proxy.new SAWS.connection_options.merge(options)
13
+ @proxy = self.class.proxy.new SAWS.connection_options.merge(options)
14
14
  end
15
15
 
16
16
  def respond_to?(*a)
@@ -12,15 +12,16 @@ module SAWS::CLI
12
12
  file = File.readable?(path) ? File.read(path).lines.map(&:strip) : []
13
13
 
14
14
  opts = Trollop::options do
15
- opt "aws-access-key-id", "AWS access key ID", :short => 'K', :type => :string
16
- opt "aws-secret-access-key", "AWS secret access key", :short => 'S', :type => :string
17
- opt "region", "Your AWS region", :short => 'R', :default => "us-east-1"
18
- end.with_indifferent_access
15
+ opt :aws_access_key_id, "AWS access key ID", :short => 'K', :type => :string
16
+ opt :aws_secret_access_key, "AWS secret access key", :short => 'S', :type => :string
17
+ opt :region, "Your AWS region", :short => 'R', :default => "us-east-1"
18
+ opt :log_file, "Log file path", :type => :string
19
+ end
19
20
 
20
- opts["aws-access-key-id"] ||= ENV['AWS_ACCESS_KEY_ID'] || file[0]
21
- opts["aws-secret-access-key"] ||= ENV['AWS_SECRET_ACCESS_KEY'] || file[1]
21
+ opts[:aws_access_key_id] ||= ENV['AWS_ACCESS_KEY_ID'] || file[0]
22
+ opts[:aws_secret_access_key] ||= ENV['AWS_SECRET_ACCESS_KEY'] || file[1]
22
23
 
23
- opts.except("help").each do |key, value|
24
+ opts.slice(:aws_access_key_id, :aws_secret_access_key).each do |key, value|
24
25
  Trollop::die key, "cannot be blank" if value.blank?
25
26
  end
26
27
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saws
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dimitrij Denissenko
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-17 00:00:00 Z
18
+ date: 2011-08-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activesupport