moserp-s3sync 1.2.6 → 1.2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +4 -2
  2. data/lib/S3.rb +21 -17
  3. data/lib/S3_s3sync_mod.rb +2 -2
  4. data/lib/s3try.rb +4 -2
  5. metadata +2 -2
data/README CHANGED
@@ -78,7 +78,9 @@ Required:
78
78
  If you don't know what these are, then s3sync is probably not the
79
79
  right tool for you to be starting out with.
80
80
  Optional:
81
- AWS_S3_HOST - I don't see why the default would ever be wrong
81
+ AWS_S3_HOST - Host on which to access the service
82
+ AWS_S3_PORT - Port on which to access the service
83
+ AWS_S3_VIRTUAL_PATH - the path of the service
82
84
  HTTP_PROXY_HOST,HTTP_PROXY_PORT,HTTP_PROXY_USER,HTTP_PROXY_PASSWORD - proxy
83
85
  SSL_CERT_DIR - Where your Cert Authority keys live; for verification
84
86
  SSL_CERT_FILE - If you have just one PEM file for CA verification
@@ -403,4 +405,4 @@ Version 1.2.6
403
405
  Catch connect errors and retry.
404
406
  ----------
405
407
 
406
- FNORD
408
+ FNORD
data/lib/S3.rb CHANGED
@@ -33,12 +33,13 @@ end
33
33
  # in another tool (such as your web browser for GETs).
34
34
  module S3
35
35
  DEFAULT_HOST = 's3.amazonaws.com'
36
+ DEFAULT_VIRTUAL_PATH = ''
36
37
  PORTS_BY_SECURITY = { true => 443, false => 80 }
37
38
  METADATA_PREFIX = 'x-amz-meta-'
38
39
  AMAZON_HEADER_PREFIX = 'x-amz-'
39
40
 
40
41
  # builds the canonical string for signing.
41
- def S3.canonical_string(method, bucket="", path="", path_args={}, headers={}, expires=nil)
42
+ def S3.canonical_string(method, virtual_path, bucket="", path="", path_args={}, headers={}, expires=nil)
42
43
  interesting_headers = {}
43
44
  headers.each do |key, value|
44
45
  lk = key.downcase
@@ -74,6 +75,7 @@ module S3
74
75
  end
75
76
  end
76
77
 
78
+ buf << "#{virtual_path}"
77
79
  # build the path using the bucket and key
78
80
  if not bucket.empty?
79
81
  buf << "/#{bucket}"
@@ -93,7 +95,6 @@ module S3
93
95
  elsif path_args.has_key?('logging')
94
96
  buf << '?logging'
95
97
  end
96
-
97
98
  return buf
98
99
  end
99
100
 
@@ -137,11 +138,12 @@ module S3
137
138
  attr_accessor :calling_format
138
139
 
139
140
  def initialize(aws_access_key_id, aws_secret_access_key, is_secure=true,
140
- server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure],
141
+ server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure], vpath=DEFAULT_VIRTUAL_PATH,
141
142
  calling_format=CallingFormat::REGULAR)
142
143
  @aws_access_key_id = aws_access_key_id
143
144
  @aws_secret_access_key = aws_secret_access_key
144
145
  @server = server
146
+ @virtual_path = vpath
145
147
  @is_secure = is_secure
146
148
  @calling_format = calling_format
147
149
  @port = port
@@ -221,7 +223,6 @@ end
221
223
 
222
224
  private
223
225
  def make_request(method, bucket='', key='', path_args={}, headers={}, data='', metadata={})
224
-
225
226
  # build the domain based on the calling format
226
227
  server = ''
227
228
  if bucket.empty?
@@ -234,11 +235,11 @@ end
234
235
  elsif @calling_format == CallingFormat::VANITY
235
236
  server = bucket
236
237
  else
237
- server = @server
238
+ server = "#{@server}"
238
239
  end
239
240
 
240
241
  # build the path based on the calling format
241
- path = ''
242
+ path = "#{@virtual_path}"
242
243
  if (not bucket.empty?) and (@calling_format == CallingFormat::REGULAR)
243
244
  path << "/#{bucket}"
244
245
  end
@@ -260,7 +261,7 @@ end
260
261
  set_headers(req, headers)
261
262
  set_headers(req, metadata, METADATA_PREFIX)
262
263
 
263
- set_aws_auth_header(req, @aws_access_key_id, @aws_secret_access_key, bucket, key, path_args)
264
+ set_aws_auth_header(req, @aws_access_key_id, @aws_secret_access_key, @virtual_path, bucket, key, path_args)
264
265
  if req.request_body_permitted?
265
266
  return http.request(req, data)
266
267
  else
@@ -285,7 +286,7 @@ end
285
286
  end
286
287
 
287
288
  # set the Authorization header using AWS signed header authentication
288
- def set_aws_auth_header(request, aws_access_key_id, aws_secret_access_key, bucket='', key='', path_args={})
289
+ def set_aws_auth_header(request, aws_access_key_id, aws_secret_access_key, virtual_path='', bucket='', key='', path_args={})
289
290
  # we want to fix the date here if it's not already been done.
290
291
  request['Date'] ||= Time.now.httpdate
291
292
 
@@ -296,7 +297,7 @@ end
296
297
  request['Content-Type'] ||= ''
297
298
 
298
299
  canonical_string =
299
- S3.canonical_string(request.method, bucket, key, path_args, request.to_hash, nil)
300
+ S3.canonical_string(request.method, virtual_path, bucket, key, path_args, request.to_hash, nil)
300
301
  encoded_canonical = S3.encode(aws_secret_access_key, canonical_string)
301
302
 
302
303
  request['Authorization'] = "AWS #{aws_access_key_id}:#{encoded_canonical}"
@@ -325,12 +326,13 @@ end
325
326
  DEFAULT_EXPIRES_IN = 60
326
327
 
327
328
  def initialize(aws_access_key_id, aws_secret_access_key, is_secure=true,
328
- server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure],
329
+ server=DEFAULT_HOST, port=PORTS_BY_SECURITY[is_secure], vpath=DEFAULT_VIRTUAL_PATH,
329
330
  format=CallingFormat::REGULAR)
330
331
  @aws_access_key_id = aws_access_key_id
331
332
  @aws_secret_access_key = aws_secret_access_key
332
333
  @protocol = is_secure ? 'https' : 'http'
333
334
  @server = server
335
+ @virtual_path = vpath
334
336
  @port = port
335
337
  @calling_format = format
336
338
  # by default expire
@@ -429,11 +431,11 @@ end
429
431
  end
430
432
 
431
433
  canonical_string =
432
- S3::canonical_string(method, bucket, key, path_args, headers, expires)
434
+ S3::canonical_string(method, @virtual_path, bucket, key, path_args, headers, expires)
433
435
  encoded_canonical =
434
436
  S3::encode(@aws_secret_access_key, canonical_string)
435
437
 
436
- url = CallingFormat.build_url_base(@protocol, @server, @port, bucket, @calling_format)
438
+ url = CallingFormat.build_url_base(@protocol, @server, @port, @virtual_path, bucket, @calling_format)
437
439
 
438
440
  path_args["Signature"] = encoded_canonical.to_s
439
441
  path_args["Expires"] = expires.to_s
@@ -469,16 +471,16 @@ end
469
471
  VANITY = 2 # http://<vanity_domain>/key -- vanity_domain resolves to s3.amazonaws.com
470
472
 
471
473
  # build the url based on the calling format, and bucket
472
- def CallingFormat.build_url_base(protocol, server, port, bucket, format)
474
+ def CallingFormat.build_url_base(protocol, server, port, vpath, bucket, format)
473
475
  build_url_base = "#{protocol}://"
474
476
  if bucket.empty?
475
- build_url_base << "#{server}:#{port}"
477
+ build_url_base << "#{server}:#{port}/${vpath}"
476
478
  elsif format == SUBDOMAIN
477
- build_url_base << "#{bucket}.#{server}:#{port}"
479
+ build_url_base << "#{bucket}.#{server}:#{port}/${vpath}"
478
480
  elsif format == VANITY
479
- build_url_base << "#{bucket}:#{port}"
481
+ build_url_base << "#{bucket}:#{port}/${vpath}"
480
482
  else
481
- build_url_base << "#{server}:#{port}/#{bucket}"
483
+ build_url_base << "#{server}:#{port}/${vpath}/#{bucket}"
482
484
  end
483
485
  return build_url_base
484
486
  end
@@ -566,8 +568,10 @@ end
566
568
  elsif name == 'StorageClass'
567
569
  @curr_entry.storage_class = @curr_text
568
570
  elsif name == 'ID'
571
+ @curr_entry.owner = Owner.new if !@curr_entry.owner
569
572
  @curr_entry.owner.id = @curr_text
570
573
  elsif name == 'DisplayName'
574
+ @curr_entry.owner = Owner.new if !@curr_entry.owner
571
575
  @curr_entry.owner.display_name = @curr_text
572
576
  elsif name == 'CommonPrefixes'
573
577
  @common_prefixes << @common_prefix_entry
data/lib/S3_s3sync_mod.rb CHANGED
@@ -60,7 +60,7 @@ module S3
60
60
  alias __make_request__ make_request
61
61
  def make_request(method, bucket='', key='', path_args={}, headers={}, data='', metadata={}, streamOut=nil)
62
62
  # build the path based on the calling format
63
- path = ''
63
+ path = "#{@virtual_path}"
64
64
  if (not bucket.empty?) and (@calling_format == CallingFormat::REGULAR)
65
65
  path << "/#{bucket}"
66
66
  end
@@ -80,7 +80,7 @@ module S3
80
80
  set_headers(req, metadata, METADATA_PREFIX)
81
81
  set_headers(req, {'Connection' => 'keep-alive', 'Keep-Alive' => '300'})
82
82
 
83
- set_aws_auth_header(req, @aws_access_key_id, @aws_secret_access_key, bucket, key, path_args)
83
+ set_aws_auth_header(req, @aws_access_key_id, @aws_secret_access_key, @virtual_path, bucket, key, path_args)
84
84
 
85
85
  http = $S3syncHttp
86
86
 
data/lib/s3try.rb CHANGED
@@ -12,6 +12,8 @@ module S3sync
12
12
  $AWS_ACCESS_KEY_ID = ENV["AWS_ACCESS_KEY_ID"]
13
13
  $AWS_SECRET_ACCESS_KEY = ENV["AWS_SECRET_ACCESS_KEY"]
14
14
  $AWS_S3_HOST = (ENV["AWS_S3_HOST"] or "s3.amazonaws.com")
15
+ $AWS_S3_PORT = (ENV["AWS_S3_PORT"] or "80")
16
+ $AWS_S3_VIRTUAL_PATH = (ENV["AWS_S3_VIRTUAL_PATH"] or "")
15
17
  $HTTP_PROXY_HOST = ENV["HTTP_PROXY_HOST"]
16
18
  $HTTP_PROXY_PORT = ENV["HTTP_PROXY_PORT"]
17
19
  $HTTP_PROXY_USER = ENV["HTTP_PROXY_USER"]
@@ -40,7 +42,7 @@ module S3sync
40
42
 
41
43
  # ---------- CONNECT ---------- #
42
44
 
43
- $S3syncConnection = S3::AWSAuthConnection.new($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $S3syncOptions['--ssl'], $AWS_S3_HOST)
45
+ $S3syncConnection = S3::AWSAuthConnection.new($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $S3syncOptions['--ssl'], $AWS_S3_HOST, $AWS_S3_PORT, $AWS_S3_VIRTUAL_PATH)
44
46
  $S3syncConnection.calling_format = S3::CallingFormat::string_to_format($AWS_CALLING_FORMAT)
45
47
  if $S3syncOptions['--ssl']
46
48
  if $SSL_CERT_DIR
@@ -53,7 +55,7 @@ module S3sync
53
55
  end
54
56
  end
55
57
  def S3sync.s3urlSetup
56
- $S3syncGenerator = S3::QueryStringAuthGenerator.new($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $S3syncOptions['--ssl'], $AWS_S3_HOST)
58
+ $S3syncGenerator = S3::QueryStringAuthGenerator.new($AWS_ACCESS_KEY_ID, $AWS_SECRET_ACCESS_KEY, $S3syncOptions['--ssl'], $AWS_S3_HOST, $AWS_S3_PORT, $AWS_S3_VIRTUAL_PATH)
57
59
  $S3syncGenerator.calling_format = S3::CallingFormat::string_to_format($AWS_CALLING_FORMAT)
58
60
  $S3syncGenerator.expires_in = $S3syncOptions['--expires-in']
59
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moserp-s3sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ""
@@ -36,7 +36,7 @@ files:
36
36
  - README
37
37
  - README_s3cmd
38
38
  has_rdoc: true
39
- homepage: http://s3sync.net/
39
+ homepage: http://github.com/moserp/s3sync
40
40
  licenses: []
41
41
 
42
42
  post_install_message: