serverless_redirector 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: e27b96243c603289eb46266122207a19c29554d6
4
- data.tar.gz: 61edd08f58d9b112c1d0a27ce73c93bd88c96408
3
+ metadata.gz: 534a6bb887966c4cf6d13a019e9881748b22c4be
4
+ data.tar.gz: 42be56020c62ca68f9b8e462a444060ce6407f45
5
5
  SHA512:
6
- metadata.gz: 96605f200de8607cf5c019dc9e69b8f782e639a95bae3139ea2bdd591b54f8293936b8257cb596b7f2a0e8dd6619a2a4a8511074f55e93cd2ffe2cd96565b6a3
7
- data.tar.gz: 556e2fa1603bc3b7c13194fb94f294df9288d2658a1a67a267311f5aa47e77540e16884d810cd718465491c6e474f487dc9744353ad19a768258b139988bd9c0
6
+ metadata.gz: a4533d0c62c12b209a01b99b806f7becbc38b0ee5228f0d93a6478aedcd59ba7a434d65ae88696efd030d4d6ce81af071cd1047936622fe640a239b13e64b0b9
7
+ data.tar.gz: 95af1a2dcda2590ce2bff18a202b818768f4038218180c31384dd0a07923de63a169febac6b181f0782441f4036c5056e02cb73145c1d60c3e60a1e91e70cc8b
@@ -26,4 +26,4 @@ module ServerlessRedirector
26
26
  end
27
27
 
28
28
  end
29
- end
29
+ end
@@ -12,18 +12,21 @@ module ServerlessRedirector
12
12
  attr_accessor :destination_uri, # Target for the syncing...
13
13
  :manifest_path, # Where can we find out manifest?
14
14
  :log_path, # If present, where do we log? (STDOUT, by default)
15
- :dry_run # Is this a dry run?
15
+ :dry_run, # Is this a dry run?
16
+ :skip_deletes, # Deletes have a special ordering to take place to avoid downtime.
16
17
 
17
18
  def initialize(options = {})
18
19
  @dry_run = false
19
20
  @log_path = nil
20
21
  @destination_uri = nil
21
22
  @manifest_path = nil
23
+ @skip_deletes = false
22
24
  unpack_options options
23
25
  end
24
26
 
25
27
  def unpack_options(options)
26
28
  @dry_run = !!options[:dry_run] if options.key?(:dry_run)
29
+ @skip_deletes = !!options[:skip_deletes] if options.key?(:skip_deletes)
27
30
 
28
31
  @manifest_path = options.fetch(:manifest_path) if options.key?(:manifest_path)
29
32
  @log_path = options.fetch(:log_path) if options.key?(:log_path)
@@ -41,7 +44,7 @@ module ServerlessRedirector
41
44
  manifest = create_manifest
42
45
  destination = create_destination
43
46
 
44
- syncer = ServerlessRedirector::Syncer.new(manifest, destination, logger)
47
+ syncer = ServerlessRedirector::Syncer.new(manifest, destination, logger, skip_deletes)
45
48
  syncer.run dry_run
46
49
  end
47
50
 
@@ -72,4 +75,4 @@ module ServerlessRedirector
72
75
 
73
76
 
74
77
  end
75
- end
78
+ end
@@ -1,4 +1,5 @@
1
1
  require 'aws-sdk'
2
+ require 'cgi'
2
3
 
3
4
  module ServerlessRedirector
4
5
  class Destination
@@ -61,6 +62,9 @@ module ServerlessRedirector
61
62
  @uri = uri
62
63
  @bucket_name = uri.host
63
64
  @prefix = uri.path.to_s.empty? ? nil : ::File.join(uri.path[1..-1], "")
65
+ @options = CGI.parse(uri.query || "").each_with_object({}) do |(key, values), out|
66
+ out[key] = values.lastß
67
+ end
64
68
  end
65
69
 
66
70
  def existing
@@ -69,7 +73,7 @@ module ServerlessRedirector
69
73
  end.map do |o|
70
74
  path = o.key.dup
71
75
  path.gsub! /^#{Regexp.escape(prefix)}\/?/, '' if prefix
72
- ServerlessRedirector::Manifest::Redirect.new 'path' => path, 'url' => o.metadata["x-redirector-target"].to_s
76
+ ServerlessRedirector::Manifest::Redirect.new 'path' => path, 'url' => o.metadata[REDIRECT_HEADER_KEY].to_s
73
77
  end
74
78
  end
75
79
 
@@ -91,7 +95,6 @@ module ServerlessRedirector
91
95
  REDIRECT_HEADER_KEY => location
92
96
  }
93
97
  })
94
- puts "WRITTEN"
95
98
  end
96
99
 
97
100
  protected
@@ -99,8 +102,14 @@ module ServerlessRedirector
99
102
  def bucket
100
103
  @bucket ||= begin
101
104
  client = Aws::S3::Client.new
102
- region = client.get_bucket_location(bucket: bucket_name).location_constraint
103
- regional_client = Aws::S3::Client.new(region: region)
105
+ region = @options['client'] || client.get_bucket_location(bucket: bucket_name).location_constraint
106
+
107
+ accelerate = @options['accelerate'] == "true"
108
+
109
+ regional_client = Aws::S3::Client.new(
110
+ region: region,
111
+ use_accelerate_endpoint: accelerate,
112
+ )
104
113
  resource = Aws::S3::Resource.new(client: regional_client)
105
114
  resource.bucket bucket_name
106
115
  end
@@ -116,4 +125,4 @@ module ServerlessRedirector
116
125
 
117
126
  end
118
127
 
119
- end
128
+ end
@@ -5,12 +5,13 @@ require 'yaml'
5
5
  module ServerlessRedirector
6
6
  class Syncer
7
7
 
8
- attr_reader :manifest, :destination, :logger
8
+ attr_reader :manifest, :destination, :logger, :skip_deletes
9
9
 
10
- def initialize(manifest, destination, logger = ::Logger.new(STDOUT))
10
+ def initialize(manifest, destination, logger = ::Logger.new(STDOUT), skip_deletes = false)
11
11
  @manifest = manifest
12
12
  @destination = destination
13
13
  @logger = logger
14
+ @skip_deletes = skip_deletes
14
15
  end
15
16
 
16
17
  def run(dry_run = false)
@@ -39,7 +40,9 @@ module ServerlessRedirector
39
40
  changed = (targets.keys & contents.keys).select { |k| targets[k] != contents[k] }.map { |k| targets[k] }
40
41
 
41
42
  [].tap do |operations|
42
- operations.concat removed.map { |r| Operations::RemoveRedirect.new(r) }
43
+ unless skip_deletes
44
+ operations.concat removed.map { |r| Operations::RemoveRedirect.new(r) }
45
+ end
43
46
  operations.concat added.map { |r| Operations::CreateRedirect.new(r) }
44
47
  operations.concat changed.map { |r| Operations::UpdateDestination.new(r) }
45
48
  end
@@ -65,4 +68,4 @@ module ServerlessRedirector
65
68
  end
66
69
 
67
70
  end
68
- end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module ServerlessRedirector
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverless_redirector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darcy Laycock
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler