Class: Configuration::S3SourceStoreBase
- Inherits:
-
SourceStoreBase
- Object
- HandlerStatement
- SourceStoreBase
- Configuration::S3SourceStoreBase
- Extended by:
- Stats
- Includes:
- ClassLogging
- Defined in:
- lib/httpimagestore/configuration/s3.rb
Defined Under Namespace
Classes: CacheObject, CacheRoot, S3Object
Instance Attribute Summary
Attributes inherited from HandlerStatement
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(global, image_name, matcher, bucket, path_spec, public_access, cache_control, prefix, cache_root) ⇒ S3SourceStoreBase
constructor
A new instance of S3SourceStoreBase.
- #object(path) ⇒ Object
- #url(object) ⇒ Object
Methods inherited from HandlerStatement
Constructor Details
#initialize(global, image_name, matcher, bucket, path_spec, public_access, cache_control, prefix, cache_root) ⇒ S3SourceStoreBase
Returns a new instance of S3SourceStoreBase.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/httpimagestore/configuration/s3.rb', line 317 def initialize(global, image_name, matcher, bucket, path_spec, public_access, cache_control, prefix, cache_root) super global, image_name, matcher, path_spec @bucket = bucket @public_access = public_access @cache_control = cache_control @prefix = prefix @cache_root = nil begin if cache_root @cache_root = CacheRoot.new(cache_root) log.info "using S3 object cache directory '#{cache_root}' for image '#{image_name}'" else log.info "S3 object cache not configured (no cache-root) for image '#{image_name}'" end rescue CacheRoot::CacheRootNotDirError => error log.warn "not using S3 object cache for image '#{image_name}'", error end config_local :bucket, @bucket end |
Class Method Details
.parse(configuration, node) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/httpimagestore/configuration/s3.rb', line 293 def self.parse(configuration, node) image_name = node.grab_values('image name').first node.required_attributes('bucket', 'path') node.valid_attribute_values('public_access', true, false, nil) bucket, path_spec, public_access, cache_control, prefix, cache_root, if_image_name_on = *node.grab_attributes('bucket', 'path', 'public', 'cache-control', 'prefix', 'cache-root', 'if-image-name-on') public_access = false if public_access.nil? prefix = '' if prefix.nil? self.new( configuration.global, image_name, InclusionMatcher.new(image_name, if_image_name_on), bucket, path_spec, public_access, cache_control, prefix, cache_root ) end |
Instance Method Details
#client ⇒ Object
339 340 341 |
# File 'lib/httpimagestore/configuration/s3.rb', line 339 def client @global.s3 or raise S3NotConfiguredError end |
#object(path) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/httpimagestore/configuration/s3.rb', line 351 def object(path) begin key = @prefix + path image = nil if @cache_root begin cache_file = @cache_root.cache_file(@bucket, key) CacheObject.new(cache_file, client, @bucket, key) do |obj| image = yield obj end return image rescue Errno::EACCES, IOError => error log.warn "cannot use S3 object cache for bucket: '#{@bucket}' key: '#{key}' [#{cache_file}]", error end end return yield S3Object.new(client, @bucket, key) rescue AWS::S3::Errors::AccessDenied raise S3AccessDenied.new(@bucket, path) rescue AWS::S3::Errors::NoSuchBucket raise S3NoSuchBucketError.new(@bucket) rescue AWS::S3::Errors::NoSuchKey raise S3NoSuchKeyError.new(@bucket, path) end end |
#url(object) ⇒ Object
343 344 345 346 347 348 349 |
# File 'lib/httpimagestore/configuration/s3.rb', line 343 def url(object) if @public_access object.public_url else object.private_url end end |