rack2aws 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/rack2aws.rb +29 -14
- data/lib/rack2aws/colorizer.rb +23 -0
- data/lib/rack2aws/config.rb +7 -8
- data/lib/rack2aws/logger.rb +24 -0
- data/lib/rack2aws/version.rb +1 -1
- metadata +51 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea0008457829bc7e98f35545a31e64cc51be0b4
|
4
|
+
data.tar.gz: 069002f7d1973c702dcd20446ae8297ad4c57f5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1aee03e5fedf609c2f110c51a590ecc2fbdcf23365624fe7625f894a2bad711c43c4f537d65acf24956bff9ea8be39c5048a7f711e6ab0eeee9965db86deac7
|
7
|
+
data.tar.gz: 39f110bba678f6e60e48c682009a7dc9ed74604fe81a6428871ea983a6b03fb323636d9b34ace726dbffc27d0e62507463bcfd5af8babef4413779b8d890fecc
|
data/lib/rack2aws.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
require 'fog'
|
2
2
|
require 'commander'
|
3
3
|
require 'rack2aws/config'
|
4
|
+
require 'rack2aws/logger'
|
4
5
|
require 'rack2aws/version'
|
5
6
|
require 'rack2aws/processor_count'
|
6
7
|
|
7
|
-
|
8
8
|
module Rack2Aws
|
9
9
|
class FileManager
|
10
10
|
include Rack2Aws::Configuration
|
11
11
|
|
12
|
-
attr_reader :per_page, :rackspace, :aws,
|
12
|
+
attr_reader :per_page, :rackspace, :aws,
|
13
|
+
:rackspace_directory, :aws_directory, :nproc,
|
14
|
+
:verbose_mode, :files, :total, :allow_public
|
13
15
|
|
14
16
|
def initialize(options={})
|
15
17
|
options = default_options.merge(options)
|
16
18
|
@per_page = options[:per_page]
|
17
19
|
@rackspace = Fog::Storage.new(RackspaceConfig.load())
|
18
20
|
@aws = Fog::Storage.new(AWSConfig.load())
|
19
|
-
|
20
|
-
@
|
21
|
-
@aws_directory = aws.directories.get(options[:aws_bucket])
|
21
|
+
@rackspace_directory = rackspace.directories.get(options[:container])
|
22
|
+
@aws_directory = aws.directories.get(options[:bucket])
|
22
23
|
@nproc = options[:nproc]
|
24
|
+
@allow_public = options[:public]
|
23
25
|
@verbose_mode = options[:verbose]
|
24
26
|
@files = []
|
25
27
|
@total = 0
|
26
28
|
end
|
27
29
|
|
28
30
|
def default_options
|
29
|
-
{ :per_page => 10000 }
|
31
|
+
{ :per_page => 10000, :public => false, :verbose => false }
|
30
32
|
end
|
31
33
|
|
32
34
|
def copy
|
@@ -86,22 +88,26 @@ module Rack2Aws
|
|
86
88
|
aws_directory.files.create(:key => file.key,
|
87
89
|
:body => file.body,
|
88
90
|
:content_type => file,
|
89
|
-
:public =>
|
91
|
+
:public => allow_public)
|
90
92
|
end
|
91
93
|
|
92
94
|
private :copy_files, :copy_file
|
93
95
|
end
|
94
96
|
|
95
97
|
class CLI
|
98
|
+
include Rack2Aws::Logger
|
96
99
|
include Commander::Methods
|
97
100
|
include Rack2Aws::ProcessorCount
|
98
101
|
|
99
102
|
def run
|
100
103
|
program :name, 'rack2aws'
|
101
104
|
program :version, Rack2Aws::VERSION
|
102
|
-
program :description, '
|
105
|
+
program :description, 'Teleport your files from Rackspace Cloud Files to AWS S3'
|
103
106
|
program :help, 'Author', 'Faissal Elamraoui <amr.faissal@gmail.com>'
|
104
107
|
|
108
|
+
# Show welcome message
|
109
|
+
show_welcome()
|
110
|
+
|
105
111
|
global_option('--verbose', 'Explain what is being done') { $verbose = true }
|
106
112
|
|
107
113
|
command :port do |cmd|
|
@@ -111,6 +117,7 @@ module Rack2Aws
|
|
111
117
|
cmd.option '--container CONTAINER_NAME', String, 'Rackspace Cloud Files container name'
|
112
118
|
cmd.option '--bucket BUCKET_NAME', String, 'AWS S3 bucket name'
|
113
119
|
cmd.option '--nproc NUM_PROC', Integer, 'Number of processes to fork'
|
120
|
+
cmd.option '--public', 'Whether files should be uploaded as public'
|
114
121
|
cmd.action do |args, options|
|
115
122
|
if options.container.nil?
|
116
123
|
options.container = ask('Rackspace Cloud Files container: ')
|
@@ -124,12 +131,20 @@ module Rack2Aws
|
|
124
131
|
options.nproc = processor_count()
|
125
132
|
end
|
126
133
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
134
|
+
if !options.public.nil?
|
135
|
+
options.public = if agree(warn("Are you sure you want your files uploaded as public?"))
|
136
|
+
true
|
137
|
+
else
|
138
|
+
nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
options.verbose = !options.verbose.nil? ? true : nil
|
143
|
+
|
144
|
+
# Remove all nil values from options' __hash__ table
|
145
|
+
options.__hash__.delete_if{ |k,v| v.nil? }
|
146
|
+
|
147
|
+
FileManager.new(options.__hash__).copy
|
133
148
|
end
|
134
149
|
end
|
135
150
|
run!
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class String
|
2
|
+
def black; "\e[30m#{self}\e[0m" end
|
3
|
+
def red; "\e[31m#{self}\e[0m" end
|
4
|
+
def green; "\e[32m#{self}\e[0m" end
|
5
|
+
def brown; "\e[33m#{self}\e[0m" end
|
6
|
+
def blue; "\e[34m#{self}\e[0m" end
|
7
|
+
def magenta; "\e[35m#{self}\e[0m" end
|
8
|
+
def cyan; "\e[36m#{self}\e[0m" end
|
9
|
+
def gray; "\e[37m#{self}\e[0m" end
|
10
|
+
def bg_black; "\e[40m#{self}\e[0m" end
|
11
|
+
def bg_red; "\e[41m#{self}\e[0m" end
|
12
|
+
def bg_green; "\e[42m#{self}\e[0m" end
|
13
|
+
def bg_brown; "\e[43m#{self}\e[0m" end
|
14
|
+
def bg_blue; "\e[44m#{self}\e[0m" end
|
15
|
+
def bg_magenta; "\e[45m#{self}\e[0m" end
|
16
|
+
def bg_cyan; "\e[46m#{self}\e[0m" end
|
17
|
+
def bg_gray; "\e[47m#{self}\e[0m" end
|
18
|
+
def bold; "\e[1m#{self}\e[22m" end
|
19
|
+
def italic; "\e[3m#{self}\e[23m" end
|
20
|
+
def underline; "\e[4m#{self}\e[24m" end
|
21
|
+
def blink; "\e[5m#{self}\e[25m" end
|
22
|
+
def reverse_color; "\e[7m#{self}\e[27m" end
|
23
|
+
end
|
data/lib/rack2aws/config.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rack2aws/props_reader'
|
2
2
|
require 'rack2aws/errors'
|
3
3
|
|
4
|
-
|
5
4
|
# Class to parse configuration files in the format of "param = value".
|
6
5
|
class KVConfigParser
|
7
6
|
attr_accessor :config_file, :params, :groups
|
@@ -149,13 +148,13 @@ module Rack2Aws
|
|
149
148
|
|
150
149
|
class RackspaceConfig
|
151
150
|
def self.load()
|
152
|
-
config_path
|
151
|
+
@config_path ||= "#{ENV['HOME']}/.rack/config"
|
153
152
|
|
154
|
-
if !File.exist?(config_path)
|
153
|
+
if !File.exist?(@config_path)
|
155
154
|
raise FileNotFoundError, "Rackspace configuration file not found"
|
156
155
|
end
|
157
156
|
|
158
|
-
props_reader = PropertiesReader.new(config_path)
|
157
|
+
props_reader = PropertiesReader.new(@config_path)
|
159
158
|
return {
|
160
159
|
:provider => 'Rackspace',
|
161
160
|
:rackspace_api_key => props_reader.get("api-key"),
|
@@ -167,13 +166,13 @@ module Rack2Aws
|
|
167
166
|
|
168
167
|
class AWSConfig
|
169
168
|
def self.load()
|
170
|
-
config_path
|
169
|
+
@config_path ||= "#{ENV['HOME']}/.aws/credentials"
|
171
170
|
|
172
|
-
if !File.exist?(config_path)
|
173
|
-
raise FileNotFoundError, "
|
171
|
+
if !File.exist?(@config_path)
|
172
|
+
raise FileNotFoundError, "AWS configuration file not found"
|
174
173
|
end
|
175
174
|
|
176
|
-
credentials = KVConfigParser.new(config_path)
|
175
|
+
credentials = KVConfigParser.new(@config_path)
|
177
176
|
return {
|
178
177
|
:provider => 'AWS',
|
179
178
|
:region => credentials['default']['region'],
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'artii'
|
2
|
+
require 'rack2aws/version'
|
3
|
+
require 'rack2aws/colorizer'
|
4
|
+
|
5
|
+
module Rack2Aws
|
6
|
+
module Logger
|
7
|
+
|
8
|
+
def show_welcome
|
9
|
+
welcome_art = Artii::Base.new
|
10
|
+
$stdout.puts "##############################################################".bold.blue
|
11
|
+
output = welcome_art.asciify("Rack2Aws").bold.blue
|
12
|
+
output << "v#{Rack2Aws::VERSION} (>o<)".bold.blue
|
13
|
+
$stdout.puts output
|
14
|
+
$stdout.puts "#############################################################".bold.blue
|
15
|
+
end
|
16
|
+
|
17
|
+
def warn(msg)
|
18
|
+
output = "WARNING: ".bold
|
19
|
+
output << msg
|
20
|
+
output.brown
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/rack2aws/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack2aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faissal Elamraoui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.4'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 4.4.0
|
20
23
|
type: :runtime
|
@@ -22,6 +25,9 @@ dependencies:
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.4'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: 4.4.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +35,9 @@ dependencies:
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.37'
|
40
|
+
- - ">="
|
32
41
|
- !ruby/object:Gem::Version
|
33
42
|
version: 1.37.0
|
34
43
|
type: :runtime
|
@@ -36,8 +45,31 @@ dependencies:
|
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
47
|
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.37'
|
50
|
+
- - ">="
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: 1.37.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: artii
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.1'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.1.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.1'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.1.1
|
41
73
|
- !ruby/object:Gem::Dependency
|
42
74
|
name: bundler
|
43
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +98,20 @@ dependencies:
|
|
66
98
|
- - "~>"
|
67
99
|
- !ruby/object:Gem::Version
|
68
100
|
version: '10.0'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: rspec
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '3.4'
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '3.4'
|
69
115
|
description:
|
70
116
|
email:
|
71
117
|
- amr.faissal@gmail.com
|
@@ -76,8 +122,10 @@ extra_rdoc_files: []
|
|
76
122
|
files:
|
77
123
|
- bin/rack2aws
|
78
124
|
- lib/rack2aws.rb
|
125
|
+
- lib/rack2aws/colorizer.rb
|
79
126
|
- lib/rack2aws/config.rb
|
80
127
|
- lib/rack2aws/errors.rb
|
128
|
+
- lib/rack2aws/logger.rb
|
81
129
|
- lib/rack2aws/processor_count.rb
|
82
130
|
- lib/rack2aws/props_reader.rb
|
83
131
|
- lib/rack2aws/version.rb
|
@@ -104,5 +152,5 @@ rubyforge_project:
|
|
104
152
|
rubygems_version: 2.5.1
|
105
153
|
signing_key:
|
106
154
|
specification_version: 4
|
107
|
-
summary:
|
155
|
+
summary: Teleport your files from Rackspace Cloud Files to AWS S3
|
108
156
|
test_files: []
|