sdbport 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
- ## HEAD:
1
+ ## 0.3.0:
2
+
3
+ * Added support for reading multiple env configs
2
4
 
3
5
  ## 0.2.1:
4
6
 
data/README.md CHANGED
@@ -8,34 +8,63 @@ Sdbport exports & imports data from AWS SimpleDB domains. It can be used as a cl
8
8
 
9
9
  gem install sdbport
10
10
 
11
- ## Usage
11
+ ## Getting Started
12
12
 
13
13
  Set your AWS credentials:
14
14
 
15
15
  ```
16
- export AWS_ACCESS_KEY_ID=key
17
- export AWS_SECRET_ACCESS_KEY=secret
16
+ export AWS_ACCESS_KEY_ID=your_aws_key
17
+ export AWS_SECRET_ACCESS_KEY=your_aws_secret
18
18
  ```
19
19
 
20
- Or create a config file (-a and -s can then be ommited):
20
+ Export SimpleDB domain from us-west-1:
21
+
22
+ ```
23
+ sdbport export -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -r us-west-1 -n data -o /tmp/test-domain-dump
24
+ ```
25
+
26
+ Import into domain in us-east-1
27
+
28
+ ```
29
+ sdbport import -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -r us-west-1 -n data -i /tmp/test-domain-dump
30
+
31
+ ## Exporting and importing from multiple accounts.
32
+
33
+ You can specify your credentials on the command line, however it is best to add them to a configuration file.
34
+
35
+ By default, sdbport look for .sdbport.yml in your home directory. To get started, add you AWS keys.
36
+
37
+ ```
38
+ cat > ~/.sdbport.yml << EOF
39
+ default:
40
+ access_key: your_aws_key
41
+ secret_key: your_aws_secert
42
+ EOF
43
+ ```
44
+
45
+ You can add multiple account credentials and specify the account with --account (-a).
21
46
 
22
47
  ```
23
48
  cat > ~/.sdbport.yml << EOF
24
- access_key: your_aws_key
25
- secret_key: your_aws_secert
49
+ prod:
50
+ access_key: your_aws_key
51
+ secret_key: your_aws_secert
52
+ preprod:
53
+ access_key: your_aws_key
54
+ secret_key: your_aws_secert
26
55
  EOF
27
56
  ```
28
57
 
29
- Export SimpleDB domain:
58
+ Export SimpleDB domain data from prod account in us-west-1:
30
59
 
31
60
  ```
32
- sdbport export -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -r us-west-1 -n test -o /tmp/test-domain-dump
61
+ sdbport export -a prod -r us-west-1 -n data -o /tmp/data-domain-dump
33
62
  ```
34
63
 
35
- Import into new domain:
64
+ Import into preprod account in us-east-1:
36
65
 
37
66
  ```
38
- sdbport import -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -r us-west-1 -n new-domain -i /tmp/test-domain-dump
67
+ sdbport import -a preprod -r us-east-1 -n data -i /tmp/data-domain-dump
39
68
  ```
40
69
 
41
70
  To list CLI subcommands:
@@ -7,25 +7,19 @@ require 'sdbport/cli/purge'
7
7
  module Sdbport
8
8
  class CLI
9
9
 
10
- def initialize
11
- @config = Config.new
12
- @aws_default_creds = { :access_key => @config.access_key,
13
- :secret_key => @config.secret_key }
14
- end
15
-
16
10
  def start
17
11
 
18
12
  cmd = ARGV.shift
19
13
 
20
14
  case cmd
21
- when 'destroy'
22
- CLI::Destroy.new(@aws_default_creds).destroy
15
+ when 'destroy', 'delete'
16
+ CLI::Destroy.new.destroy
23
17
  when 'export'
24
- CLI::Export.new(@aws_default_creds).export
18
+ CLI::Export.new.export
25
19
  when 'import'
26
- CLI::Import.new(@aws_default_creds).import
20
+ CLI::Import.new.import
27
21
  when 'purge'
28
- CLI::Purge.new(@aws_default_creds).purge
22
+ CLI::Purge.new.purge
29
23
  when '-v'
30
24
  puts Sdbport::VERSION
31
25
  else
@@ -2,15 +2,16 @@ module Sdbport
2
2
  class CLI
3
3
  class Destroy
4
4
 
5
- def initialize(args)
6
- @default_access_key = args[:access_key]
7
- @default_secret_key = args[:secret_key]
5
+ def initialize
6
+ @config = Config.new
8
7
  end
9
8
 
10
9
  def destroy
11
10
  opts = read_options
12
- access_key = opts[:access_key] || @default_access_key
13
- secret_key = opts[:secret_key] || @default_secret_key
11
+ access_key = @config.access_key opts[:account]
12
+ secret_key = @config.secret_key opts[:account]
13
+ access_key = opts[:access_key] if opts[:access_key]
14
+ secret_key = opts[:secret_key] if opts[:secret_key]
14
15
 
15
16
  logger = SdbportLogger.new :log_level => opts[:level]
16
17
  domain = Domain.new :name => opts[:name],
@@ -34,10 +35,13 @@ sdbport destroy -a xxx -k yyy -r us-west-1 -n domain
34
35
 
35
36
  EOS
36
37
  opt :help, "Display Help"
38
+ opt :account, "Account Credentials", :type => :string,
39
+ :default => 'default'
37
40
  opt :level, "Log Level", :type => :string, :default => 'info'
38
41
  opt :name, "Simple DB Domain Name", :type => :string
39
- opt :region, "AWS region", :type => :string
40
- opt :access_key, "AWS Access Key ID", :type => :string
42
+ opt :region, "AWS Region", :type => :string
43
+ opt :access_key, "AWS Access Key ID", :type => :string,
44
+ :short => 'k'
41
45
  opt :secret_key, "AWS Secret Access Key", :type => :string
42
46
  end
43
47
  end
@@ -2,15 +2,16 @@ module Sdbport
2
2
  class CLI
3
3
  class Export
4
4
 
5
- def initialize(args)
6
- @default_access_key = args[:access_key]
7
- @default_secret_key = args[:secret_key]
5
+ def initialize
6
+ @config = Config.new
8
7
  end
9
8
 
10
9
  def export
11
10
  opts = read_options
12
- access_key = opts[:access_key] || @default_access_key
13
- secret_key = opts[:secret_key] || @default_secret_key
11
+ access_key = @config.access_key opts[:account]
12
+ secret_key = @config.secret_key opts[:account]
13
+ access_key = opts[:access_key] if opts[:access_key]
14
+ secret_key = opts[:secret_key] if opts[:secret_key]
14
15
 
15
16
  logger = SdbportLogger.new :log_level => opts[:level]
16
17
  domain = Domain.new :name => opts[:name],
@@ -34,11 +35,14 @@ sdbport export -a xxx -k yyy -r us-west-1 -o /tmp/file -n domain
34
35
 
35
36
  EOS
36
37
  opt :help, "Display Help"
38
+ opt :account, "Account Credentials", :type => :string,
39
+ :default => 'default'
37
40
  opt :level, "Log Level", :type => :string, :default => 'info'
38
41
  opt :name, "Simple DB Domain Name", :type => :string
39
42
  opt :output, "Output File", :type => :string
40
- opt :region, "AWS region", :type => :string
41
- opt :access_key, "AWS Access Key ID", :type => :string
43
+ opt :region, "AWS Region", :type => :string
44
+ opt :access_key, "AWS Access Key ID", :type => :string,
45
+ :short => 'k'
42
46
  opt :secret_key, "AWS Secret Access Key", :type => :string
43
47
  end
44
48
  end
@@ -2,15 +2,16 @@ module Sdbport
2
2
  class CLI
3
3
  class Import
4
4
 
5
- def initialize(args)
6
- @default_access_key = args[:access_key]
7
- @default_secret_key = args[:secret_key]
5
+ def initialize
6
+ @config = Config.new
8
7
  end
9
8
 
10
9
  def import
11
10
  opts = read_options
12
- access_key = opts[:access_key] || @default_access_key
13
- secret_key = opts[:secret_key] || @default_secret_key
11
+ access_key = @config.access_key opts[:account]
12
+ secret_key = @config.secret_key opts[:account]
13
+ access_key = opts[:access_key] if opts[:access_key]
14
+ secret_key = opts[:secret_key] if opts[:secret_key]
14
15
 
15
16
  logger = SdbportLogger.new :log_level => opts[:level]
16
17
  domain = Domain.new :name => opts[:name],
@@ -34,11 +35,14 @@ sdbport import -a xxx -k yyy -r us-west-1 -i /tmp/file -n domain
34
35
 
35
36
  EOS
36
37
  opt :help, "Display Help"
38
+ opt :account, "Account Credentials", :type => :string,
39
+ :default => 'default'
37
40
  opt :level, "Log Level", :type => :string, :default => 'info'
38
41
  opt :name, "Simple DB Domain Name", :type => :string
39
42
  opt :input, "Input File", :type => :string
40
- opt :region, "AWS region", :type => :string
41
- opt :access_key, "AWS Access Key ID", :type => :string
43
+ opt :region, "AWS Region", :type => :string
44
+ opt :access_key, "AWS Access Key ID", :type => :string,
45
+ :short => 'k'
42
46
  opt :secret_key, "AWS Secret Access Key", :type => :string
43
47
  end
44
48
  end
@@ -2,15 +2,16 @@ module Sdbport
2
2
  class CLI
3
3
  class Purge
4
4
 
5
- def initialize(args)
6
- @default_access_key = args[:access_key]
7
- @default_secret_key = args[:secret_key]
5
+ def initialize
6
+ @config = Config.new
8
7
  end
9
8
 
10
9
  def purge
11
10
  opts = read_options
12
- access_key = opts[:access_key] || @default_access_key
13
- secret_key = opts[:secret_key] || @default_secret_key
11
+ access_key = @config.access_key opts[:account]
12
+ secret_key = @config.secret_key opts[:account]
13
+ access_key = opts[:access_key] if opts[:access_key]
14
+ secret_key = opts[:secret_key] if opts[:secret_key]
14
15
 
15
16
  logger = SdbportLogger.new :log_level => opts[:level]
16
17
  domain = Domain.new :name => opts[:name],
@@ -34,10 +35,13 @@ sdbport purge -a xxx -k yyy -r us-west-1 -n domain
34
35
 
35
36
  EOS
36
37
  opt :help, "Display Help"
38
+ opt :account, "Account Credentials", :type => :string,
39
+ :default => 'default'
37
40
  opt :level, "Log Level", :type => :string, :default => 'info'
38
41
  opt :name, "Simple DB Domain Name", :type => :string
39
- opt :region, "AWS region", :type => :string
40
- opt :access_key, "AWS Access Key ID", :type => :string
42
+ opt :region, "AWS Region", :type => :string
43
+ opt :access_key, "AWS Access Key ID", :type => :string,
44
+ :short => 'k'
41
45
  opt :secret_key, "AWS Secret Access Key", :type => :string
42
46
  end
43
47
  end
@@ -1,19 +1,33 @@
1
1
  module Sdbport
2
2
  class Config
3
3
 
4
- attr_reader :access_key, :secret_key
5
-
6
4
  def initialize
7
5
  @config = load_config_file
8
- @access_key = @config.fetch 'access_key', nil
9
- @secret_key = @config.fetch 'secret_key', nil
10
6
  end
11
7
 
8
+ def access_key(account)
9
+ if @config.has_key? account
10
+ @config[account].fetch 'access_key', nil
11
+ else
12
+ nil
13
+ end
14
+ end
15
+
16
+ def secret_key(account)
17
+ if @config.has_key? account
18
+ @config[account].fetch 'secret_key', nil
19
+ else
20
+ nil
21
+ end
22
+ end
23
+
24
+ private
25
+
12
26
  def load_config_file
13
27
  config_file = "#{ENV['HOME']}/.sdbport.yml"
14
28
 
15
29
  if File.exists? config_file
16
- YAML::load File.open(config_file)
30
+ YAML::load(File.open(config_file))
17
31
  else
18
32
  Hash.new
19
33
  end
@@ -1,3 +1,3 @@
1
1
  module Sdbport
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -4,8 +4,6 @@ require 'sdbport/cli'
4
4
  describe Sdbport do
5
5
  before do
6
6
  @cli_mock = mock 'cli'
7
- @default_creds = { :access_key => 'the-key',
8
- :secret_key => 'the-secret' }
9
7
  @config_stub = stub 'config', :access_key => 'the-key',
10
8
  :secret_key => 'the-secret'
11
9
  Sdbport::Config.stub :new => @config_stub
@@ -13,36 +11,28 @@ describe Sdbport do
13
11
  end
14
12
 
15
13
  it "should call destroy" do
16
- Sdbport::CLI::Destroy.should_receive(:new).
17
- with(@default_creds).
18
- and_return @cli_mock
14
+ Sdbport::CLI::Destroy.stub :new => @cli_mock
19
15
  ARGV.stub :shift => 'destroy'
20
16
  @cli_mock.should_receive :destroy
21
17
  @cli.start
22
18
  end
23
19
 
24
20
  it "should call export" do
25
- Sdbport::CLI::Export.should_receive(:new).
26
- with(@default_creds).
27
- and_return @cli_mock
21
+ Sdbport::CLI::Export.stub :new => @cli_mock
28
22
  ARGV.stub :shift => 'export'
29
23
  @cli_mock.should_receive :export
30
24
  @cli.start
31
25
  end
32
26
 
33
27
  it "should call import" do
34
- Sdbport::CLI::Import.should_receive(:new).
35
- with(@default_creds).
36
- and_return @cli_mock
28
+ Sdbport::CLI::Import.stub :new => @cli_mock
37
29
  ARGV.stub :shift => 'import'
38
30
  @cli_mock.should_receive :import
39
31
  @cli.start
40
32
  end
41
33
 
42
34
  it "should call purge" do
43
- Sdbport::CLI::Purge.should_receive(:new).
44
- with(@default_creds).
45
- and_return @cli_mock
35
+ Sdbport::CLI::Purge.stub :new => @cli_mock
46
36
  ARGV.stub :shift => 'purge'
47
37
  @cli_mock.should_receive :purge
48
38
  @cli.start
@@ -3,8 +3,12 @@ require 'spec_helper'
3
3
  describe Sdbport do
4
4
 
5
5
  before do
6
- @config = { 'access_key ' => 'key',
7
- 'secret_key ' => 'secret' }
6
+ @config = {
7
+ 'test123' => {
8
+ 'access_key' => 'key',
9
+ 'secret_key' => 'secret'
10
+ }
11
+ }
8
12
  end
9
13
 
10
14
  it "should create a new config object and read from ~/.sdbport.yml" do
@@ -13,15 +17,15 @@ describe Sdbport do
13
17
  with("#{ENV['HOME']}/.sdbport.yml").
14
18
  and_return @config.to_yaml
15
19
  config = Sdbport::Config.new
16
- config.access_key.should == @config['access_key']
17
- config.secret_key.should == @config['secret_key']
20
+ config.access_key('test123').should == 'key'
21
+ config.secret_key('test123').should == 'secret'
18
22
  end
19
23
 
20
- it "should load a blank config if the file does not exist and no config passed" do
24
+ it "should return nil if .sdbport.yml does not exist" do
21
25
  File.stub :exists? => false
22
26
  config = Sdbport::Config.new
23
- config.access_key.should be_nil
24
- config.secret_key.should be_nil
27
+ config.access_key('test123').should be_nil
28
+ config.secret_key('test123').should be_nil
25
29
  end
26
30
 
27
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdbport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70204089955280 !ruby/object:Gem::Requirement
16
+ requirement: &70269257047280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70204089955280
24
+ version_requirements: *70269257047280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &70204089954700 !ruby/object:Gem::Requirement
27
+ requirement: &70269257046800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70204089954700
35
+ version_requirements: *70269257046800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: trollop
38
- requirement: &70204089954220 !ruby/object:Gem::Requirement
38
+ requirement: &70269257046300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70204089954220
46
+ version_requirements: *70269257046300
47
47
  description: Import and export AWS SimpleDB domains.
48
48
  email:
49
49
  - brett@weav.net
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 227852682613598022
105
+ hash: 3777096327641096662
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  segments:
113
113
  - 0
114
- hash: 227852682613598022
114
+ hash: 3777096327641096662
115
115
  requirements: []
116
116
  rubyforge_project:
117
117
  rubygems_version: 1.8.16