nightcrawler_swift 0.2.3 → 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/.gitignore +1 -0
- data/.travis.yml +4 -0
- data/Changelog.md +34 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -5
- data/lib/nightcrawler_swift/connection.rb +1 -0
- data/lib/nightcrawler_swift/exceptions.rb +1 -1
- data/lib/nightcrawler_swift/tasks/asset_sync.rake +6 -2
- data/lib/nightcrawler_swift/upload.rb +7 -1
- data/lib/nightcrawler_swift/version.rb +1 -1
- data/spec/lib/nightcrawler_swift/connection_spec.rb +12 -1
- data/spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb +59 -0
- data/spec/lib/nightcrawler_swift/upload_spec.rb +18 -3
- data/spec/spec_helper.rb +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 792e1b2a4c65b85291d7a5c733fbd238f6b4f531
|
4
|
+
data.tar.gz: b34fa251f341f191b7627d8ac200bb0daa43fdbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be4f048df14fe2453b4fc22ed8e495434c5f4fb51009f8e5765fae6f61cbc160dcf12ae4c2d274e4aa69096884b629d8e83538f03bd14dd4992ad39dc1e66f91
|
7
|
+
data.tar.gz: d9bd21e55c32c1ee73f16e817c7edf2c529552d94402c615a63a37026f01eb5ba477b21c461878f35fcd54953e574553dda79e5ce6f50cf5b745e61ad55030a7
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Changelog.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.3.0
|
4
|
+
|
5
|
+
- Included ```Cache-Control``` header to upload command through max_age configuration parameter
|
6
|
+
- Sending etag when uploading assets
|
7
|
+
- Bugfix: rake task now returns exit code 1 when error
|
8
|
+
|
9
|
+
## 0.2.3
|
10
|
+
|
11
|
+
- Removed rest-client version due to compatibility issues
|
12
|
+
|
13
|
+
## 0.2.2
|
14
|
+
|
15
|
+
- Included ```Content-Type``` header to upload command
|
16
|
+
|
17
|
+
## 0.2.1
|
18
|
+
|
19
|
+
- Bugfix: sync was not connecting
|
20
|
+
|
21
|
+
## 0.2.0
|
22
|
+
|
23
|
+
- Better Rails integration
|
24
|
+
- Download command
|
25
|
+
|
26
|
+
## 0.1.1
|
27
|
+
|
28
|
+
- Bugfix: sync broken syntax
|
29
|
+
|
30
|
+
## 0.1.0
|
31
|
+
|
32
|
+
- Connection object
|
33
|
+
- Sync, upload, delete and list commands
|
34
|
+
- Rake task to sync Rails public dir
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
[](https://codeclimate.com/github/tulios/nightcrawler_swift)
|
2
|
-
|
2
|
+
[](https://travis-ci.org/tulios/nightcrawler_swift)
|
3
|
+
[](http://badge.fury.io/rb/nightcrawler_swift)
|
3
4
|
# Nightcrawler Swift
|
4
5
|
|
5
6
|
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.
|
@@ -21,17 +22,19 @@ Or install it yourself as:
|
|
21
22
|
## Usage
|
22
23
|
|
23
24
|
### With Rails
|
24
|
-
#### 1) Configure your swift credentials
|
25
|
+
#### 1) Configure your swift credentials and options
|
25
26
|
|
26
27
|
_In config/application.rb_ or _config/environments/*.rb_
|
27
28
|
|
28
29
|
```ruby
|
29
30
|
config.nightcrawler_swift.bucket = "rogue"
|
30
|
-
config.nightcrawler_swift.
|
31
|
+
config.nightcrawler_swift.tenant_name = "nightcrawler"
|
31
32
|
config.nightcrawler_swift.username = "my_username1"
|
32
33
|
config.nightcrawler_swift.password = "my_password1"
|
33
34
|
config.nightcrawler_swift.auth_url = "https://auth.url.com:123/v2.0/tokens"
|
35
|
+
config.nightcrawler_swift.max_age = 3600 #optional
|
34
36
|
```
|
37
|
+
**max_age** will be used to define *Cache-Control:max-age=<value>* header. It's not required.
|
35
38
|
|
36
39
|
By default it will use ```Rails.logger``` as logger, to change that use a different logger in configurations, like:
|
37
40
|
|
@@ -49,7 +52,7 @@ It will invoke ```rake assets:precompile``` and will copy your public directory
|
|
49
52
|
|
50
53
|
### Programatically
|
51
54
|
|
52
|
-
#### 1) Configure your swift credentials
|
55
|
+
#### 1) Configure your swift credentials and options
|
53
56
|
|
54
57
|
```ruby
|
55
58
|
NightcrawlerSwift.configure({
|
@@ -57,7 +60,8 @@ NightcrawlerSwift.configure({
|
|
57
60
|
tenant_name: "nightcrawler"
|
58
61
|
username: "my_username1",
|
59
62
|
password: "my_password1",
|
60
|
-
auth_url: "https://auth.url.com:123/v2.0/tokens"
|
63
|
+
auth_url: "https://auth.url.com:123/v2.0/tokens",
|
64
|
+
max_age: 3600 #optional
|
61
65
|
})
|
62
66
|
```
|
63
67
|
|
@@ -5,8 +5,12 @@ namespace :nightcrawler_swift do
|
|
5
5
|
|
6
6
|
desc "Synchronizes the public directory with OpenStack Swift"
|
7
7
|
task asset_sync: ["assets:precompile", "environment"] do
|
8
|
-
|
9
|
-
|
8
|
+
begin
|
9
|
+
NightcrawlerSwift.sync File.join(Rails.root, "public")
|
10
|
+
rescue => e
|
11
|
+
STDERR.puts e.message
|
12
|
+
exit 1
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
@@ -1,9 +1,15 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
1
3
|
module NightcrawlerSwift
|
2
4
|
class Upload < Command
|
3
5
|
|
4
6
|
def execute path, file
|
5
7
|
content_type = MultiMime.by_file(file).content_type
|
6
|
-
|
8
|
+
content = file.read
|
9
|
+
etag = '"%s"' % Digest::MD5.new.update(content).hexdigest
|
10
|
+
headers = {etag: etag, content_type: content_type}
|
11
|
+
headers.merge!({cache_control: "max-age=#{connection.opts.max_age}"}) if connection.opts.max_age
|
12
|
+
response = put "#{connection.upload_url}/#{path}", body: content, headers: headers
|
7
13
|
[200, 201].include?(response.code)
|
8
14
|
end
|
9
15
|
|
@@ -8,7 +8,8 @@ describe NightcrawlerSwift::Connection do
|
|
8
8
|
tenant_name: "tenant_username1",
|
9
9
|
username: "username1",
|
10
10
|
password: "some-pass",
|
11
|
-
auth_url: "https://auth.url.com:123/v2.0/tokens"
|
11
|
+
auth_url: "https://auth.url.com:123/v2.0/tokens",
|
12
|
+
max_age: 31536000 #1 year
|
12
13
|
}
|
13
14
|
end
|
14
15
|
|
@@ -89,6 +90,16 @@ describe NightcrawlerSwift::Connection do
|
|
89
90
|
it "returns self" do
|
90
91
|
expect(subject.connect!).to eql(subject)
|
91
92
|
end
|
93
|
+
|
94
|
+
context "max_age" do
|
95
|
+
it "stores it" do
|
96
|
+
expect(subject.opts.max_age).to eql(opts[:max_age])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should be an integer" do
|
100
|
+
expect { NightcrawlerSwift::Connection.new({max_age: "a string"}) }.to raise_error(NightcrawlerSwift::Exceptions::ConfigurationError)
|
101
|
+
end
|
102
|
+
end
|
92
103
|
end
|
93
104
|
|
94
105
|
describe "when some error happens" do
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
unless defined?(Rails)
|
4
|
+
module Rails
|
5
|
+
def self.root; end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "asset_sync.rake" do
|
10
|
+
let :rake do
|
11
|
+
Rake.application = Rake::Application.new
|
12
|
+
end
|
13
|
+
|
14
|
+
let :load_path do
|
15
|
+
[File.expand_path(File.join(File.dirname(__FILE__), "../../../../lib/nightcrawler_swift/tasks"))]
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
rake.rake_require "asset_sync", load_path, []
|
20
|
+
|
21
|
+
Rake::Task.define_task("environment")
|
22
|
+
Rake::Task.define_task("assets:precompile")
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "nightcrawler_swift:rails:asset_sync" do
|
26
|
+
let(:task_name) { "nightcrawler_swift:rails:asset_sync" }
|
27
|
+
subject { rake[task_name] }
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(Rails).to receive(:root).and_return(".")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "requires environment and assets:precompile" do
|
34
|
+
expect(subject.prerequisites).to include "environment"
|
35
|
+
expect(subject.prerequisites).to include "assets:precompile"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "calls sync with Rails public dir path" do
|
39
|
+
expect(NightcrawlerSwift).to receive(:sync).with("./public")
|
40
|
+
subject.invoke
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when occurs an error" do
|
44
|
+
it "exits with code 1" do
|
45
|
+
allow(STDERR).to receive(:puts)
|
46
|
+
allow(NightcrawlerSwift).to receive(:sync).and_raise(StandardError.new)
|
47
|
+
code = "wrong code"
|
48
|
+
|
49
|
+
begin
|
50
|
+
subject.invoke
|
51
|
+
rescue SystemExit => e
|
52
|
+
code = e.status
|
53
|
+
end
|
54
|
+
|
55
|
+
expect(code).to eql(1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'digest'
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe NightcrawlerSwift::Upload do
|
@@ -14,13 +15,21 @@ describe NightcrawlerSwift::Upload do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
let :connection do
|
17
|
-
double :connection, upload_url: "server-url"
|
18
|
+
double :connection, upload_url: "server-url", opts: OpenStruct.new {}
|
18
19
|
end
|
19
20
|
|
20
21
|
let :response do
|
21
22
|
double(:response, code: 201)
|
22
23
|
end
|
23
24
|
|
25
|
+
let :etag do
|
26
|
+
'"%s"' % Digest::MD5.new.update(file.read).hexdigest
|
27
|
+
end
|
28
|
+
|
29
|
+
let :max_age do
|
30
|
+
31536000
|
31
|
+
end
|
32
|
+
|
24
33
|
before do
|
25
34
|
allow(NightcrawlerSwift).to receive(:connection).and_return(connection)
|
26
35
|
allow(subject).to receive(:put).and_return(response)
|
@@ -41,9 +50,9 @@ describe NightcrawlerSwift::Upload do
|
|
41
50
|
expect(subject).to have_received(:put).with(anything, hash_including(body: "content"))
|
42
51
|
end
|
43
52
|
|
44
|
-
it "sends file
|
53
|
+
it "sends file metadata as headers" do
|
45
54
|
execute
|
46
|
-
expect(subject).to have_received(:put).with(anything, hash_including(headers: { content_type: "text/css"}))
|
55
|
+
expect(subject).to have_received(:put).with(anything, hash_including(headers: { content_type: "text/css", etag: etag}))
|
47
56
|
end
|
48
57
|
|
49
58
|
it "sends to upload url with given path" do
|
@@ -51,6 +60,12 @@ describe NightcrawlerSwift::Upload do
|
|
51
60
|
expect(subject).to have_received(:put).with("server-url/file_name", anything)
|
52
61
|
end
|
53
62
|
|
63
|
+
it "sends max_age into headers" do
|
64
|
+
connection.opts.max_age = max_age
|
65
|
+
execute
|
66
|
+
expect(subject).to have_received(:put).with(anything, hash_including(headers: { content_type: "text/css", etag: etag, cache_control: "max-age=#{max_age}" }))
|
67
|
+
end
|
68
|
+
|
54
69
|
context "when response code is 200" do
|
55
70
|
let(:response) { double(:response, code: 200) }
|
56
71
|
it { expect(execute).to be true }
|
data/spec/spec_helper.rb
CHANGED
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.3.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: 2014-08-
|
12
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -108,6 +108,8 @@ files:
|
|
108
108
|
- ".rspec"
|
109
109
|
- ".ruby-gemset"
|
110
110
|
- ".ruby-version"
|
111
|
+
- ".travis.yml"
|
112
|
+
- Changelog.md
|
111
113
|
- Gemfile
|
112
114
|
- Gemfile.lock
|
113
115
|
- LICENSE.txt
|
@@ -138,6 +140,7 @@ files:
|
|
138
140
|
- spec/lib/nightcrawler_swift/download_spec.rb
|
139
141
|
- spec/lib/nightcrawler_swift/list_spec.rb
|
140
142
|
- spec/lib/nightcrawler_swift/sync_spec.rb
|
143
|
+
- spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
|
141
144
|
- spec/lib/nightcrawler_swift/upload_spec.rb
|
142
145
|
- spec/lib/nightcrawler_swift_spec.rb
|
143
146
|
- spec/spec_helper.rb
|
@@ -179,6 +182,7 @@ test_files:
|
|
179
182
|
- spec/lib/nightcrawler_swift/download_spec.rb
|
180
183
|
- spec/lib/nightcrawler_swift/list_spec.rb
|
181
184
|
- spec/lib/nightcrawler_swift/sync_spec.rb
|
185
|
+
- spec/lib/nightcrawler_swift/tasks/asset_sync_spec.rb
|
182
186
|
- spec/lib/nightcrawler_swift/upload_spec.rb
|
183
187
|
- spec/lib/nightcrawler_swift_spec.rb
|
184
188
|
- spec/spec_helper.rb
|