nightcrawler_swift 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +7 -0
- data/Gemfile.lock +7 -5
- data/README.md +1 -1
- data/lib/nightcrawler_swift/cli/opt_parser.rb +7 -0
- data/lib/nightcrawler_swift/cli/runner.rb +18 -6
- data/lib/nightcrawler_swift/ext/hash.rb +24 -22
- data/lib/nightcrawler_swift/ext/nil_class.rb +15 -0
- data/lib/nightcrawler_swift/ext/open_struct.rb +15 -0
- data/lib/nightcrawler_swift/gateway.rb +4 -1
- data/lib/nightcrawler_swift/version.rb +1 -1
- data/lib/nightcrawler_swift.rb +2 -0
- data/nightcrawler_swift.gemspec +6 -1
- data/spec/lib/nightcrawler_swift/cli/opt_parser_spec.rb +10 -0
- data/spec/lib/nightcrawler_swift/cli/runner_spec.rb +45 -2
- data/spec/lib/nightcrawler_swift/connection_spec.rb +3 -1
- data/spec/lib/nightcrawler_swift/ext/hash_spec.rb +1 -1
- data/spec/lib/nightcrawler_swift/ext/nil_class_spec.rb +15 -0
- data/spec/lib/nightcrawler_swift/ext/open_struct_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8ef6b380623f8ce83cfea1491c10c44bfc8ed04
|
4
|
+
data.tar.gz: 9df2abbd80c6f1fceedf2dddc58d59be45e33520
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fdf97c07f42e76d5b83941b2f95d8cb32270bba360369c0b28547a25151ad56290aad0ea5ecfb076d1c012fb5abf4a331c579f216ed815dd342f9f5addf97d5
|
7
|
+
data.tar.gz: 9f2d5e258abc3f309cc57759a81938041ddf8ec49111276e3b4ee3bf6120edf527c875a01715b28a030aa970c508d5dbbfb185d702dd2d354e068cba11d6eff3
|
data/Changelog.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.7.0
|
4
|
+
|
5
|
+
- CLI now supports ```--no-cache``` which ignores the cached connection and removes the cache file if it exists (issue #12)
|
6
|
+
- Bugfix: invalidate nswift_cache when the connection fail (issue #27)
|
7
|
+
- Bugfix: OpenStruct in Ruby 1.9.x doesn't have the method [], using 'send' instead
|
8
|
+
- Bugfix: OpenStruct and nil doesn't have the method to_h in Ruby 1.9.x
|
9
|
+
|
3
10
|
## 0.6.0
|
4
11
|
|
5
12
|
- Upload command allows a custom max-age (issue #23)
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nightcrawler_swift (0.
|
4
|
+
nightcrawler_swift (0.7.0)
|
5
5
|
multi_mime (>= 1.0.1)
|
6
6
|
rest-client
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
byebug (3.
|
11
|
+
byebug (3.5.1)
|
12
12
|
columnize (~> 0.8)
|
13
13
|
debugger-linecache (~> 1.2)
|
14
|
+
slop (~> 3.6)
|
14
15
|
codeclimate-test-reporter (0.4.0)
|
15
16
|
simplecov (>= 0.7.1, < 1.0.0)
|
16
|
-
columnize (0.
|
17
|
+
columnize (0.9.0)
|
17
18
|
debugger-linecache (1.2.0)
|
18
19
|
diff-lcs (1.2.5)
|
19
20
|
docile (1.1.5)
|
20
|
-
mime-types (2.3)
|
21
|
+
mime-types (2.4.3)
|
21
22
|
multi_json (1.10.1)
|
22
23
|
multi_mime (1.0.1)
|
23
|
-
netrc (0.
|
24
|
+
netrc (0.10.2)
|
24
25
|
rake (10.3.2)
|
25
26
|
rest-client (1.7.2)
|
26
27
|
mime-types (>= 1.16, < 3.0)
|
@@ -42,6 +43,7 @@ GEM
|
|
42
43
|
multi_json
|
43
44
|
simplecov-html (~> 0.8.0)
|
44
45
|
simplecov-html (0.8.0)
|
46
|
+
slop (3.6.0)
|
45
47
|
|
46
48
|
PLATFORMS
|
47
49
|
ruby
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Nightcrawler Swift [![Code Climate](https://codeclimate.com/github/tulios/nightcrawler_swift/badges/gpa.svg)](https://codeclimate.com/github/tulios/nightcrawler_swift) [![Travis](https://api.travis-ci.org/tulios/nightcrawler_swift.svg?branch=master)](https://travis-ci.org/tulios/nightcrawler_swift)
|
1
|
+
# Nightcrawler Swift [![Gem Version](https://badge.fury.io/rb/nightcrawler_swift.svg)](http://badge.fury.io/rb/nightcrawler_swift) [![Code Climate](https://codeclimate.com/github/tulios/nightcrawler_swift/badges/gpa.svg)](https://codeclimate.com/github/tulios/nightcrawler_swift) [![Travis](https://api.travis-ci.org/tulios/nightcrawler_swift.svg?branch=master)](https://travis-ci.org/tulios/nightcrawler_swift)
|
2
2
|
|
3
3
|
Like the X-Men nightcrawler this gem teleports your assets to a OpenStack Swift bucket/container. It was designed to sync your assets with OpenStack Swift and allow some operations with your buckets/containers.
|
4
4
|
|
@@ -36,6 +36,7 @@ module NightcrawlerSwift::CLI
|
|
36
36
|
configure_option_bucket
|
37
37
|
configure_option_max_age
|
38
38
|
configure_option_config
|
39
|
+
configure_option_no_cache
|
39
40
|
configure_option_help
|
40
41
|
configure_option_version
|
41
42
|
end
|
@@ -73,6 +74,12 @@ module NightcrawlerSwift::CLI
|
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
77
|
+
def configure_option_no_cache
|
78
|
+
@parser.on_tail("--no-cache", "Avoids the connection cache. It also clears the cache if it exists") do
|
79
|
+
@runner.options.use_cache = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
76
83
|
def configure_option_help
|
77
84
|
@parser.on_tail("-h", "--help", "Show this message") do
|
78
85
|
@runner.log help
|
@@ -33,6 +33,7 @@ module NightcrawlerSwift::CLI
|
|
33
33
|
@options.configured = true
|
34
34
|
@options.default_config_file = true
|
35
35
|
@options.config_file = File.expand_path(File.join(user_home_dir, CONFIG_FILE))
|
36
|
+
@options.use_cache = true
|
36
37
|
@options.cache_file = File.expand_path(File.join(user_home_dir, CACHE_FILE))
|
37
38
|
@options.config_hash = {}
|
38
39
|
end
|
@@ -79,23 +80,34 @@ module NightcrawlerSwift::CLI
|
|
79
80
|
def connect_and_execute &block
|
80
81
|
path = options.cache_file
|
81
82
|
if File.exist?(path)
|
82
|
-
|
83
|
-
NightcrawlerSwift.connection.auth_response = OpenStruct.new(hash)
|
84
|
-
NightcrawlerSwift.connection.configure
|
85
|
-
|
86
|
-
token_id = NightcrawlerSwift.connection.token_id
|
87
|
-
NightcrawlerSwift.logger.debug "Cache found, restablishing connection with token_id: #{token_id}"
|
83
|
+
@options.use_cache ? restore_connection(path) : File.delete(path)
|
88
84
|
end
|
89
85
|
|
90
86
|
begin
|
91
87
|
block.call
|
92
88
|
ensure
|
89
|
+
return unless @options.use_cache
|
93
90
|
File.open(path, "w") do |f|
|
94
91
|
f.write(NightcrawlerSwift.connection.auth_response.to_h.to_json)
|
95
92
|
end
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
96
|
+
def restore_connection cache_path
|
97
|
+
begin
|
98
|
+
hash = JSON.parse File.read(cache_path)
|
99
|
+
NightcrawlerSwift.connection.auth_response = OpenStruct.new(hash)
|
100
|
+
NightcrawlerSwift.connection.configure
|
101
|
+
|
102
|
+
token_id = NightcrawlerSwift.connection.token_id
|
103
|
+
NightcrawlerSwift.logger.debug "Cache found, restablishing connection with token_id: #{token_id}"
|
104
|
+
|
105
|
+
rescue
|
106
|
+
log "Failed to restore connection, removing cache"
|
107
|
+
File.delete cache_path
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
99
111
|
def parse_parameters
|
100
112
|
@opt_parser.parse!
|
101
113
|
check_rcfile if options.default_config_file
|
@@ -1,38 +1,40 @@
|
|
1
1
|
module NightcrawlerSwift
|
2
|
-
module
|
2
|
+
module Ext
|
3
|
+
module Hash
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
unless {}.respond_to?(:symbolize_keys)
|
6
|
+
def symbolize_keys
|
7
|
+
{}.tap do |result|
|
8
|
+
keys.each {|k| result[k.to_sym] = self[k]}
|
9
|
+
end
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def symbolize_keys!
|
13
|
+
self.tap do
|
14
|
+
keys.each {|k| self[k.to_sym] = delete(k)}
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
unless {}.respond_to?(:compact)
|
20
|
+
def compact
|
21
|
+
{}.tap do |result|
|
22
|
+
keys.each {|k| result[k] = self[k] unless self[k].nil?}
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def compact!
|
27
|
+
self.tap do
|
28
|
+
keys.each do |k|
|
29
|
+
value = delete(k)
|
30
|
+
self[k] = value unless value.nil?
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
Hash.send :include, NightcrawlerSwift::Hash
|
40
|
+
Hash.send :include, NightcrawlerSwift::Ext::Hash
|
data/lib/nightcrawler_swift.rb
CHANGED
@@ -8,6 +8,8 @@ require "rest_client"
|
|
8
8
|
require "nightcrawler_swift/version"
|
9
9
|
require "nightcrawler_swift/exceptions"
|
10
10
|
require "nightcrawler_swift/ext/hash"
|
11
|
+
require "nightcrawler_swift/ext/open_struct"
|
12
|
+
require "nightcrawler_swift/ext/nil_class"
|
11
13
|
require "nightcrawler_swift/options"
|
12
14
|
require "nightcrawler_swift/gateway"
|
13
15
|
require "nightcrawler_swift/connection"
|
data/nightcrawler_swift.gemspec
CHANGED
@@ -25,5 +25,10 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
27
|
spec.add_development_dependency "codeclimate-test-reporter"
|
28
|
-
|
28
|
+
|
29
|
+
if RUBY_VERSION =~ /1\.9/
|
30
|
+
spec.add_development_dependency "debugger"
|
31
|
+
else
|
32
|
+
spec.add_development_dependency "byebug"
|
33
|
+
end
|
29
34
|
end
|
@@ -131,6 +131,16 @@ describe NightcrawlerSwift::CLI::OptParser do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
|
+
|
135
|
+
["--no-cache"].each do |switch|
|
136
|
+
context switch do
|
137
|
+
it "configures use_cache with false" do
|
138
|
+
allow(runner).to receive(:argv).and_return([switch])
|
139
|
+
subject.parse!
|
140
|
+
expect(runner.options.use_cache).to eql false
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
134
144
|
end
|
135
145
|
|
136
146
|
describe "#parse!" do
|
@@ -63,7 +63,12 @@ describe NightcrawlerSwift::CLI::Runner do
|
|
63
63
|
expect(subject.options.config_file).to eql File.expand_path(path)
|
64
64
|
end
|
65
65
|
|
66
|
-
it "
|
66
|
+
it "enables the use of cache" do
|
67
|
+
subject.run
|
68
|
+
expect(subject.options.use_cache).to eql true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "points to a cache file in the user home dir" do
|
67
72
|
subject.run
|
68
73
|
path = File.join(config_dir, NightcrawlerSwift::CLI::CACHE_FILE)
|
69
74
|
expect(subject.options.cache_file).to eql File.expand_path(path)
|
@@ -112,7 +117,9 @@ describe NightcrawlerSwift::CLI::Runner do
|
|
112
117
|
|
113
118
|
expect(connection).to receive(:configure).and_call_original
|
114
119
|
subject.run
|
115
|
-
|
120
|
+
# This test uses 'eq' instead of 'eql' because in Ruby 1.9.x the method
|
121
|
+
# 'equal?' is different than '==' making this test fail
|
122
|
+
expect(connection.auth_response).to eq(OpenStruct.new(connection_success_json))
|
116
123
|
end
|
117
124
|
end
|
118
125
|
|
@@ -146,6 +153,30 @@ describe NightcrawlerSwift::CLI::Runner do
|
|
146
153
|
end
|
147
154
|
end
|
148
155
|
|
156
|
+
context "with no-cache flag" do
|
157
|
+
before do
|
158
|
+
subject.send :configure_default_options
|
159
|
+
expect(subject.options.use_cache).to eql true
|
160
|
+
allow(subject).to receive(:parse_parameters) { subject.options.use_cache = false }
|
161
|
+
end
|
162
|
+
|
163
|
+
it "doesn't write the auth_response into cache file" do
|
164
|
+
expect(File.exist?(cache_file)).to eql false
|
165
|
+
allow(connection).to receive(:auth_response).and_return(OpenStruct.new(connection_success_json))
|
166
|
+
subject.run
|
167
|
+
expect(File.exist?(cache_file)).to eql false
|
168
|
+
end
|
169
|
+
|
170
|
+
it "removes the cache file if it exists" do
|
171
|
+
expect(File.exist?(cache_file)).to eql false
|
172
|
+
allow(connection).to receive(:auth_response).and_return(OpenStruct.new(connection_success_json))
|
173
|
+
File.open(cache_file, "w") {|f| f.write(connection_success_json.to_json)}
|
174
|
+
expect(File.exist?(cache_file)).to eql true
|
175
|
+
subject.run
|
176
|
+
expect(File.exist?(cache_file)).to eql false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
149
180
|
it "writes the auth_response into cache file" do
|
150
181
|
expect(File.exist?(cache_file)).to eql false
|
151
182
|
expect(connection).to receive(:auth_response).and_return(OpenStruct.new(connection_success_json))
|
@@ -176,6 +207,18 @@ describe NightcrawlerSwift::CLI::Runner do
|
|
176
207
|
end
|
177
208
|
end
|
178
209
|
|
210
|
+
context "when there is an error with connection cache" do
|
211
|
+
it "removes the cache file if it exists and allows the creation of a new one" do
|
212
|
+
expect(File.exist?(cache_file)).to eql false
|
213
|
+
allow(connection).to receive(:auth_response).and_return(OpenStruct.new(connection_success_json))
|
214
|
+
File.open(cache_file, "w") {|f| f.write("null")}
|
215
|
+
expect(File.exist?(cache_file)).to eql true
|
216
|
+
subject.run
|
217
|
+
expect(File.exist?(cache_file)).to eql true
|
218
|
+
expect(File.read(cache_file)).to eql connection_success_json.to_json
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
179
222
|
context "when rescue Errno::ENOENT" do
|
180
223
|
before do
|
181
224
|
NightcrawlerSwift.logger = Logger.new(StringIO.new)
|
@@ -63,7 +63,9 @@ describe NightcrawlerSwift::Connection do
|
|
63
63
|
|
64
64
|
it "stores the auth_response" do
|
65
65
|
subject.connect!
|
66
|
-
|
66
|
+
# This test uses 'eq' instead of 'eql' because in Ruby 1.9.x the method
|
67
|
+
# 'equal?' is different than '==' making this test fail
|
68
|
+
expect(subject.auth_response).to eq(OpenStruct.new(auth_success_json))
|
67
69
|
end
|
68
70
|
|
69
71
|
it "stores the token id" do
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NightcrawlerSwift::Ext::OpenStruct do
|
4
|
+
|
5
|
+
let :hash do
|
6
|
+
{key1: "value", key2: true}
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
OpenStruct.new hash
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#to_h" do
|
14
|
+
it "returns a hash with the content" do
|
15
|
+
expect(subject.to_h).to eql hash
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "for a blank object" do
|
19
|
+
subject do
|
20
|
+
OpenStruct.new
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns an empty hash" do
|
24
|
+
expect(subject.to_h).to eql({})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,7 @@ require "codeclimate-test-reporter"
|
|
2
2
|
CodeClimate::TestReporter.start
|
3
3
|
|
4
4
|
require "rake"
|
5
|
-
require "byebug"
|
5
|
+
RUBY_VERSION =~ /1\.9/ ? require("debugger") : require("byebug")
|
6
6
|
require "nightcrawler_swift"
|
7
7
|
|
8
8
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nightcrawler_swift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tulios
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -146,6 +146,8 @@ files:
|
|
146
146
|
- lib/nightcrawler_swift/connection.rb
|
147
147
|
- lib/nightcrawler_swift/exceptions.rb
|
148
148
|
- lib/nightcrawler_swift/ext/hash.rb
|
149
|
+
- lib/nightcrawler_swift/ext/nil_class.rb
|
150
|
+
- lib/nightcrawler_swift/ext/open_struct.rb
|
149
151
|
- lib/nightcrawler_swift/gateway.rb
|
150
152
|
- lib/nightcrawler_swift/options.rb
|
151
153
|
- lib/nightcrawler_swift/railtie.rb
|
@@ -170,6 +172,8 @@ files:
|
|
170
172
|
- spec/lib/nightcrawler_swift/commands/upload_spec.rb
|
171
173
|
- spec/lib/nightcrawler_swift/connection_spec.rb
|
172
174
|
- spec/lib/nightcrawler_swift/ext/hash_spec.rb
|
175
|
+
- spec/lib/nightcrawler_swift/ext/nil_class_spec.rb
|
176
|
+
- spec/lib/nightcrawler_swift/ext/open_struct_spec.rb
|
173
177
|
- spec/lib/nightcrawler_swift/gateway_spec.rb
|
174
178
|
- spec/lib/nightcrawler_swift/options_spec.rb
|
175
179
|
- spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
|
@@ -219,6 +223,8 @@ test_files:
|
|
219
223
|
- spec/lib/nightcrawler_swift/commands/upload_spec.rb
|
220
224
|
- spec/lib/nightcrawler_swift/connection_spec.rb
|
221
225
|
- spec/lib/nightcrawler_swift/ext/hash_spec.rb
|
226
|
+
- spec/lib/nightcrawler_swift/ext/nil_class_spec.rb
|
227
|
+
- spec/lib/nightcrawler_swift/ext/open_struct_spec.rb
|
222
228
|
- spec/lib/nightcrawler_swift/gateway_spec.rb
|
223
229
|
- spec/lib/nightcrawler_swift/options_spec.rb
|
224
230
|
- spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
|