sdbport 0.2.0 → 0.2.1
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.
- data/CHANGELOG +4 -0
- data/README.md +9 -0
- data/lib/sdbport.rb +1 -0
- data/lib/sdbport/cli.rb +10 -4
- data/lib/sdbport/cli/destroy.rb +15 -7
- data/lib/sdbport/cli/export.rb +12 -6
- data/lib/sdbport/cli/import.rb +12 -6
- data/lib/sdbport/cli/purge.rb +15 -7
- data/lib/sdbport/config.rb +23 -0
- data/lib/sdbport/version.rb +1 -1
- data/spec/cli_spec.rb +50 -0
- data/spec/config_spec.rb +27 -0
- metadata +14 -9
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -17,6 +17,15 @@ export AWS_ACCESS_KEY_ID=key
|
|
17
17
|
export AWS_SECRET_ACCESS_KEY=secret
|
18
18
|
```
|
19
19
|
|
20
|
+
Or create a config file (-a and -s can then be ommited):
|
21
|
+
|
22
|
+
```
|
23
|
+
cat > ~/.sdbport.yml << EOF
|
24
|
+
access_key: your_aws_key
|
25
|
+
secret_key: your_aws_secert
|
26
|
+
EOF
|
27
|
+
```
|
28
|
+
|
20
29
|
Export SimpleDB domain:
|
21
30
|
|
22
31
|
```
|
data/lib/sdbport.rb
CHANGED
data/lib/sdbport/cli.rb
CHANGED
@@ -7,19 +7,25 @@ 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
|
+
|
10
16
|
def start
|
11
17
|
|
12
18
|
cmd = ARGV.shift
|
13
19
|
|
14
20
|
case cmd
|
15
21
|
when 'destroy'
|
16
|
-
CLI::Destroy.new.destroy
|
22
|
+
CLI::Destroy.new(@aws_default_creds).destroy
|
17
23
|
when 'export'
|
18
|
-
CLI::Export.new.export
|
24
|
+
CLI::Export.new(@aws_default_creds).export
|
19
25
|
when 'import'
|
20
|
-
CLI::Import.new.import
|
26
|
+
CLI::Import.new(@aws_default_creds).import
|
21
27
|
when 'purge'
|
22
|
-
CLI::Purge.new.purge
|
28
|
+
CLI::Purge.new(@aws_default_creds).purge
|
23
29
|
when '-v'
|
24
30
|
puts Sdbport::VERSION
|
25
31
|
else
|
data/lib/sdbport/cli/destroy.rb
CHANGED
@@ -2,15 +2,23 @@ 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]
|
8
|
+
end
|
9
|
+
|
5
10
|
def destroy
|
6
|
-
opts
|
11
|
+
opts = read_options
|
12
|
+
access_key = opts[:access_key] || @default_access_key
|
13
|
+
secret_key = opts[:secret_key] || @default_secret_key
|
14
|
+
|
7
15
|
logger = SdbportLogger.new :log_level => opts[:level]
|
8
|
-
domain = Domain.new :name
|
9
|
-
:region
|
10
|
-
:access_key
|
11
|
-
:secret_key
|
12
|
-
:logger
|
13
|
-
domain.destroy
|
16
|
+
domain = Domain.new :name => opts[:name],
|
17
|
+
:region => opts[:region],
|
18
|
+
:access_key => access_key,
|
19
|
+
:secret_key => secret_key,
|
20
|
+
:logger => logger
|
21
|
+
exit 1 unless domain.destroy
|
14
22
|
end
|
15
23
|
|
16
24
|
def read_options
|
data/lib/sdbport/cli/export.rb
CHANGED
@@ -2,17 +2,23 @@ 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]
|
8
|
+
end
|
9
|
+
|
5
10
|
def export
|
6
|
-
opts
|
11
|
+
opts = read_options
|
12
|
+
access_key = opts[:access_key] || @default_access_key
|
13
|
+
secret_key = opts[:secret_key] || @default_secret_key
|
14
|
+
|
7
15
|
logger = SdbportLogger.new :log_level => opts[:level]
|
8
16
|
domain = Domain.new :name => opts[:name],
|
9
17
|
:region => opts[:region],
|
10
|
-
:access_key =>
|
11
|
-
:secret_key =>
|
18
|
+
:access_key => access_key,
|
19
|
+
:secret_key => secret_key,
|
12
20
|
:logger => logger
|
13
|
-
unless domain.export opts[:output]
|
14
|
-
exit 1
|
15
|
-
end
|
21
|
+
exit 1 unless domain.export opts[:output]
|
16
22
|
end
|
17
23
|
|
18
24
|
def read_options
|
data/lib/sdbport/cli/import.rb
CHANGED
@@ -2,17 +2,23 @@ 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]
|
8
|
+
end
|
9
|
+
|
5
10
|
def import
|
6
|
-
opts
|
11
|
+
opts = read_options
|
12
|
+
access_key = opts[:access_key] || @default_access_key
|
13
|
+
secret_key = opts[:secret_key] || @default_secret_key
|
14
|
+
|
7
15
|
logger = SdbportLogger.new :log_level => opts[:level]
|
8
16
|
domain = Domain.new :name => opts[:name],
|
9
17
|
:region => opts[:region],
|
10
|
-
:access_key =>
|
11
|
-
:secret_key =>
|
18
|
+
:access_key => access_key,
|
19
|
+
:secret_key => secret_key,
|
12
20
|
:logger => logger
|
13
|
-
unless domain.import opts[:input]
|
14
|
-
exit 1
|
15
|
-
end
|
21
|
+
exit 1 unless domain.import opts[:input]
|
16
22
|
end
|
17
23
|
|
18
24
|
def read_options
|
data/lib/sdbport/cli/purge.rb
CHANGED
@@ -2,15 +2,23 @@ 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]
|
8
|
+
end
|
9
|
+
|
5
10
|
def purge
|
6
|
-
opts
|
11
|
+
opts = read_options
|
12
|
+
access_key = opts[:access_key] || @default_access_key
|
13
|
+
secret_key = opts[:secret_key] || @default_secret_key
|
14
|
+
|
7
15
|
logger = SdbportLogger.new :log_level => opts[:level]
|
8
|
-
domain = Domain.new :name
|
9
|
-
:region
|
10
|
-
:access_key
|
11
|
-
:secret_key
|
12
|
-
:logger
|
13
|
-
|
16
|
+
domain = Domain.new :name => opts[:name],
|
17
|
+
:region => opts[:region],
|
18
|
+
:access_key => access_key,
|
19
|
+
:secret_key => secret_key,
|
20
|
+
:logger => logger
|
21
|
+
exit 1 unless domain.purge
|
14
22
|
end
|
15
23
|
|
16
24
|
def read_options
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sdbport
|
2
|
+
class Config
|
3
|
+
|
4
|
+
attr_reader :access_key, :secret_key
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@config = load_config_file
|
8
|
+
@access_key = @config.fetch 'access_key', nil
|
9
|
+
@secret_key = @config.fetch 'secret_key', nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_config_file
|
13
|
+
config_file = "#{ENV['HOME']}/.sdbport.yml"
|
14
|
+
|
15
|
+
if File.exists? config_file
|
16
|
+
YAML::load File.open(config_file)
|
17
|
+
else
|
18
|
+
Hash.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/sdbport/version.rb
CHANGED
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sdbport/cli'
|
3
|
+
|
4
|
+
describe Sdbport do
|
5
|
+
before do
|
6
|
+
@cli_mock = mock 'cli'
|
7
|
+
@default_creds = { :access_key => 'the-key',
|
8
|
+
:secret_key => 'the-secret' }
|
9
|
+
@config_stub = stub 'config', :access_key => 'the-key',
|
10
|
+
:secret_key => 'the-secret'
|
11
|
+
Sdbport::Config.stub :new => @config_stub
|
12
|
+
@cli = Sdbport::CLI.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should call destroy" do
|
16
|
+
Sdbport::CLI::Destroy.should_receive(:new).
|
17
|
+
with(@default_creds).
|
18
|
+
and_return @cli_mock
|
19
|
+
ARGV.stub :shift => 'destroy'
|
20
|
+
@cli_mock.should_receive :destroy
|
21
|
+
@cli.start
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should call export" do
|
25
|
+
Sdbport::CLI::Export.should_receive(:new).
|
26
|
+
with(@default_creds).
|
27
|
+
and_return @cli_mock
|
28
|
+
ARGV.stub :shift => 'export'
|
29
|
+
@cli_mock.should_receive :export
|
30
|
+
@cli.start
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should call import" do
|
34
|
+
Sdbport::CLI::Import.should_receive(:new).
|
35
|
+
with(@default_creds).
|
36
|
+
and_return @cli_mock
|
37
|
+
ARGV.stub :shift => 'import'
|
38
|
+
@cli_mock.should_receive :import
|
39
|
+
@cli.start
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should call purge" do
|
43
|
+
Sdbport::CLI::Purge.should_receive(:new).
|
44
|
+
with(@default_creds).
|
45
|
+
and_return @cli_mock
|
46
|
+
ARGV.stub :shift => 'purge'
|
47
|
+
@cli_mock.should_receive :purge
|
48
|
+
@cli.start
|
49
|
+
end
|
50
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sdbport do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@config = { 'access_key ' => 'key',
|
7
|
+
'secret_key ' => 'secret' }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should create a new config object and read from ~/.sdbport.yml" do
|
11
|
+
File.stub :exists? => true
|
12
|
+
File.should_receive(:open).
|
13
|
+
with("#{ENV['HOME']}/.sdbport.yml").
|
14
|
+
and_return @config.to_yaml
|
15
|
+
config = Sdbport::Config.new
|
16
|
+
config.access_key.should == @config['access_key']
|
17
|
+
config.secret_key.should == @config['secret_key']
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should load a blank config if the file does not exist and no config passed" do
|
21
|
+
File.stub :exists? => false
|
22
|
+
config = Sdbport::Config.new
|
23
|
+
config.access_key.should be_nil
|
24
|
+
config.secret_key.should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
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.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-10-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70204089955280 !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: *
|
24
|
+
version_requirements: *70204089955280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fog
|
27
|
-
requirement: &
|
27
|
+
requirement: &70204089954700 !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: *
|
35
|
+
version_requirements: *70204089954700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: trollop
|
38
|
-
requirement: &
|
38
|
+
requirement: &70204089954220 !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: *
|
46
|
+
version_requirements: *70204089954220
|
47
47
|
description: Import and export AWS SimpleDB domains.
|
48
48
|
email:
|
49
49
|
- brett@weav.net
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/sdbport/cli/export.rb
|
70
70
|
- lib/sdbport/cli/import.rb
|
71
71
|
- lib/sdbport/cli/purge.rb
|
72
|
+
- lib/sdbport/config.rb
|
72
73
|
- lib/sdbport/domain.rb
|
73
74
|
- lib/sdbport/domain/destroy.rb
|
74
75
|
- lib/sdbport/domain/export.rb
|
@@ -78,6 +79,8 @@ files:
|
|
78
79
|
- lib/sdbport/version.rb
|
79
80
|
- sdbport.gemspec
|
80
81
|
- spec/aws/simpledb_spec.rb
|
82
|
+
- spec/cli_spec.rb
|
83
|
+
- spec/config_spec.rb
|
81
84
|
- spec/domain/destroy_spec.rb
|
82
85
|
- spec/domain/export_spec.rb
|
83
86
|
- spec/domain/import_spec.rb
|
@@ -99,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
102
|
version: '0'
|
100
103
|
segments:
|
101
104
|
- 0
|
102
|
-
hash:
|
105
|
+
hash: 227852682613598022
|
103
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
107
|
none: false
|
105
108
|
requirements:
|
@@ -108,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
111
|
version: '0'
|
109
112
|
segments:
|
110
113
|
- 0
|
111
|
-
hash:
|
114
|
+
hash: 227852682613598022
|
112
115
|
requirements: []
|
113
116
|
rubyforge_project:
|
114
117
|
rubygems_version: 1.8.16
|
@@ -117,6 +120,8 @@ specification_version: 3
|
|
117
120
|
summary: Import and export AWS SimpleDB domains.
|
118
121
|
test_files:
|
119
122
|
- spec/aws/simpledb_spec.rb
|
123
|
+
- spec/cli_spec.rb
|
124
|
+
- spec/config_spec.rb
|
120
125
|
- spec/domain/destroy_spec.rb
|
121
126
|
- spec/domain/export_spec.rb
|
122
127
|
- spec/domain/import_spec.rb
|