prelands_rails 0.1.4 → 0.1.5

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: 9963abae54f24ecedee07af2eda355eb1dda5790141cc4579a4037f2bf12a7d3
4
- data.tar.gz: 8e3608256bd2073be0abc06745e323e55748e8e7418b1907af2b446aa7c48018
3
+ metadata.gz: 7215ed2505e3982375df9f4af396e1cf41f664e66a8b94d0048b4cf825cae7f4
4
+ data.tar.gz: b7537bb7fe333adea7c257964dcf2fc6a45c262e84571345217c7f28e575cee9
5
5
  SHA512:
6
- metadata.gz: 5f815e3ba1532e9e34d67931796a82621b9926421db2db46fcd96ee917271f5bbc155076be23e711a5218ca77c916658ffd96626ba3c2f41a8aed2fd7fae42c4
7
- data.tar.gz: 822108a653b8296a33a542b195fef4c588b6b6f0d7796e148cf354fbe6b1f8ae421d2fc41616549b02534fae312ba2690c939400339ff0b3af7f6ac805f57423
6
+ metadata.gz: 5e58628c60bb44f6fd8ca4455b6459410daab098e2bc5e393ad8438b48adb73304897c3a41e3d58f302bc81c0bb12f3f57313969609bafe6003cc6f3f8c15714
7
+ data.tar.gz: e14305a5130d5f552f09f5f20d02db037ada4ca9e88a8c5b49780cfb36a39f30ff2346d7dc1a0e3ca778eeefe70e56ed86c33a54e41af11f96adc7cecc02a8ac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prelands_rails (0.1.4)
4
+ prelands_rails (0.1.5)
5
5
  aws-sdk
6
6
  interactor (~> 3.0)
7
7
  interactor-contracts
data/README.md CHANGED
@@ -7,4 +7,20 @@
7
7
  1. Bump version inside `prelands_rails.gemspec`.
8
8
  2. Make commit & push to `master` branch.
9
9
  3. Then checkout `tags` branch and `git rebase master` (accept theirs if there are any conflicts).
10
- 4. Then `git push` - and Gitlab CI publish the new version of the gem.
10
+ 4. Then `git push` - and Gitlab CI publish the new version of the gem.
11
+
12
+ # Local developing
13
+
14
+ Execute in bash console using the actual path to the gem folder:
15
+
16
+ bundle config local.prelands_rails /home/scout/git/prelands_rails/
17
+
18
+ Expected output:
19
+
20
+ You are replacing the current global value of local.prelands_rails, which is currently "/home/scout/git/preland_rails/"
21
+
22
+ In the Gemfile of a host application specify actual gem version, branch and semi-github path:
23
+
24
+ gem 'prelands_rails', '0.1.4', github: 'prelands_rails/prelands_rails', branch: 'master'
25
+
26
+ Run `bundle`, launch puma server. Now your host application uses the local files.
@@ -92,6 +92,33 @@ module PrelandsRails
92
92
  end
93
93
  end
94
94
 
95
+ # Переместит файл в пределах +bucket_name+
96
+ # @return true если успешно переместил
97
+ def move_file(s3_old_file_name, s3_new_file_name, bucket_name)
98
+ log :move_file, ['', s3_old_file_name, ' moving to ', s3_new_file_name, ' in ', bucket_name, '.'].join('"')
99
+
100
+ obj = Aws::S3::Object.new(bucket_name, s3_old_file_name, client: @s3.client)
101
+ new_target = [bucket_name, s3_new_file_name].join('/')
102
+
103
+ begin
104
+ obj.move_to new_target
105
+ rescue Aws::S3::Errors::NoSuchKey
106
+ log :move_file, 'Aws::S3::Errors::NoSuchKey: The specified key does not exist: "%s"' % s3_old_file_name
107
+ return false
108
+ end
109
+
110
+ obj = Aws::S3::Object.new(bucket_name, s3_new_file_name, client: @s3.client)
111
+
112
+ begin
113
+ obj.acl.put({ acl: ACL_PUBLIC_READ })
114
+ rescue Aws::S3::Errors::NoSuchKey
115
+ log :move_file_acl_put, 'Aws::S3::Errors::NoSuchKey: The specified key does not exist: "%s"' % s3_old_file_name
116
+ return false
117
+ end
118
+
119
+ true
120
+ end
121
+
95
122
  private
96
123
 
97
124
  def log(method, output)
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrelandsRails
4
+ class RecompileSimpleSource
5
+ class RenameZipFile
6
+ include ::PrelandsRails::AbstractInteractor
7
+ include ::Interactor
8
+ include ::Interactor::Contracts
9
+
10
+ expects do
11
+ required(:aws_prefix).value(type?: String)
12
+ required(:old_aws_prefix).value(type?: String)
13
+ required(:s3_credentials).schema do
14
+ required(:access_key).filled(:str?)
15
+ required(:secret_key).filled(:str?)
16
+ required(:region).filled(:str?)
17
+ end
18
+ required(:zip_bucket_name).filled(:str?)
19
+ end
20
+
21
+ assures do
22
+ required(:is_zip_moved).filled(:bool?)
23
+ end
24
+
25
+ def act
26
+ old_name = '%s/src.zip' % context.old_aws_prefix
27
+ new_name = '%s/src.zip' % context.aws_prefix
28
+
29
+ context.is_zip_moved =
30
+ client.move_file old_name, new_name, context.zip_bucket_name
31
+ end
32
+
33
+ private
34
+
35
+ def client
36
+ return @client if defined?(@client)
37
+
38
+ creds = context.s3_credentials
39
+ @client = ::PrelandsRails::MyAwsClient.new creds[:access_key], creds[:secret_key], creds[:region]
40
+ end
41
+
42
+ on_breach { |breaches| bad_expects breaches }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrelandsRails
4
+ class RecompileSimpleSource
5
+ #
6
+ # обновит запись ::Preland::SimpleSource
7
+ #
8
+ class UpdateRecord
9
+ include ::PrelandsRails::AbstractInteractor
10
+ include ::Interactor
11
+ include ::Interactor::Contracts
12
+ include ::PrelandsRails::Base
13
+
14
+ expects do
15
+ required(:aws_prefix).value(type?: String)
16
+ required(:old_aws_prefix).value(type?: String)
17
+ required(:model_preland_simple_source).filled
18
+ end
19
+
20
+ assures do
21
+ required(:preland_simple_source).filled
22
+ end
23
+
24
+ def act
25
+ source.aws_prefix = context.aws_prefix
26
+ source.save!
27
+ context.preland_simple_source = source
28
+ end
29
+
30
+ private
31
+
32
+ def source
33
+ @source ||= context.model_preland_simple_source.find_by aws_prefix: context.old_aws_prefix
34
+ end
35
+
36
+ on_breach { |breaches| bad_expects breaches }
37
+ end
38
+ end
39
+ end
@@ -18,6 +18,7 @@ module PrelandsRails
18
18
  required(:region).filled(:str?)
19
19
  end
20
20
  required(:bucket_names).value(type?: Array)
21
+ required(:model_preland_simple_source).filled
21
22
  end
22
23
 
23
24
  before do
@@ -33,6 +34,8 @@ module PrelandsRails
33
34
  required(:incoming_locales).filled(type?: Array)
34
35
  required(:files_content).value(type?: Hash)
35
36
  required(:compiled_htmls).value(type?: Hash)
37
+ required(:old_aws_prefix).value(type?: String)
38
+ required(:is_zip_moved).filled(:bool?)
36
39
  end
37
40
 
38
41
  after do
@@ -44,7 +47,11 @@ module PrelandsRails
44
47
  ::PrelandsRails::CreateSimpleSource::DetectIncomingLocales,
45
48
  ::PrelandsRails::CreateSimpleSource::CheckZipFiles,
46
49
  ::PrelandsRails::CreateSimpleSource::Compile,
47
- Upload
50
+ ::PrelandsRails::UpdateSimpleSource::GenerateNewAwsPrefix,
51
+ Upload,
52
+ UpdateRecord, # update aws_prefix
53
+ ::PrelandsRails::UpdateSimpleSource::RemoveContentFromOldAwsPrefix,
54
+ RenameZipFile
48
55
 
49
56
  on_breach { |breaches| bad_expects breaches }
50
57
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrelandsRails
4
+ class UpdateSimpleSource
5
+
6
+ class GenerateNewAwsPrefix
7
+ include ::PrelandsRails::AbstractInteractor
8
+ include ::Interactor
9
+ include ::Interactor::Contracts
10
+
11
+ expects do
12
+ required(:aws_prefix).value(type?: String)
13
+ end
14
+
15
+ assures do
16
+ required(:old_aws_prefix).value(type?: String)
17
+ end
18
+
19
+ def act
20
+ context.old_aws_prefix = context.aws_prefix
21
+ context.aws_prefix = SecureRandom.uuid[0..7]
22
+ end
23
+
24
+ on_breach { |breaches| bad_expects breaches }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrelandsRails
4
+ class UpdateSimpleSource
5
+
6
+ class RemoveContentFromOldAwsPrefix
7
+ include ::PrelandsRails::AbstractInteractor
8
+ include ::Interactor
9
+ include ::Interactor::Contracts
10
+ include ::PrelandsRails::UpdateSimpleSource::Upload::DeleteCompiledFiles
11
+
12
+ expects do
13
+ required(:old_aws_prefix).value(type?: String)
14
+ required(:s3_credentials).schema do
15
+ required(:access_key).filled(:str?)
16
+ required(:secret_key).filled(:str?)
17
+ required(:region).filled(:str?)
18
+ end
19
+ required(:bucket_names).value(type?: Array)
20
+ end
21
+
22
+ def act
23
+ delete_compiled_files(context.old_aws_prefix)
24
+ end
25
+
26
+ on_breach { |breaches| bad_expects breaches }
27
+ end
28
+ end
29
+ end
@@ -11,7 +11,8 @@ module PrelandsRails
11
11
 
12
12
  expects do
13
13
  required(:archive) # Входящий архив с исходниками от фрилансера. Rack::Test::UploadedFile | ActionDispatch::Http::UploadedFile
14
- required(:aws_prefix).value(type?: String) # имя директории в букете
14
+ required(:aws_prefix).value(type?: String)
15
+ required(:old_aws_prefix).value(type?: String)
15
16
  required(:preland_id).filled
16
17
  required(:preland_domain_ids).value(type?: Array)
17
18
  required(:incoming_locales).filled(type?: Array)
@@ -27,10 +28,11 @@ module PrelandsRails
27
28
  end
28
29
 
29
30
  def act
30
- source = context.model_preland_simple_source.find_by aws_prefix: context.aws_prefix
31
+ source = context.model_preland_simple_source.find_by aws_prefix: context.old_aws_prefix
31
32
  source.archive = context.archive if context.archive
32
33
  source.preland_domain_ids = context.preland_domain_ids
33
34
  source.locales = context.incoming_locales
35
+ source.aws_prefix = context.aws_prefix
34
36
  source.save!
35
37
  context.preland_simple_source = source
36
38
  end
@@ -7,16 +7,17 @@ module PrelandsRails
7
7
  # Удалить из +bucket_names+ файлы преленда из директории +aws_prefix+.
8
8
  #
9
9
  module DeleteCompiledFiles
10
- def delete_compiled_files
11
- creds = context.s3_credentials
12
- client = ::PrelandsRails::MyAwsClient.new creds[:access_key], creds[:secret_key], creds[:region]
10
+ def delete_compiled_files(that_aws_prefix = nil)
11
+ aws_prefix = that_aws_prefix || context.aws_prefix
12
+ creds = context.s3_credentials
13
+ client = ::PrelandsRails::MyAwsClient.new creds[:access_key], creds[:secret_key], creds[:region]
13
14
 
14
15
  context.bucket_names.each do |bucket_name|
15
16
  files = client.list_objects bucket_name
16
17
  next unless files
17
18
 
18
19
  files = files.map do |file_name|
19
- { key: file_name } if file_name.index(context.aws_prefix) == 0
20
+ { key: file_name } if file_name.index(aws_prefix) == 0
20
21
  end.compact
21
22
 
22
23
  next if files.empty?
@@ -2,7 +2,11 @@
2
2
 
3
3
  module PrelandsRails
4
4
  #
5
- # Примет zip-файл с исходниками преленда и опубликует этот преленд.
5
+ # Примет zip-файл с исходниками преленда и обновит исходники этого преленда.
6
+ # В результате будет обновлён `aws_prefix` -- имя директории в букете,
7
+ # что позволит избежать кэширования статического контента. . Другими словами,
8
+ # при обновлении файлов не надо ждать, пока Amazon обновит кэш или
9
+ # очищать кэш Amazon-а.
6
10
  #
7
11
  class UpdateSimpleSource
8
12
  include ::PrelandsRails::AbstractInteractor
@@ -41,8 +45,10 @@ module PrelandsRails
41
45
  CheckZipFiles,
42
46
  ValidateZipContent,
43
47
  Compile,
44
- Upload,
45
- UpdateRecord
48
+ GenerateNewAwsPrefix,
49
+ Upload, # to new aws_prefix
50
+ UpdateRecord, # also update aws_prefix
51
+ RemoveContentFromOldAwsPrefix
46
52
 
47
53
  on_breach { |breaches| bad_expects breaches }
48
54
  end
@@ -32,6 +32,8 @@ require 'prelands_rails/create_simple_source'
32
32
  require 'prelands_rails/update_simple_source/upload/delete_compiled_files'
33
33
  require 'prelands_rails/update_simple_source/check_zip_files'
34
34
  require 'prelands_rails/update_simple_source/compile'
35
+ require 'prelands_rails/update_simple_source/generate_new_aws_prefix'
36
+ require 'prelands_rails/update_simple_source/remove_content_from_old_aws_prefix'
35
37
  require 'prelands_rails/update_simple_source/update_record'
36
38
  require 'prelands_rails/update_simple_source/upload'
37
39
  require 'prelands_rails/update_simple_source/validate_zip_content'
@@ -39,8 +41,10 @@ require 'prelands_rails/update_simple_source'
39
41
 
40
42
  require 'prelands_rails/validate_simple_source'
41
43
 
42
- require 'prelands_rails/recompile_simple_source/upload'
43
44
  require 'prelands_rails/recompile_simple_source/download_zip'
45
+ require 'prelands_rails/recompile_simple_source/rename_zip_file'
46
+ require 'prelands_rails/recompile_simple_source/update_record'
47
+ require 'prelands_rails/recompile_simple_source/upload'
44
48
  require 'prelands_rails/recompile_simple_source'
45
49
 
46
50
  module PrelandsRails
@@ -5,7 +5,7 @@ end
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "prelands_rails"
8
- spec.version = "0.1.4"
8
+ spec.version = "0.1.5"
9
9
  spec.authors = ["C80609A"]
10
10
  spec.email = ["c080609a@gmail.com"]
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prelands_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - C80609A
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: interactor
@@ -314,10 +314,14 @@ files:
314
314
  - lib/prelands_rails/create_simple_source/validate_zip_content/validate_js/js.rb
315
315
  - lib/prelands_rails/recompile_simple_source.rb
316
316
  - lib/prelands_rails/recompile_simple_source/download_zip.rb
317
+ - lib/prelands_rails/recompile_simple_source/rename_zip_file.rb
318
+ - lib/prelands_rails/recompile_simple_source/update_record.rb
317
319
  - lib/prelands_rails/recompile_simple_source/upload.rb
318
320
  - lib/prelands_rails/update_simple_source.rb
319
321
  - lib/prelands_rails/update_simple_source/check_zip_files.rb
320
322
  - lib/prelands_rails/update_simple_source/compile.rb
323
+ - lib/prelands_rails/update_simple_source/generate_new_aws_prefix.rb
324
+ - lib/prelands_rails/update_simple_source/remove_content_from_old_aws_prefix.rb
321
325
  - lib/prelands_rails/update_simple_source/update_record.rb
322
326
  - lib/prelands_rails/update_simple_source/upload.rb
323
327
  - lib/prelands_rails/update_simple_source/upload/delete_compiled_files.rb