s3_dir 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/lib/s3_dir/version.rb +3 -0
- data/lib/s3_dir.rb +76 -0
- data/s3_dir.gemspec +26 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a17c51ae36e976e230825df8db63b8b29ff2a01
|
4
|
+
data.tar.gz: c9135601df89eb46385f1d079fb67f6a51a59e63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0ab809198e1182d1ef12ec2940372f8be210a7a7d40316ac7680ef19e1f523e6abaf3f83a41606134a85b0198d168ece6b324b8363b5bc40c1295841fa2ee8c
|
7
|
+
data.tar.gz: 9d033deadc24d90f77a3ed7bf36a2041d29afcf2ad6b0a86284ed3793532b158a689cb380912ef67cb1ae6b0c82bd6e1c49fc79888d83ee8dd05fbd11ebb0022
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 nuex
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
S3Dir
|
2
|
+
=====
|
3
|
+
|
4
|
+
Quickly upload a directory and its contents to s3.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 's3_dir'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
You'll need to configure your `fog` AWS credentials in `~/.fog`:
|
17
|
+
|
18
|
+
:aws_credentials:
|
19
|
+
:aws_access_key_id: AWS_ACCESS_KEY
|
20
|
+
:aws_secret_access_key: AWS_SECRET_ACCESS_KEY
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
require 's3_dir'
|
25
|
+
|
26
|
+
path = '/path/to/upload'
|
27
|
+
bucket = 'mybucket'
|
28
|
+
S3Dir.upload(path, bucket, credential: :aws_credentials)
|
29
|
+
|
30
|
+
### Configuration Options
|
31
|
+
|
32
|
+
`credential` default ENV['FOG_CREDENTIAL']
|
33
|
+
Namespace for AWS credentials in the `.fog` file
|
34
|
+
|
35
|
+
`private` default false
|
36
|
+
Setting private to true will make the bucket and all
|
37
|
+
of its contents not public.
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/s3_dir.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative 's3_dir/version'
|
2
|
+
require 'fog/aws/storage'
|
3
|
+
|
4
|
+
# S3Dir uploads files to S3
|
5
|
+
#
|
6
|
+
# S3Dir assumes your credentials are in `~/.fog`. Pass
|
7
|
+
# the credential argument with the namespace of your
|
8
|
+
# credentials in the `.fog` file.
|
9
|
+
#
|
10
|
+
# ## Usage:
|
11
|
+
#
|
12
|
+
# require 's3_dir'
|
13
|
+
#
|
14
|
+
# dir = '/path/to/upload'
|
15
|
+
# bucket = 's3-website.com'
|
16
|
+
#
|
17
|
+
# S3Dir.upload(dir, bucket, credential: :s3-website)
|
18
|
+
#
|
19
|
+
# Options include:
|
20
|
+
#
|
21
|
+
# `credential` default ENV['FOG_CREDENTIAL']
|
22
|
+
# Namespace for AWS credentials in the `.fog` file
|
23
|
+
#
|
24
|
+
# `private` default false
|
25
|
+
# Setting private to true will make the bucket and all
|
26
|
+
# of its contents not public.
|
27
|
+
#
|
28
|
+
module S3Dir
|
29
|
+
# Upload files to S3
|
30
|
+
def self.upload dir, key, options={}
|
31
|
+
files_path = File.expand_path(dir)
|
32
|
+
|
33
|
+
# Merge defaults with passed-in options
|
34
|
+
settings = {credential: ENV['FOG_CREDENTIAL'],
|
35
|
+
private: false}.merge(options)
|
36
|
+
|
37
|
+
# We have to manually extract fog credentials here
|
38
|
+
# because we'll need those settings when creating a new
|
39
|
+
# Fog::Storage object with custom settings
|
40
|
+
all_credentials = YAML::load_file(File.join(ENV['HOME'], '.fog'))
|
41
|
+
credential = settings[:credential]
|
42
|
+
credentials = all_credentials[credential]
|
43
|
+
access_key = credentials[:aws_access_key_id]
|
44
|
+
secret_key = credentials[:aws_secret_access_key]
|
45
|
+
region = credentials[:region] || 'us-west-2'
|
46
|
+
|
47
|
+
# If we don't specify this endpoint, Fog will complain about
|
48
|
+
# not using the correct endpoint if the bucket has dots in
|
49
|
+
# the name (i.e. website bucket)
|
50
|
+
endpoint = 'http://s3.amazonaws.com'
|
51
|
+
|
52
|
+
# This may be a public bucket
|
53
|
+
is_public = !settings[:private]
|
54
|
+
|
55
|
+
# Set up our storage object
|
56
|
+
# We have to specify path_style here because Fog will complain about
|
57
|
+
# our website bucket (if we're using a bucket with dots in the name)
|
58
|
+
# not being covered by the SSL certificate.
|
59
|
+
storage = Fog::Storage.new(provider: 'aws', aws_access_key_id: access_key,
|
60
|
+
aws_secret_access_key: secret_key,
|
61
|
+
path_style: true, region: region,
|
62
|
+
endpoint: endpoint)
|
63
|
+
bucket = storage.directories.get(key)
|
64
|
+
bucket ||= storage.directories.create(key: key, public: is_public)
|
65
|
+
|
66
|
+
Dir.chdir(files_path) do
|
67
|
+
Dir['**/*'].each do |entry|
|
68
|
+
if File.directory?(entry)
|
69
|
+
bucket.files.create(key: entry, public: is_public)
|
70
|
+
else
|
71
|
+
bucket.files.create(key: entry, public: is_public, body: File.open(entry))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/s3_dir.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 's3_dir/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "s3_dir"
|
8
|
+
spec.version = S3Dir::VERSION
|
9
|
+
spec.authors = ["nuex"]
|
10
|
+
spec.email = ["nx@nu-ex.com"]
|
11
|
+
spec.description = %q{Upload a directory to AWS S3}
|
12
|
+
spec.summary = %q{Uploads a directory of files to an AWS S3 bucket}
|
13
|
+
spec.homepage = "https://github.com/nuex/s3_dir"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'unf', '~> 0.1.3'
|
25
|
+
spec.add_dependency 'fog', '~> 1.17.0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: s3_dir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nuex
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: unf
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fog
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.17.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.17.0
|
69
|
+
description: Upload a directory to AWS S3
|
70
|
+
email:
|
71
|
+
- nx@nu-ex.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/s3_dir.rb
|
82
|
+
- lib/s3_dir/version.rb
|
83
|
+
- s3_dir.gemspec
|
84
|
+
homepage: https://github.com/nuex/s3_dir
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.1.11
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Uploads a directory of files to an AWS S3 bucket
|
108
|
+
test_files: []
|
109
|
+
has_rdoc:
|