asset_sync 2.12.1 → 2.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fbb82cb5023ce3d6e1f088aa62fa32718f8e743977c31b773e3f2a324a0a397
4
- data.tar.gz: 504e104e3dfe839bb19b0794a7af8f4bb932fd7f7500347374c14b8862e5ae43
3
+ metadata.gz: 56414f299dce966e768266fd6a06f73896a95fbd7747be08bf94481dcd25f6ce
4
+ data.tar.gz: 906057c77eca271b2042aa174de7644c235f58cbd36db95dbec6eae17180f3d0
5
5
  SHA512:
6
- metadata.gz: 2945ac417bfcc350068b1c9ce3c59781f0cd7bb50bd606919803e55602a81b06d6d6fed24de0c7e62ca695a83901481d296a9ae20031b5ab1e9edfc61a69823a
7
- data.tar.gz: b96f8274e66d1d7ec2ab182fdcb3833edd7c24b9dc9d9fd9d038a3db8608dc1102a23b2998ec5c9749e89fe6d12212488dc9733ec927328fcc0f388bf84df357
6
+ metadata.gz: f45ce18cf34f17ab8fb9fcfffe2ab9746fe8642fe02b779d8ed53b94f8ba884e23fae6c2180ee2b5478d756c5dd3510ae12b4055a4bd8a46e2447fee0f9e6d38
7
+ data.tar.gz: 37b916a3e8531351719b209c58660a7e26438689ea5bc8c0ca059af83c879b764ec7333c4a9612db629a89ee381796535ee53a71af8dea0c2cbfdaa3c83c77dc
@@ -0,0 +1,68 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ paths-ignore:
8
+ - 'README.md'
9
+ - 'CHANGELOG.md'
10
+ push:
11
+ branches:
12
+ - master
13
+ paths-ignore:
14
+ - 'README.md'
15
+ - 'CHANGELOG.md'
16
+
17
+ jobs:
18
+ unit_tests:
19
+ name: Unit Tests
20
+ # Homemade support for [ci skip] no longer needed
21
+ # https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
22
+ # if: "contains(github.event.commits[0].message, '[ci skip]') == false"
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ os:
27
+ - ubuntu
28
+ ruby:
29
+ - 2.5
30
+ - 2.6
31
+ - 2.7
32
+ - 3.0
33
+ - jruby
34
+ gemfile:
35
+ - gemfiles/rails_5_2.gemfile
36
+ - gemfiles/rails_6_0.gemfile
37
+ - gemfiles/rails_6_1.gemfile
38
+ allow_failures:
39
+ - false
40
+ include:
41
+ - os: ubuntu
42
+ ruby: ruby-head
43
+ gemfile: gemfiles/rails_6_1.gemfile
44
+ allow_failures: true
45
+ - os: ubuntu
46
+ ruby: jruby-head
47
+ gemfile: gemfiles/rails_6_1.gemfile
48
+ allow_failures: true
49
+ exclude:
50
+ - os: ubuntu
51
+ ruby: 3.0
52
+ gemfile: gemfiles/rails_5_2.gemfile
53
+ allow_failures: false
54
+ env:
55
+ BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
56
+ ALLOW_FAILURES: "${{ matrix.allow_failures }}"
57
+ runs-on: ${{ matrix.os }}-latest
58
+ continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
59
+ steps:
60
+ - name: Checkout
61
+ uses: actions/checkout@v2
62
+ - name: Setup Ruby
63
+ uses: ruby/setup-ruby@v1
64
+ with:
65
+ ruby-version: ${{ matrix.ruby }}
66
+ bundler-cache: true
67
+ - name: Test
68
+ run: bundle exec rake spec:unit || $ALLOW_FAILURES
data/.travis.yml CHANGED
@@ -2,11 +2,12 @@
2
2
  # http://docs.travis-ci.com/user/workers/container-based-infrastructure/
3
3
  sudo: false
4
4
  language: ruby
5
+ arch:
6
+ - amd64
7
+ - ppc64le
5
8
  cache:
6
9
  bundler: true
7
10
  rvm:
8
- - 2.3
9
- - 2.4
10
11
  - 2.5
11
12
  - 2.6
12
13
  - 2.7
@@ -14,10 +15,9 @@ rvm:
14
15
  - jruby
15
16
  - jruby-head
16
17
  gemfile:
17
- - gemfiles/rails_5_0.gemfile
18
- - gemfiles/rails_5_1.gemfile
19
18
  - gemfiles/rails_5_2.gemfile
20
19
  - gemfiles/rails_6_0.gemfile
20
+ - gemfiles/rails_6_1.gemfile
21
21
  before_install:
22
22
  # Cannot use bundler 2.x due to dependency (mainly rails 4.2)
23
23
  # Solution from https://github.com/rails/rails/blob/4-2-stable/.travis.yml
@@ -34,11 +34,6 @@ matrix:
34
34
  allow_failures:
35
35
  - rvm: ruby-head
36
36
  - rvm: jruby-head
37
- exclude:
38
- - rvm: 2.3
39
- gemfile: gemfiles/rails_6_0.gemfile
40
- - rvm: 2.4
41
- gemfile: gemfiles/rails_6_0.gemfile
42
37
  notifications:
43
38
  webhooks:
44
39
  urls:
data/Appraisals CHANGED
@@ -1,12 +1,4 @@
1
1
 
2
- appraise "rails_5_0" do
3
- gem "rails", "~> 5.0.0"
4
- end
5
-
6
- appraise "rails_5_1" do
7
- gem "rails", "~> 5.1.0"
8
- end
9
-
10
2
  appraise "rails_5_2" do
11
3
  gem "rails", "~> 5.2.0"
12
4
  end
@@ -14,3 +6,7 @@ end
14
6
  appraise "rails_6_0" do
15
7
  gem "rails", "~> 6.0.0"
16
8
  end
9
+
10
+ appraise "rails_6_1" do
11
+ gem "rails", "~> 6.1.0"
12
+ end
data/CHANGELOG.md CHANGED
@@ -18,6 +18,48 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ =======
22
+ ## [2.14.2]
23
+
24
+ ### Added
25
+
26
+ - Add support for setting option `google_json_key_string` in YML (not new option)
27
+ (https://github.com/AssetSync/asset_sync/pull/419)
28
+
29
+
30
+ =======
31
+ ## [2.14.1]
32
+
33
+ ### Added
34
+
35
+ - Add support for setting option `log_silently` in YML (not new option)
36
+ (https://github.com/AssetSync/asset_sync/pull/417)
37
+
38
+
39
+ ## [2.14.0] - 2021-03-31
40
+
41
+ ### Added
42
+
43
+ - Add support for fog option `google_json_key_string`
44
+ (https://github.com/AssetSync/asset_sync/pull/415)
45
+
46
+
47
+ ## [2.13.1] - 2021-03-01
48
+
49
+ ### Fixed
50
+
51
+ - Fix "files to be uploaded list" generation for file names with dashes
52
+ (https://github.com/AssetSync/asset_sync/pull/414)
53
+
54
+
55
+ ## [2.13.0] - 2020-12-14
56
+
57
+ ### Added
58
+
59
+ - Add Backblaze B2 Cloud Storage support
60
+ (https://github.com/AssetSync/asset_sync/pull/410)
61
+
62
+
21
63
  ## [2.12.1] - 2020-06-17
22
64
 
23
65
  ### Fixed
@@ -978,7 +1020,12 @@ Changes:
978
1020
  * Merge branch 'sinatra'
979
1021
 
980
1022
 
981
- [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.12.1...HEAD
1023
+ [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.14.2...HEAD
1024
+ [2.14.2]: https://github.com/AssetSync/asset_sync/compare/v2.14.1...v2.14.2
1025
+ [2.14.1]: https://github.com/AssetSync/asset_sync/compare/v2.14.0...v2.14.1
1026
+ [2.14.0]: https://github.com/AssetSync/asset_sync/compare/v2.13.1...v2.14.0
1027
+ [2.13.1]: https://github.com/AssetSync/asset_sync/compare/v2.13.0...v2.13.1
1028
+ [2.13.0]: https://github.com/AssetSync/asset_sync/compare/v2.12.1...v2.13.0
982
1029
  [2.12.1]: https://github.com/AssetSync/asset_sync/compare/v2.12.0...v2.12.1
983
1030
  [2.12.0]: https://github.com/AssetSync/asset_sync/compare/v2.11.0...v2.12.0
984
1031
  [2.11.0]: https://github.com/AssetSync/asset_sync/compare/v2.10.0...v2.11.0
data/README.md CHANGED
@@ -38,6 +38,13 @@ gem "asset_sync"
38
38
  gem "fog-azure-rm"
39
39
  ```
40
40
 
41
+ To use Backblaze B2, insert these.
42
+
43
+ ``` ruby
44
+ gem "asset_sync"
45
+ gem "fog-backblaze"
46
+ ```
47
+
41
48
 
42
49
  ### Extended Installation (Faster sync with turbosprockets)
43
50
 
@@ -77,6 +84,13 @@ Or, to use Azure Blob storage, configure as this.
77
84
  config.action_controller.asset_host = "//#{ENV['AZURE_STORAGE_ACCOUNT_NAME']}.blob.core.windows.net/#{ENV['FOG_DIRECTORY']}"
78
85
  ```
79
86
 
87
+ Or, to use Backblaze B2, configure as this.
88
+
89
+ ``` ruby
90
+ #config/environments/production.rb
91
+ config.action_controller.asset_host = "//f000.backblazeb2.com/file/#{ENV['FOG_DIRECTORY']}"
92
+ ```
93
+
80
94
 
81
95
  On **HTTPS**: the exclusion of any protocol in the asset host declaration above will allow browsers to choose the transport mechanism on the fly. So if your application is available under both HTTP and HTTPS the assets will be served to match.
82
96
 
@@ -170,7 +184,7 @@ heroku config:add FOG_DIRECTORY=xxxx
170
184
  heroku config:add FOG_PROVIDER=Rackspace
171
185
  ```
172
186
 
173
- Google Storage Cloud configuration is supported as well. The preferred option is using the [GCS JSON API](https://github.com/fog/fog-google#storage) which requires that you create an appropriate service account, generate the signatures and make them accessible to asset sync at the prescribed location
187
+ Google Storage Cloud configuration is supported as well. The preferred option is using the [GCS JSON API](https://github.com/fog/fog-google#storage) which requires that you create an appropriate service account, generate the signatures and make them accessible to asset sync at the prescribed location
174
188
 
175
189
  ```bash
176
190
  heroku config:add FOG_PROVIDER=Google
@@ -199,6 +213,7 @@ Run the included Rake task to generate a starting point.
199
213
  rails g asset_sync:install --provider=Rackspace
200
214
  rails g asset_sync:install --provider=AWS
201
215
  rails g asset_sync:install --provider=AzureRM
216
+ rails g asset_sync:install --provider=Backblaze
202
217
 
203
218
  The generator will create a Rails initializer at `config/initializers/asset_sync.rb`.
204
219
 
@@ -245,7 +260,7 @@ AssetSync.configure do |config|
245
260
  #
246
261
  # Upload files concurrently
247
262
  # config.concurrent_uploads = false
248
- #
263
+ #
249
264
  # Number of threads when concurrent_uploads is enabled
250
265
  # config.concurrent_uploads_max_threads = 10
251
266
  #
@@ -274,6 +289,7 @@ Run the included Rake task to generate a starting point.
274
289
  rails g asset_sync:install --use-yml --provider=Rackspace
275
290
  rails g asset_sync:install --use-yml --provider=AWS
276
291
  rails g asset_sync:install --use-yml --provider=AzureRM
292
+ rails g asset_sync:install --use-yml --provider=Backblaze
277
293
 
278
294
  The generator will create a YAML file at `config/asset_sync.yml`.
279
295
 
@@ -383,7 +399,7 @@ To customize the overrides:
383
399
  AssetSync.configure do |config|
384
400
  # Clear the default overrides
385
401
  config.file_ext_to_mime_type_overrides.clear
386
-
402
+
387
403
  # Add/Edit overrides
388
404
  # Will call `#to_s` for inputs
389
405
  config.file_ext_to_mime_type_overrides.add(:js, :"application/x-javascript")
@@ -392,7 +408,7 @@ end
392
408
  The blocks are run when local files are being scanned and uploaded
393
409
 
394
410
  #### Fog (Required)
395
- * **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage) or *AzureRM* (Azure Blob)
411
+ * **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage) or *AzureRM* (Azure Blob) or *Backblaze* (Backblaze B2)
396
412
  * **fog\_directory**: your bucket name
397
413
 
398
414
  #### Fog (Optional)
@@ -426,6 +442,11 @@ When using the S3 API
426
442
  * **azure\_storage\_account\_name**: your Azure Blob access key
427
443
  * **azure\_storage\_access\_key**: your Azure Blob access secret
428
444
 
445
+ #### Backblaze B2
446
+ * **b2\_key\_id**: Your Backblaze B2 key ID
447
+ * **b2\_key\_token**: Your Backblaze B2 key token
448
+ * **b2\_bucket\_id**: Your Backblaze B2 bucket ID
449
+
429
450
  #### Rackspace (Optional)
430
451
 
431
452
  * **rackspace\_auth\_url**: Rackspace auth URL, for Rackspace London use: `https://lon.identity.api.rackspacecloud.com/v2.0`
@@ -551,7 +572,7 @@ AssetSync.configure do |config|
551
572
  config.prefix = 'assets'
552
573
  # Can be a `Pathname` or `String`
553
574
  # Will be converted into an `Pathname`
554
- # If relative, will be converted into an absolute path
575
+ # If relative, will be converted into an absolute path
555
576
  # via `::Rails.root` or `::Dir.pwd`
556
577
  config.public_path = Pathname('./public')
557
578
  end
@@ -622,7 +643,7 @@ Make sure you have a .env file with these details:-
622
643
  AWS_SECRET_ACCESS_KEY=<yoursecretkey>
623
644
  FOG_DIRECTORY=<yourbucket>
624
645
  FOG_REGION=<youbucketregion>
625
-
646
+
626
647
  # for AzureRM provider
627
648
  AZURE_STORAGE_ACCOUNT_NAME=<youraccountname>
628
649
  AZURE_STORAGE_ACCESS_KEY=<youraccesskey>
data/asset_sync.gemspec CHANGED
@@ -28,10 +28,13 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_development_dependency "fog-aws"
30
30
  s.add_development_dependency "fog-azure-rm"
31
+ s.add_development_dependency "fog-backblaze"
31
32
 
32
33
  s.add_development_dependency "uglifier"
33
34
  s.add_development_dependency "appraisal"
34
35
 
36
+ s.add_development_dependency "gem-release"
37
+
35
38
  s.files = `git ls-files`.split("\n")
36
39
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
37
40
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -5,6 +5,6 @@ source "https://rubygems.org"
5
5
  gem "rcov", platforms: :mri_18, group: [:development, :test]
6
6
  gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
7
7
  gem "jruby-openssl", platform: :jruby
8
- gem "rails", "~> 5.0.0"
8
+ gem "rails", "~> 6.1.0"
9
9
 
10
10
  gemspec path: "../"
@@ -49,12 +49,18 @@ module AssetSync
49
49
  # Google Storage
50
50
  attr_accessor :google_storage_secret_access_key, :google_storage_access_key_id # when using S3 interop
51
51
  attr_accessor :google_json_key_location # when using service accounts
52
+ attr_accessor :google_json_key_string # when using service accounts
52
53
  attr_accessor :google_project # when using service accounts
53
54
 
54
55
  # Azure Blob with Fog::AzureRM
55
56
  attr_accessor :azure_storage_account_name
56
57
  attr_accessor :azure_storage_access_key
57
58
 
59
+ # Backblaze B2 with Fog::Backblaze
60
+ attr_accessor :b2_key_id
61
+ attr_accessor :b2_key_token
62
+ attr_accessor :b2_bucket_id
63
+
58
64
  validates :existing_remote_files, :inclusion => { :in => %w(keep delete ignore) }
59
65
 
60
66
  validates :fog_provider, :presence => true
@@ -66,8 +72,12 @@ module AssetSync
66
72
  validates :rackspace_api_key, :presence => true, :if => :rackspace?
67
73
  validates :google_storage_secret_access_key, :presence => true, :if => :google_interop?
68
74
  validates :google_storage_access_key_id, :presence => true, :if => :google_interop?
69
- validates :google_json_key_location, :presence => true, :if => :google_service_account?
70
75
  validates :google_project, :presence => true, :if => :google_service_account?
76
+ validate(:if => :google_service_account?) do
77
+ unless google_json_key_location.present? || google_json_key_string.present?
78
+ errors.add(:base, 'must provide either google_json_key_location or google_json_key_string if using Google service account')
79
+ end
80
+ end
71
81
  validates :concurrent_uploads, :inclusion => { :in => [true, false] }
72
82
 
73
83
  def initialize
@@ -142,17 +152,21 @@ module AssetSync
142
152
  end
143
153
 
144
154
  def google_interop?
145
- google? && google_json_key_location.nil?
155
+ google? && google_json_key_location.nil? && google_json_key_string.nil?
146
156
  end
147
157
 
148
158
  def google_service_account?
149
- google? && google_json_key_location
159
+ google? && (google_json_key_location || google_json_key_string)
150
160
  end
151
161
 
152
162
  def azure_rm?
153
163
  fog_provider =~ /azurerm/i
154
164
  end
155
165
 
166
+ def backblaze?
167
+ fog_provider =~ /backblaze/i
168
+ end
169
+
156
170
  def cache_asset_regexp=(cache_asset_regexp)
157
171
  self.cache_asset_regexps = [cache_asset_regexp]
158
172
  end
@@ -214,13 +228,15 @@ module AssetSync
214
228
  self.google_project = yml["google_project"] if yml.has_key?("google_project")
215
229
  self.google_storage_secret_access_key = yml["google_storage_secret_access_key"] if yml.has_key?("google_storage_secret_access_key")
216
230
  self.google_storage_access_key_id = yml["google_storage_access_key_id"] if yml.has_key?("google_storage_access_key_id")
231
+ self.google_json_key_string = yml["google_json_key_string"] if yml.has_key?("google_json_key_string")
217
232
  self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files")
218
233
  self.gzip_compression = yml["gzip_compression"] if yml.has_key?("gzip_compression")
219
234
  self.manifest = yml["manifest"] if yml.has_key?("manifest")
220
235
  self.fail_silently = yml["fail_silently"] if yml.has_key?("fail_silently")
236
+ self.log_silently = yml["log_silently"] if yml.has_key?("log_silently")
221
237
  self.always_upload = yml["always_upload"] if yml.has_key?("always_upload")
222
238
  self.ignored_files = yml["ignored_files"] if yml.has_key?("ignored_files")
223
- self.custom_headers = yml["custom_headers"] if yml.has_key?("custom_headers")
239
+ self.custom_headers = yml["custom_headers"] if yml.has_key?("custom_headers")
224
240
  self.run_on_precompile = yml["run_on_precompile"] if yml.has_key?("run_on_precompile")
225
241
  self.invalidate = yml["invalidate"] if yml.has_key?("invalidate")
226
242
  self.cdn_distribution_id = yml['cdn_distribution_id'] if yml.has_key?("cdn_distribution_id")
@@ -233,6 +249,10 @@ module AssetSync
233
249
  self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
234
250
  self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")
235
251
 
252
+ self.b2_key_id = yml['b2_key_id'] if yml.has_key?("b2_key_id")
253
+ self.b2_key_token = yml['b2_key_token'] if yml.has_key?("b2_key_token")
254
+ self.b2_bucket_id = yml['b2_bucket_id'] if yml.has_key?("b2_bucket_id")
255
+
236
256
  # TODO deprecate the other old style config settings. FML.
237
257
  self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
238
258
  self.aws_secret_access_key = yml["aws_access_secret"] if yml.has_key?("aws_access_secret")
@@ -279,6 +299,8 @@ module AssetSync
279
299
  elsif google?
280
300
  if google_json_key_location
281
301
  options.merge!({:google_json_key_location => google_json_key_location, :google_project => google_project})
302
+ elsif google_json_key_string
303
+ options.merge!({:google_json_key_string => google_json_key_string, :google_project => google_project})
282
304
  else
283
305
  options.merge!({
284
306
  :google_storage_secret_access_key => google_storage_secret_access_key,
@@ -293,6 +315,13 @@ module AssetSync
293
315
  :azure_storage_access_key => azure_storage_access_key,
294
316
  })
295
317
  options.merge!({:environment => fog_region}) if fog_region
318
+ elsif backblaze?
319
+ require 'fog/backblaze'
320
+ options.merge!({
321
+ :b2_key_id => b2_key_id,
322
+ :b2_key_token => b2_key_token,
323
+ :b2_bucket_id => b2_bucket_id,
324
+ })
296
325
  else
297
326
  raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS, Rackspace and Google are supported currently."
298
327
  end
@@ -36,6 +36,10 @@ module AssetSync
36
36
  config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME'] if ENV.has_key?('AZURE_STORAGE_ACCOUNT_NAME')
37
37
  config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY'] if ENV.has_key?('AZURE_STORAGE_ACCESS_KEY')
38
38
 
39
+ config.b2_key_id = ENV['B2_KEY_ID'] if ENV.has_key?('B2_KEY_ID')
40
+ config.b2_key_token = ENV['B2_KEY_TOKEN'] if ENV.has_key?('B2_KEY_TOKEN')
41
+ config.b2_bucket_id = ENV['B2_BUCKET_ID'] if ENV.has_key?('B2_BUCKET_ID')
42
+
39
43
  config.enabled = (ENV['ASSET_SYNC_ENABLED'] == 'true') if ENV.has_key?('ASSET_SYNC_ENABLED')
40
44
 
41
45
  config.existing_remote_files = ENV['ASSET_SYNC_EXISTING_REMOTE_FILES'] || "keep"
@@ -4,7 +4,7 @@ require "asset_sync/multi_mime"
4
4
 
5
5
  module AssetSync
6
6
  class Storage
7
- REGEXP_FINGERPRINTED_FILES = /^(.*)\/([^-]+)-[^\.]+\.([^\.]+)$/
7
+ REGEXP_FINGERPRINTED_FILES = /\A(.*)\/(.+)-[^\.]+\.([^\.]+)\z/m
8
8
  REGEXP_ASSETS_TO_CACHE_CONTROL = /-[0-9a-fA-F]{32,}$/
9
9
 
10
10
  class BucketNotFound < StandardError;
@@ -22,7 +22,13 @@ module AssetSync
22
22
 
23
23
  def bucket
24
24
  # fixes: https://github.com/rumblelabs/asset_sync/issues/18
25
- @bucket ||= connection.directories.get(self.config.fog_directory, :prefix => self.config.assets_prefix)
25
+
26
+ @bucket ||= if self.config.backblaze?
27
+ connection.directories.get(self.config.fog_directory)
28
+ else
29
+ connection.directories.get(self.config.fog_directory, :prefix => self.config.assets_prefix)
30
+ end
31
+
26
32
  end
27
33
 
28
34
  def log(msg)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssetSync
4
- VERSION = "2.12.1"
4
+ VERSION = "2.14.2"
5
5
  end
@@ -5,7 +5,7 @@ module AssetSync
5
5
 
6
6
  # Commandline options can be defined here using Thor-like options:
7
7
  class_option :use_yml, :type => :boolean, :default => false, :desc => "Use YML file instead of Rails Initializer"
8
- class_option :provider, :type => :string, :default => "AWS", :desc => "Generate with support for 'AWS', 'Rackspace', 'Google', or 'AzureRM"
8
+ class_option :provider, :type => :string, :default => "AWS", :desc => "Generate with support for 'AWS', 'Rackspace', 'Google', 'AzureRM', or 'Backblaze'"
9
9
 
10
10
  def self.source_root
11
11
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
@@ -27,6 +27,10 @@ module AssetSync
27
27
  options[:provider] == 'AzureRM'
28
28
  end
29
29
 
30
+ def backblaze?
31
+ options[:provider] == 'Backblaze'
32
+ end
33
+
30
34
  def aws_access_key_id
31
35
  "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
32
36
  end
@@ -63,6 +67,18 @@ module AssetSync
63
67
  "<%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>"
64
68
  end
65
69
 
70
+ def b2_key_id
71
+ "<%= ENV['B2_KEY_ID'] %>"
72
+ end
73
+
74
+ def b2_key_token
75
+ "<%= ENV['B2_KEY_TOKEN'] %>"
76
+ end
77
+
78
+ def b2_bucket_id
79
+ "<%= ENV['B2_BUCKET_ID'] %>"
80
+ end
81
+
66
82
  def app_name
67
83
  @app_name ||= Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "").downcase
68
84
  end
@@ -35,6 +35,12 @@ if defined?(AssetSync)
35
35
  config.azure_storage_account_name = ENV['AZURE_STORAGE_ACCOUNT_NAME']
36
36
  config.azure_storage_access_key = ENV['AZURE_STORAGE_ACCESS_KEY']
37
37
 
38
+ <%- elsif backblaze? -%>
39
+ config.fog_provider = 'Backblaze'
40
+ config.b2_key_id = ENV['B2_KEY_ID']
41
+ config.b2_key_token = ENV['B2_KEY_TOKEN']
42
+ config.b2_bucket_id = ENV['B2_BUCKET_ID']
43
+
38
44
  # config.fog_directory specifies container name of Azure Blob storage
39
45
  <%- end -%>
40
46
  config.fog_directory = ENV['FOG_DIRECTORY']
@@ -32,8 +32,13 @@ defaults: &defaults
32
32
  fog_provider: 'AzureRM'
33
33
  azure_storage_account_name: "<%= azure_storage_account_name %>"
34
34
  azure_storage_access_key: "<%= azure_storage_access_key %>"
35
-
36
35
  # fog_directory specifies container name of Azure Blob storage
36
+ <%- elsif backblaze? -%>
37
+ fog_provider: Backblaze
38
+ b2_key_id: "<%= b2_key_id %>"
39
+ b2_key_token: "<%= b2_key_token %>"
40
+ b2_bucket_id: "<%= b2_bucket_id %>"
41
+ # fog_directory specifies container name of Backblaze B2 Bucket
37
42
  <%- end -%>
38
43
  fog_directory: "<%= app_name %>-assets"
39
44
 
@@ -0,0 +1,20 @@
1
+ defaults: &defaults
2
+ fog_provider: "Backblaze"
3
+ b2_key_id: 'xxxx'
4
+ b2_key_token: 'zzzz'
5
+ b2_bucket_id: '1234'
6
+
7
+ development:
8
+ <<: *defaults
9
+ fog_directory: "rails_app_development"
10
+ existing_remote_files: keep
11
+
12
+ test:
13
+ <<: *defaults
14
+ fog_directory: "rails_app_test"
15
+ existing_remote_files: keep
16
+
17
+ production:
18
+ <<: *defaults
19
+ fog_directory: "rails_app_production"
20
+ existing_remote_files: delete
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "fog/backblaze"
3
+
4
+ def bucket(name)
5
+ options = {
6
+ :provider => 'Backblaze',
7
+ :b2_key_id => ENV['B2_KEY_ID'],
8
+ :b2_key_token => ENV['B2_KEY_TOKEN'],
9
+ :b2_bucket_id => ENV['B2_BUCKET_ID']
10
+ }
11
+ options.merge!({ :environment => ENV['FOG_REGION'] }) if ENV.has_key?('FOG_REGION')
12
+
13
+ connection = Fog::Storage.new(options)
14
+ connection.directories.get(ENV['FOG_DIRECTORY'])
15
+ end
16
+
17
+ def execute(command)
18
+ app_path = File.expand_path("../../dummy_app", __FILE__)
19
+ Dir.chdir app_path
20
+ `#{command}`
21
+ end
22
+
23
+ describe "AssetSync" do
24
+
25
+ before(:each) do
26
+ @prefix = SecureRandom.hex(6)
27
+ end
28
+
29
+ let(:app_js_regex){
30
+ /#{@prefix}\/application-[a-zA-Z0-9]*.js$/
31
+ }
32
+
33
+ let(:app_js_gz_regex){
34
+ /#{@prefix}\/application-[a-zA-Z0-9]*.js.gz$/
35
+ }
36
+
37
+ let(:files){ bucket(@prefix).files }
38
+
39
+
40
+ after(:each) do
41
+ @directory = bucket(@prefix)
42
+ @directory.files.each do |f|
43
+ f.destroy
44
+ end
45
+ end
46
+
47
+ it "sync" do
48
+ execute "rake ASSET_SYNC_PREFIX=#{@prefix} assets:precompile"
49
+
50
+ files = bucket(@prefix).files
51
+
52
+ app_js = files.select{ |f| f.key =~ app_js_regex }.first
53
+ expect(app_js.content_type).to eq("application/javascript")
54
+
55
+ app_js_gz = files.select{ |f| f.key =~ app_js_gz_regex }.first
56
+ expect(app_js_gz.content_type).to eq("application/javascript")
57
+ expect(app_js_gz.content_encoding).to eq("gzip")
58
+ end
59
+
60
+ it "sync with enabled=false" do
61
+ execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_ENABLED=false assets:precompile"
62
+ expect(bucket(@prefix).files.size).to eq(0)
63
+ end
64
+
65
+ it "sync with gzip_compression=true" do
66
+ execute "rake ASSET_SYNC_PREFIX=#{@prefix} ASSET_SYNC_GZIP_COMPRESSION=true assets:precompile"
67
+ # bucket(@prefix).files.size.should == 3
68
+
69
+ app_js_path = files.select{ |f| f.key =~ app_js_regex }.first
70
+ app_js = files.get( app_js_path.key )
71
+ expect(app_js.content_type).to eq("application/javascript")
72
+ end
73
+
74
+ end
@@ -0,0 +1,150 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe AssetSync do
4
+ include_context "mock Rails without_yml"
5
+
6
+ describe 'with initializer' do
7
+ before(:each) do
8
+ AssetSync.config = AssetSync::Config.new
9
+ AssetSync.configure do |config|
10
+ config.fog_provider = 'Backblaze'
11
+ config.b2_key_id = 'aaaa'
12
+ config.b2_key_token = 'bbbb'
13
+ config.b2_bucket_id = '4567'
14
+ config.fog_directory = 'mybucket'
15
+ config.existing_remote_files = "keep"
16
+ end
17
+ end
18
+
19
+ it "should configure provider as Backblaze" do
20
+ expect(AssetSync.config.fog_provider).to eq('Backblaze')
21
+ end
22
+
23
+ it "should should keep existing remote files" do
24
+ expect(AssetSync.config.existing_remote_files?).to eq(true)
25
+ end
26
+
27
+ it "should configure b2_key_id" do
28
+ expect(AssetSync.config.b2_key_id).to eq("aaaa")
29
+ end
30
+
31
+ it "should configure b2_key_token" do
32
+ expect(AssetSync.config.b2_key_token).to eq("bbbb")
33
+ end
34
+
35
+ it "should configure b2_bucket_id" do
36
+ expect(AssetSync.config.b2_bucket_id).to eq("4567")
37
+ end
38
+
39
+ it "should configure fog_directory" do
40
+ expect(AssetSync.config.fog_directory).to eq("mybucket")
41
+ end
42
+
43
+ it "should configure existing_remote_files" do
44
+ expect(AssetSync.config.existing_remote_files).to eq("keep")
45
+ end
46
+
47
+ it "should default gzip_compression to false" do
48
+ expect(AssetSync.config.gzip_compression).to be_falsey
49
+ end
50
+
51
+ it "should default manifest to false" do
52
+ expect(AssetSync.config.manifest).to be_falsey
53
+ end
54
+ end
55
+
56
+ describe 'from yml' do
57
+ before(:each) do
58
+ set_rails_root('backblaze_with_yml')
59
+ AssetSync.config = AssetSync::Config.new
60
+ end
61
+
62
+ it "should configure b2_key_id" do
63
+ expect(AssetSync.config.b2_key_id).to eq("xxxx")
64
+ end
65
+
66
+ it "should configure b2_key_token" do
67
+ expect(AssetSync.config.b2_key_token).to eq("zzzz")
68
+ end
69
+
70
+ it "should configure b2_bucket_id" do
71
+ expect(AssetSync.config.b2_bucket_id).to eq("1234")
72
+ end
73
+
74
+ it "should configure fog_directory" do
75
+ expect(AssetSync.config.fog_directory).to eq("rails_app_test")
76
+ end
77
+
78
+ it "should configure existing_remote_files" do
79
+ expect(AssetSync.config.existing_remote_files).to eq("keep")
80
+ end
81
+
82
+ it "should default gzip_compression to false" do
83
+ expect(AssetSync.config.gzip_compression).to be_falsey
84
+ end
85
+
86
+ it "should default manifest to false" do
87
+ expect(AssetSync.config.manifest).to be_falsey
88
+ end
89
+ end
90
+
91
+ describe 'with no configuration' do
92
+ before(:each) do
93
+ AssetSync.config = AssetSync::Config.new
94
+ end
95
+
96
+ it "should be invalid" do
97
+ expect{ AssetSync.sync }.to raise_error(::AssetSync::Config::Invalid)
98
+ end
99
+ end
100
+
101
+ describe 'with fail_silent configuration' do
102
+ before(:each) do
103
+ allow(AssetSync).to receive(:stderr).and_return(StringIO.new)
104
+ AssetSync.config = AssetSync::Config.new
105
+ AssetSync.configure do |config|
106
+ config.fail_silently = true
107
+ end
108
+ end
109
+
110
+ it "should not raise an invalid exception" do
111
+ expect{ AssetSync.sync }.not_to raise_error
112
+ end
113
+ end
114
+
115
+ describe 'with gzip_compression enabled' do
116
+ before(:each) do
117
+ AssetSync.config = AssetSync::Config.new
118
+ AssetSync.config.gzip_compression = true
119
+ end
120
+
121
+ it "config.gzip? should be true" do
122
+ expect(AssetSync.config.gzip?).to be_truthy
123
+ end
124
+ end
125
+
126
+ describe 'with manifest enabled' do
127
+ before(:each) do
128
+ AssetSync.config = AssetSync::Config.new
129
+ AssetSync.config.manifest = true
130
+ end
131
+
132
+ it "config.manifest should be true" do
133
+ expect(AssetSync.config.manifest).to be_truthy
134
+ end
135
+
136
+ it "config.manifest_path should default to public/assets.." do
137
+ expect(AssetSync.config.manifest_path).to match(/public\/assets\/manifest.yml/)
138
+ end
139
+
140
+ it "config.manifest_path should default to public/assets.." do
141
+ Rails.application.config.assets.manifest = "/var/assets"
142
+ expect(AssetSync.config.manifest_path).to eq("/var/assets/manifest.yml")
143
+ end
144
+
145
+ it "config.manifest_path should default to public/custom_assets.." do
146
+ Rails.application.config.assets.prefix = 'custom_assets'
147
+ expect(AssetSync.config.manifest_path).to match(/public\/custom_assets\/manifest.yml/)
148
+ end
149
+ end
150
+ end
@@ -99,6 +99,28 @@ describe AssetSync do
99
99
  end
100
100
  end
101
101
 
102
+ describe "when using service account with JSON key string" do
103
+ before(:each) do
104
+ AssetSync.configure do |config|
105
+ config.google_json_key_string = 'a-google-json-key-string'
106
+ config.google_project = 'a-google-project-name'
107
+ end
108
+ end
109
+
110
+ it "should configure google_json_key_string" do
111
+ expect(AssetSync.config.google_json_key_string).to eq("a-google-json-key-string")
112
+ end
113
+
114
+ it "should return the correct fog_options" do
115
+ expected_fog_options = { google_json_key_string: "a-google-json-key-string",
116
+ google_project: 'a-google-project-name',
117
+ provider: "Google"}
118
+ expect(AssetSync.config.fog_options).to eq(expected_fog_options)
119
+ end
120
+ it "should not require that google_storage_secret_access_key or access_key_id be set" do
121
+ expect(AssetSync.config.valid?).to eq(true)
122
+ end
123
+ end
102
124
  end
103
125
 
104
126
  describe 'from yml' do
@@ -137,17 +137,22 @@ describe AssetSync::Storage do
137
137
 
138
138
  it 'should upload updated non-fingerprinted files' do
139
139
  @local_files = [
140
- 'public/image.png',
141
- 'public/image-82389298328.png',
142
- 'public/image-a8389f9h324.png',
140
+ 'public/great-image.png',
141
+ 'public/great-image-82389298328.png',
142
+ 'public/great-image-a8389f9h324.png',
143
+ "public/new\nline.js",
144
+ "public/new\nline-aaaaaaaaaaa.js",
145
+ "public/new\nline-bbbbbbbbbbb.js",
143
146
  'public/application.js',
144
147
  'public/application-b3389d983k1.js',
145
148
  'public/application-ac387d53f31.js',
146
149
  'public',
147
150
  ]
148
151
  @remote_files = [
149
- 'public/image.png',
150
- 'public/image-a8389f9h324.png',
152
+ 'public/great-image.png',
153
+ 'public/great-image-a8389f9h324.png',
154
+ "public/new\nline.js",
155
+ "public/new\nline-aaaaaaaaaaa.js",
151
156
  'public/application.js',
152
157
  'public/application-b3389d983k1.js',
153
158
  ]
@@ -158,7 +163,8 @@ describe AssetSync::Storage do
158
163
  allow(File).to receive(:file?).and_return(true) # Pretend they all exist
159
164
 
160
165
  updated_nonfingerprinted_files = [
161
- 'public/image.png',
166
+ 'public/great-image.png',
167
+ "public/new\nline.js",
162
168
  'public/application.js',
163
169
  ]
164
170
  (@local_files - @remote_files + updated_nonfingerprinted_files).each do |file|
@@ -436,6 +442,7 @@ describe AssetSync::Storage do
436
442
  allow(directory).to receive(:files).and_return([file])
437
443
  allow(file).to receive(:key).and_return('public/image.png')
438
444
  allow(connection).to receive(:directories).and_return(directories)
445
+ allow(config).to receive(:backblaze?).and_return(false)
439
446
  expect(connection).not_to receive(:delete_multiple_objects)
440
447
  expect(file).to receive(:destroy)
441
448
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.1
4
+ version: 2.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hamilton
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-06-17 00:00:00.000000000 Z
14
+ date: 2021-05-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-core
@@ -153,6 +153,20 @@ dependencies:
153
153
  - - ">="
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
+ - !ruby/object:Gem::Dependency
157
+ name: fog-backblaze
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
156
170
  - !ruby/object:Gem::Dependency
157
171
  name: uglifier
158
172
  requirement: !ruby/object:Gem::Requirement
@@ -181,6 +195,20 @@ dependencies:
181
195
  - - ">="
182
196
  - !ruby/object:Gem::Version
183
197
  version: '0'
198
+ - !ruby/object:Gem::Dependency
199
+ name: gem-release
200
+ requirement: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ type: :development
206
+ prerelease: false
207
+ version_requirements: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
184
212
  description: After you run assets:precompile your compiled assets will be synchronised
185
213
  with your S3 bucket.
186
214
  email:
@@ -193,6 +221,7 @@ extensions: []
193
221
  extra_rdoc_files: []
194
222
  files:
195
223
  - ".editorconfig"
224
+ - ".github/workflows/tests.yaml"
196
225
  - ".gitignore"
197
226
  - ".travis.yml"
198
227
  - Appraisals
@@ -203,10 +232,9 @@ files:
203
232
  - UPGRADING.md
204
233
  - asset_sync.gemspec
205
234
  - docs/heroku.md
206
- - gemfiles/rails_5_0.gemfile
207
- - gemfiles/rails_5_1.gemfile
208
235
  - gemfiles/rails_5_2.gemfile
209
236
  - gemfiles/rails_6_0.gemfile
237
+ - gemfiles/rails_6_1.gemfile
210
238
  - lib/asset_sync.rb
211
239
  - lib/asset_sync/asset_sync.rb
212
240
  - lib/asset_sync/config.rb
@@ -223,15 +251,18 @@ files:
223
251
  - spec/dummy_app/app/assets/javascripts/application.js
224
252
  - spec/fixtures/aws_with_yml/config/asset_sync.yml
225
253
  - spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
254
+ - spec/fixtures/backblaze_with_yml/config/asset_sync.yml
226
255
  - spec/fixtures/google_with_service_account_yml/config/asset_sync.yml
227
256
  - spec/fixtures/google_with_yml/config/asset_sync.yml
228
257
  - spec/fixtures/rackspace_with_yml/config/asset_sync.yml
229
258
  - spec/fixtures/with_invalid_yml/config/asset_sync.yml
230
259
  - spec/integration/aws_integration_spec.rb
231
260
  - spec/integration/azure_rm_integration_spec.rb
261
+ - spec/integration/backblaze_intergration_spec.rb
232
262
  - spec/spec_helper.rb
233
263
  - spec/unit/asset_sync_spec.rb
234
264
  - spec/unit/azure_rm_spec.rb
265
+ - spec/unit/backblaze_spec.rb
235
266
  - spec/unit/google_spec.rb
236
267
  - spec/unit/multi_mime_spec.rb
237
268
  - spec/unit/rackspace_spec.rb
@@ -256,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
287
  - !ruby/object:Gem::Version
257
288
  version: '0'
258
289
  requirements: []
259
- rubygems_version: 3.1.4
290
+ rubygems_version: 3.2.18
260
291
  signing_key:
261
292
  specification_version: 4
262
293
  summary: Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and
@@ -266,15 +297,18 @@ test_files:
266
297
  - spec/dummy_app/app/assets/javascripts/application.js
267
298
  - spec/fixtures/aws_with_yml/config/asset_sync.yml
268
299
  - spec/fixtures/azure_rm_with_yml/config/asset_sync.yml
300
+ - spec/fixtures/backblaze_with_yml/config/asset_sync.yml
269
301
  - spec/fixtures/google_with_service_account_yml/config/asset_sync.yml
270
302
  - spec/fixtures/google_with_yml/config/asset_sync.yml
271
303
  - spec/fixtures/rackspace_with_yml/config/asset_sync.yml
272
304
  - spec/fixtures/with_invalid_yml/config/asset_sync.yml
273
305
  - spec/integration/aws_integration_spec.rb
274
306
  - spec/integration/azure_rm_integration_spec.rb
307
+ - spec/integration/backblaze_intergration_spec.rb
275
308
  - spec/spec_helper.rb
276
309
  - spec/unit/asset_sync_spec.rb
277
310
  - spec/unit/azure_rm_spec.rb
311
+ - spec/unit/backblaze_spec.rb
278
312
  - spec/unit/google_spec.rb
279
313
  - spec/unit/multi_mime_spec.rb
280
314
  - spec/unit/rackspace_spec.rb
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rcov", platforms: :mri_18, group: [:development, :test]
6
- gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
7
- gem "jruby-openssl", platform: :jruby
8
- gem "rails", "~> 5.1.0"
9
-
10
- gemspec path: "../"