jaxx 0.0.4 → 0.0.6
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/README.md +53 -2
- data/lib/jaxx.rb +4 -1
- data/lib/jaxx/cli.rb +2 -2
- data/lib/jaxx/download.rb +1 -1
- data/lib/jaxx/environment.rb +10 -28
- data/lib/jaxx/process.rb +8 -9
- data/lib/jaxx/version.rb +1 -1
- data/spec/helpers/service.rb +5 -3
- data/spec/lib/jaxx/environment_spec.rb +2 -21
- data/spec/lib/jaxx/process_spec.rb +0 -2
- data/spec/spec_helper.rb +4 -3
- metadata +5 -5
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Jaxx
|
2
2
|
|
3
|
-
|
3
|
+
Upload and Download files from S3.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,58 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Upload
|
22
|
+
```
|
23
|
+
jaxx-upload -h
|
24
|
+
jaxx [options]
|
25
|
+
-b, --bucket [BUCKET]
|
26
|
+
-k, --access-key [ACCESS_KEY]
|
27
|
+
-s [ACCESS_SECRET],
|
28
|
+
--access-secret
|
29
|
+
-f, --file [FILE]
|
30
|
+
-p, --privacy [PRIVACY]
|
31
|
+
-h, --help
|
32
|
+
```
|
33
|
+
|
34
|
+
### Download
|
35
|
+
```
|
36
|
+
jaxx-download -h
|
37
|
+
jaxx [options]
|
38
|
+
-b, --bucket [BUCKET]
|
39
|
+
-k, --access-key [ACCESS_KEY]
|
40
|
+
-s [ACCESS_SECRET],
|
41
|
+
--access-secret
|
42
|
+
-f, --file [FILE]
|
43
|
+
-p, --privacy [PRIVACY]
|
44
|
+
-h, --help
|
45
|
+
```
|
46
|
+
|
47
|
+
## Examples
|
48
|
+
|
49
|
+
### Upload from local machine
|
50
|
+
```
|
51
|
+
jaxx-upload -b test-bucket -f vapour.txt -k MY_KEY -s MY_SECRET
|
52
|
+
```
|
53
|
+
|
54
|
+
### Download to local machine
|
55
|
+
```
|
56
|
+
jaxx-download -b test-bucket -f vapour.txt -k MY_KEY -s MY_SECRET
|
57
|
+
```
|
58
|
+
|
59
|
+
### Upload to S3 from AWS Instance
|
60
|
+
```
|
61
|
+
jaxx-upload -b test-bucket -f vapour.txt
|
62
|
+
```
|
63
|
+
|
64
|
+
### Download from S3 to current folder from AWS Instance
|
65
|
+
```
|
66
|
+
jaxx-download -b test-bucket -f vapour.txt
|
67
|
+
```
|
68
|
+
|
69
|
+
### Upload from local machine, and make it publicly available
|
70
|
+
```
|
71
|
+
jaxx-upload -b test-bucket -f vapour.txt -k MY_KEY -s MY_SECRET -p public
|
72
|
+
```
|
22
73
|
|
23
74
|
## Contributing
|
24
75
|
|
data/lib/jaxx.rb
CHANGED
data/lib/jaxx/cli.rb
CHANGED
@@ -6,7 +6,7 @@ module Jaxx
|
|
6
6
|
|
7
7
|
def self.execute meth, args
|
8
8
|
parser.parse!(args)
|
9
|
-
options.empty? ? (
|
9
|
+
options.empty? ? (Jaxx.logger.write(parser) and exit) : Jaxx.send(meth, options)
|
10
10
|
rescue RuntimeError => exc
|
11
11
|
exit 1
|
12
12
|
end
|
@@ -20,7 +20,7 @@ module Jaxx
|
|
20
20
|
o.on('-s', '--access-secret [ACCESS_SECRET]') { |s| options['access_secret'] = s }
|
21
21
|
o.on('-f', '--file [FILE]') { |f| options['file'] = f }
|
22
22
|
o.on('-p', '--privacy [PRIVACY]') { |p| options['privacy'] = p }
|
23
|
-
o.on('-h', '--help') {
|
23
|
+
o.on('-h', '--help') { o }
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
data/lib/jaxx/download.rb
CHANGED
@@ -16,7 +16,7 @@ module Jaxx
|
|
16
16
|
directory.files.get(process.file) do |chunk, byt_remain, byt_total|
|
17
17
|
file.write(chunk)
|
18
18
|
complete = (((byt_total-byt_remain).to_f/byt_total) * 100)
|
19
|
-
Jaxx.logger.
|
19
|
+
Jaxx.logger.write "Saving file: %.2f percent complete.\r" % complete
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/jaxx/environment.rb
CHANGED
@@ -2,46 +2,28 @@ require 'timeout'
|
|
2
2
|
require 'socket'
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
+
require 'timeout'
|
6
|
+
require 'fog'
|
5
7
|
|
6
8
|
module Jaxx
|
7
9
|
class Environment
|
8
10
|
|
9
|
-
DEFAULT_ARGS = {
|
10
|
-
|
11
|
-
'service_path' => '/latest/meta-data/iam/security-credentials/default',
|
12
|
-
'service_timeout' => 1
|
13
|
-
}
|
11
|
+
DEFAULT_ARGS = { 'service_timeout' => 1 }
|
12
|
+
DEFAULT_CREDENTIALS = { :aws_access_key_id => "", :aws_secret_access_key => "", :aws_session_token => nil, :use_iam_profile => true }
|
14
13
|
|
15
|
-
attr_reader :
|
14
|
+
attr_reader :service_timeout
|
16
15
|
|
17
16
|
def initialize args = {}
|
18
|
-
@
|
19
|
-
end
|
20
|
-
|
21
|
-
def ami?
|
22
|
-
credentials[:code] == 'Success'
|
17
|
+
@service_timeout = DEFAULT_ARGS.dup.merge(args).delete('service_timeout')
|
23
18
|
end
|
24
19
|
|
25
20
|
def credentials
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@credentials = {
|
31
|
-
:access_key => response['AccessKeyId'],
|
32
|
-
:access_secret => response['SecretAccessKey'],
|
33
|
-
:code => response['Code']
|
34
|
-
}
|
21
|
+
Timeout::timeout(service_timeout) do
|
22
|
+
DEFAULT_CREDENTIALS.merge Fog::Compute::AWS.fetch_credentials(:use_iam_profile => true)
|
23
|
+
end
|
35
24
|
rescue Errno::EHOSTDOWN, Errno::EHOSTUNREACH, Timeout::Error => exc
|
36
|
-
|
25
|
+
DEFAULT_CREDENTIALS
|
37
26
|
end
|
38
27
|
|
39
|
-
private
|
40
|
-
|
41
|
-
def credential_response
|
42
|
-
http = Net::HTTP.new service_domain
|
43
|
-
http.open_timeout = http.read_timeout = service_timeout
|
44
|
-
JSON.parse http.get(service_path).body
|
45
|
-
end
|
46
28
|
end
|
47
29
|
end
|
data/lib/jaxx/process.rb
CHANGED
@@ -28,17 +28,18 @@ module Jaxx
|
|
28
28
|
return @credentials unless @credentials.nil?
|
29
29
|
|
30
30
|
key, secret = access_key.to_s, access_secret.to_s
|
31
|
-
if
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
@credentials = if key.empty? or secret.empty?
|
32
|
+
Jaxx.environment.credentials
|
33
|
+
else
|
34
|
+
{ :aws_access_key_id => key, :aws_secret_access_key => secret, :aws_session_token => "" }
|
35
|
+
end.merge(:use_iam_profile => true)
|
35
36
|
end
|
36
37
|
|
37
38
|
def start &block
|
38
39
|
errs = errors
|
39
40
|
|
40
41
|
["Unable to process transaction", format_errors(errs)].flatten.each do |msg|
|
41
|
-
Jaxx.logger.
|
42
|
+
Jaxx.logger.write msg
|
42
43
|
end and raise(RuntimeError) unless errs.empty?
|
43
44
|
|
44
45
|
block.call(storage)
|
@@ -57,9 +58,7 @@ module Jaxx
|
|
57
58
|
private
|
58
59
|
|
59
60
|
def storage
|
60
|
-
@storage ||= Fog::Storage::AWS.new
|
61
|
-
:aws_secret_access_key => credentials[:access_secret],
|
62
|
-
:use_iam_profile => Jaxx.environment.ami?
|
61
|
+
@storage ||= Fog::Storage::AWS.new credentials
|
63
62
|
end
|
64
63
|
|
65
64
|
def validate_bucket
|
@@ -75,7 +74,7 @@ module Jaxx
|
|
75
74
|
end
|
76
75
|
|
77
76
|
def validate_credentials
|
78
|
-
"for access key and access secret required" if credentials[:
|
77
|
+
"for access key and access secret required" if credentials[:aws_access_key_id].empty? or credentials[:aws_secret_access_key].empty?
|
79
78
|
end
|
80
79
|
|
81
80
|
def validate_privacy
|
data/lib/jaxx/version.rb
CHANGED
data/spec/helpers/service.rb
CHANGED
@@ -3,9 +3,11 @@ require 'fakeweb'
|
|
3
3
|
module ServiceHelper
|
4
4
|
|
5
5
|
def stub_credentials_service
|
6
|
-
|
7
|
-
|
8
|
-
:
|
6
|
+
Fog::Compute::AWS.stub(:fetch_credentials).and_return({
|
7
|
+
:aws_access_key_id => 'foo',
|
8
|
+
:aws_secret_access_key => 'bar',
|
9
|
+
:aws_session_token => 'foobar'
|
10
|
+
})
|
9
11
|
end
|
10
12
|
|
11
13
|
end
|
@@ -3,41 +3,22 @@ require 'spec_helper'
|
|
3
3
|
module Jaxx
|
4
4
|
describe Environment do
|
5
5
|
|
6
|
-
it "#service_domain" do
|
7
|
-
subject.service_domain.should_not be_nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it "#service_path" do
|
11
|
-
subject.service_path.should_not be_nil
|
12
|
-
end
|
13
|
-
|
14
6
|
it "#service_timeout" do
|
15
7
|
subject.service_timeout.should_not be_nil
|
16
8
|
end
|
17
9
|
|
18
10
|
context "outside ami instance" do
|
19
11
|
|
20
|
-
it "#ami?" do
|
21
|
-
subject.ami?.should be_false
|
22
|
-
end
|
23
|
-
|
24
12
|
it "#credentials" do
|
25
13
|
subject.credentials.should be_kind_of(Hash)
|
26
|
-
subject.credentials[:
|
14
|
+
subject.credentials[:aws_session_token].should be_nil
|
27
15
|
end
|
28
16
|
end
|
29
17
|
|
30
18
|
context "within ami instance" do
|
31
19
|
|
32
|
-
before :each do
|
33
|
-
stub_credentials_service
|
34
|
-
end
|
35
|
-
|
36
|
-
it "#ami?" do
|
37
|
-
subject.ami?.should be_true
|
38
|
-
end
|
39
|
-
|
40
20
|
it "#credentials" do
|
21
|
+
stub_credentials_service
|
41
22
|
subject.credentials.should be_kind_of(Hash)
|
42
23
|
end
|
43
24
|
end
|
@@ -16,8 +16,6 @@ module Jaxx
|
|
16
16
|
described_class.new.errors.should include(:bucket => 'is required')
|
17
17
|
end
|
18
18
|
|
19
|
-
it "raises error on local authentication, when not on AMI"
|
20
|
-
|
21
19
|
it "accepts access key" do
|
22
20
|
described_class.new('access_key' => 'abc').access_key.should == 'abc'
|
23
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,11 +5,12 @@ $:.unshift File.expand_path('../lib', __FILE__)
|
|
5
5
|
require 'jaxx'
|
6
6
|
require 'rspec'
|
7
7
|
|
8
|
-
|
8
|
+
Jaxx.logger StringIO.new
|
9
|
+
|
9
10
|
|
10
|
-
|
11
|
+
require_relative 'helpers/service'
|
11
12
|
|
12
13
|
RSpec.configure do |c|
|
13
|
-
c.include ServiceHelper
|
14
|
+
c.include ServiceHelper
|
14
15
|
c.after(:each) { FakeWeb.clean_registry }
|
15
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jaxx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -206,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
206
|
version: '0'
|
207
207
|
segments:
|
208
208
|
- 0
|
209
|
-
hash: -
|
209
|
+
hash: -1531357280253582986
|
210
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
211
|
none: false
|
212
212
|
requirements:
|
@@ -215,10 +215,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
segments:
|
217
217
|
- 0
|
218
|
-
hash: -
|
218
|
+
hash: -1531357280253582986
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
|
-
rubygems_version: 1.8.
|
221
|
+
rubygems_version: 1.8.25
|
222
222
|
signing_key:
|
223
223
|
specification_version: 3
|
224
224
|
summary: RubyGems to allow any file to be pushed to S3 in the simplist way
|