aws-sdk-resources 2.1.10 → 2.1.11

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: d82eab920e3920327e72467858eb52048d432efc
4
- data.tar.gz: e5978b84777534653793268e73e2699aab67a69b
3
+ metadata.gz: ffbe024e349c47a5e33aa5379e3308a6e63a5ca6
4
+ data.tar.gz: b0e23cc39bf790b7d955a34787121d0070340515
5
5
  SHA512:
6
- metadata.gz: 41825ae78f1f0c4cecedc6b4a51f2a3ff7052107d2e7ec3a7c28e296f94f809920cf8f167a1dc857c5bdccc4f75fcb93fa124832a74bdb4bb13fbee97d8728cf
7
- data.tar.gz: a73d555d3e57d794cc4e9992598c75a644745761421407eb00fbf850d387a7ae1ad006abddf6912db5c5fb719ffc241700a92773ff8f3dcc3eefa228b79191fb
6
+ metadata.gz: cc23f381add28d612cf00e3af1330209d16fa36be401d78cc539b83ae343b9168099995f8f004736d1595ef5c81e249307221e4224626a805521657f1be71e2c
7
+ data.tar.gz: 20931e36d4bee2f6de27eba4b8e234626085446e112567ffa17082ca278c5e78afee13016e51cdd0032da8d911de9fb56207692aa579c474bc011ed489d51e5c
@@ -5,7 +5,6 @@ module Aws
5
5
  require 'aws-sdk-resources/services/s3/object'
6
6
  require 'aws-sdk-resources/services/s3/object_summary'
7
7
  require 'aws-sdk-resources/services/s3/multipart_upload'
8
- require 'aws-sdk-resources/services/s3/public_url'
9
8
 
10
9
  autoload :Encryption, 'aws-sdk-resources/services/s3/encryption'
11
10
  autoload :FilePart, 'aws-sdk-resources/services/s3/file_part'
@@ -28,15 +28,30 @@ module Aws
28
28
  delete
29
29
  end
30
30
 
31
+ # Returns a public URL for this bucket.
32
+ #
33
+ # bucket = s3.bucket('bucket-name')
34
+ # bucket.url
35
+ # #=> "https://bucket-name.s3.amazonaws.com"
36
+ #
37
+ # You can pass `virtual_host: true` to use the bucket name as the
38
+ # host name.
39
+ #
40
+ # bucket = s3.bucket('my.bucket.com', virtual_host: true)
41
+ # bucket.url
42
+ # #=> "http://my.bucket.com"
43
+ #
44
+ # @option options [Boolean] :virtual_host (false) When `true`,
45
+ # the bucket name will be used as the host name. This is useful
46
+ # when you have a CNAME configured for this bucket.
47
+ #
31
48
  # @return [String] the URL for this bucket.
32
- def url
33
- url = URI.parse(client.config.endpoint.to_s)
34
- if dns_compatible?(url.scheme) && !client.config.force_path_style
35
- url.host = "#{name}.#{url.host}"
49
+ def url(options = {})
50
+ if options[:virtual_host]
51
+ "http://#{name}"
36
52
  else
37
- url.path = "/#{name}"
53
+ s3_bucket_url
38
54
  end
39
- url.to_s
40
55
  end
41
56
 
42
57
  # Creates a {PresignedPost} that makes it easy to upload a file from
@@ -66,10 +81,25 @@ module Aws
66
81
 
67
82
  private
68
83
 
69
- def dns_compatible?(scheme)
70
- Plugins::S3BucketDns.dns_compatible?(name, scheme == 'https')
84
+ def s3_bucket_url
85
+ url = client.config.endpoint.dup
86
+ if bucket_as_hostname?(url.scheme == 'https')
87
+ url.host = "#{name}.#{url.host}"
88
+ else
89
+ url.path += '/' unless url.path[-1] == '/'
90
+ url.path += path_escape(name)
91
+ end
92
+ url.to_s
71
93
  end
72
94
 
95
+ def bucket_as_hostname?(https)
96
+ Plugins::S3BucketDns.dns_compatible?(name, https) &&
97
+ !client.config.force_path_style
98
+ end
99
+
100
+ def path_escape(name)
101
+ name.gsub(/[^\/]+/) {|part| Seahorse::Util.uri_escape(part) }
102
+ end
73
103
  end
74
104
  end
75
105
  end
@@ -33,6 +33,13 @@ module Aws
33
33
  # | `:head` | {Client#head_object} |
34
34
  # | `:delete` | {Client#delete_object} |
35
35
  #
36
+ # @option params [Boolean] :virtual_host (false) When `true` the
37
+ # presigned URL will use the bucket name as a virtual host.
38
+ #
39
+ # bucket = Aws::S3::Bucket.new('my.bucket.com')
40
+ # bucket.object('key').presigned_url(virtual_host: true)
41
+ # #=> "http://my.bucket.com/key?..."
42
+ #
36
43
  # @option params [Integer] :expires_in (900) Number of seconds before
37
44
  # the pre-signed URL expires. This may not exceed one week (604800
38
45
  # seconds).
@@ -55,14 +62,21 @@ module Aws
55
62
  # s3.bucket('bucket-name').object('obj-key').public_url
56
63
  # #=> "https://bucket-name.s3.amazonaws.com/obj-key"
57
64
  #
65
+ # To use virtual hosted bucket url (disables https):
66
+ #
67
+ # s3.bucket('my.bucket.com').object('key').public_url(virtual_host: true)
68
+ # #=> "http://my.bucket.com/key"
69
+ #
70
+ # @option options [Boolean] :virtual_host (false) When `true`, the bucket
71
+ # name will be used as the host name. This is useful when you have
72
+ # a CNAME configured for the bucket.
73
+ #
58
74
  # @return [String]
59
- def public_url
60
- PublicUrl.build(
61
- endpoint: client.config.endpoint,
62
- bucket_name: bucket_name,
63
- object_key: key,
64
- force_path_style: client.config.force_path_style
65
- )
75
+ def public_url(options = {})
76
+ url = URI.parse(bucket.url(options))
77
+ url.path += '/' unless url.path[-1] == '/'
78
+ url.path += key.gsub(/[^\/]+/) { |s| Seahorse::Util.uri_escape(s) }
79
+ url.to_s
66
80
  end
67
81
 
68
82
  # Uploads a file from disk to the current object in S3.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.10
4
+ version: 2.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.10
19
+ version: 2.1.11
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.10
26
+ version: 2.1.11
27
27
  description: Provides resource oriented interfaces and other higher-level abstractions
28
28
  for many AWS services. This gem is part of the official AWS SDK for Ruby.
29
29
  email:
@@ -79,7 +79,6 @@ files:
79
79
  - lib/aws-sdk-resources/services/s3/object.rb
80
80
  - lib/aws-sdk-resources/services/s3/object_summary.rb
81
81
  - lib/aws-sdk-resources/services/s3/presigned_post.rb
82
- - lib/aws-sdk-resources/services/s3/public_url.rb
83
82
  - lib/aws-sdk-resources/services/sns.rb
84
83
  - lib/aws-sdk-resources/services/sns/message_verifier.rb
85
84
  - lib/aws-sdk-resources/services/sqs.rb
@@ -1,71 +0,0 @@
1
- module Aws
2
- module S3
3
- # @api private
4
- module PublicUrl
5
- class << self
6
-
7
- # @option options [required, URI::HTTP, URI::HTTPS] :endpoint
8
- # The Amazon S3 endpoint to generate the public URL against.
9
- #
10
- # @option options [required, String] :bucket_name Name of the bucket
11
- # the object is in.
12
- #
13
- # @option options [required, String] :object_key Key of the object
14
- # to generate a URL for.
15
- #
16
- # @option options [Boolean] :force_path_style (false) When `true`,
17
- # the bucket name will always be part of the URI path. When `false`,
18
- # DNS compatible bucket names will be the endpoint host subdomain.
19
- #
20
- # # path style
21
- # "https://s3.amazonaws.com/bucket-name/key"
22
- #
23
- # # dns-style
24
- # "https://bucket-name.s3.amazonaws.com/key"
25
- #
26
- # @return [String]
27
- def build(options = {})
28
- endpoint = options[:endpoint].dup
29
- apply_bucket_name(endpoint, options)
30
- apply_object_key(endpoint, options)
31
- endpoint.to_s
32
- end
33
-
34
- private
35
-
36
- def apply_bucket_name(endpoint, options)
37
- if path_style?(endpoint, options)
38
- endpoint.path += '/' unless endpoint.path[-1] == '/'
39
- endpoint.path += Seahorse::Util.uri_escape(options[:bucket_name])
40
- else
41
- endpoint.host = options[:bucket_name] + '.' + endpoint.host
42
- end
43
- end
44
-
45
- def apply_object_key(endpoint, options)
46
- key = options[:object_key]
47
- endpoint.path += '/' unless endpoint.path[-1] == '/'
48
- endpoint.path += key.split('/').map { |v| escape(v) }.join('/')
49
- end
50
-
51
- def path_style?(endpoint, options)
52
- options[:force_path_style] == true ||
53
- dns_compat?(endpoint, options) == false
54
- end
55
-
56
- def dns_compat?(endpoint, options)
57
- Aws::Plugins::S3BucketDns.dns_compatible?(
58
- options[:bucket_name],
59
- endpoint.scheme == 'https'
60
- )
61
- end
62
-
63
- def escape(string)
64
- Seahorse::Util.uri_escape(string)
65
- end
66
-
67
-
68
- end
69
- end
70
- end
71
- end