bcms_awss3 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "sqlite3"
4
+ gem "browsercms", :path=>"~/projects/browsercms"
5
+ gemspec
6
+
7
+
8
+
@@ -0,0 +1,92 @@
1
+ # Overview
2
+
3
+ A [BrowserCMS](http://www.browsercms.org) module to allow storage of images and files on the Amazon S3 storage facility
4
+
5
+ Note: This is fork of the original [bcms_s3 project](https://github.com/aunderwo/bcms_s3). It has been updated to work with BrowserCMS 3.5.0 and will be published as a gem named bcms_aws_s3 (mainly due to gem ownership).
6
+
7
+ ## Features
8
+
9
+ * Allows uploaded files to be stored on Amazon S3.
10
+ * Option to change caching to suit heroku and/or use 'www' as the prefix for the non-cms site.
11
+
12
+ Note that all file uploaded here are **publicly accessible** on AWS S3, though the paths are pretty hard to guess.
13
+
14
+ ## Installation
15
+
16
+ $ gem install bcms_aws_s3
17
+
18
+ And the following to your gem file
19
+
20
+ gem "bcms_aws_s3"
21
+
22
+ Create a config/s3.yml with your credentials (see below). All files uploaded to the CMS will not be pushed and stored on Amazon s3.
23
+
24
+ ## Using S3 for file storage
25
+
26
+ Adding this gem to your project will automatically configure the CMS to use AWS for storage. If you want to add the gem, but keep using the existing filesystem, configure the following in your config/application.rb.
27
+
28
+ config.cms.attachments.storage = :filesystem # This gems sets this value to :s3 when required.
29
+
30
+ Create a config/s3.yml file that contains your credentials and bucket. This should be in the following format:
31
+
32
+ access_key_id: your AWS access key
33
+ secret_access_key: your AWS secret access key
34
+ bucket: your unique bucket name
35
+
36
+ ### Configuring S3
37
+
38
+ Before you can upload files, you will need to create an S3 bucket (one or more) and configure that. You can configure in either:
39
+
40
+ # config/s3.yml
41
+ bucket: your_project_bucket_name
42
+
43
+ Which will use the same bucket in development, testing and production. Or in an environment file (if you want buckets for each environment)
44
+
45
+ # config/environments/production.rb
46
+ config.cms.attachments.s3_bucket = "your_project_bucket_production"
47
+
48
+ # config/environments/development.rb
49
+ config.cms.attachments.s3_bucket = "your_project_bucket_development"
50
+
51
+ ## Remaining todos
52
+
53
+ 1. cname's don't work currently
54
+ 2. Attachments are public
55
+
56
+ ## Using this module with [Heroku](http://heroku.com)
57
+
58
+ If using this module in conjunction with deployment on heroku you should probably turning heroku caching on by setting Cms::S3.heroku_caching in config/initializers/browsercms.rb to true.
59
+
60
+ In order to avoid putting your secret AWS key in the s3.yml file, you can take advantage of [heroku's config vars](http://docs.heroku.com/config-vars). Use ERB to read the values from the environment. This way you can safely commit your s3.yml file to the repository without revealing your amazon credentials.
61
+
62
+ access_key_id: <%= ENV['s3_access_key_id'] %>
63
+ secret_access_key: <%= ENV['s3_secret_access_key'] %>
64
+ bucket: <%= ENV['s3_bucket'] %>
65
+
66
+ For developing on your local machine, export the s3 variables to your environment.
67
+
68
+ export s3_access_key_id='your AWS access key'
69
+ export s3_secret_access_key='your AWS secret access key'
70
+ export s3_bucket='your unique bucket name'
71
+
72
+ Set the config vars on heroku to get it working there as well.
73
+
74
+ heroku config:add s3_access_key_id='your AWS access key'
75
+ heroku config:add s3_secret_access_key='your AWS secret access key'
76
+ heroku config:add s3_bucket='your unique bucket name'
77
+
78
+ ## www prefix for non cms urls
79
+ If your non cms domain is www.myapp.com rather than app.com this can be enabled by setting Cms::S3.www_domain_prefix in config/initializers/browsercms.rb to true.
80
+
81
+ ## using cnames to your S3 bucket
82
+ If you've set up CNAMES in your DNS to point to your bucket, then you can enable the use of that instead of the FQDN ending in amazonaws.com by setting Cms::S3.options[:s3_cname] in your s3.yml file.
83
+
84
+ ## Important things to note
85
+ 1. The s3.yml should be excluded from public repositories (e.g github) since it contains your secret AWS key which should **never** be revealed to the public.
86
+ **Please note**. This no longer applies since the access keys and buckets are now specified in environmental variables and therefore the s3.yml file now contains just references to these environmental variables.
87
+ 2. Changing from local storage to S3 storage will require you to re-upload all your files (or copy the tree to s3)
88
+
89
+ ## Contributors
90
+
91
+ * Original work on S3 storage for BrowserCMS by [Neil Middleton](http://github.com/neilmiddleton/)
92
+ * v2.1 by [Anthony Underwood](https://github.com/aunderwo)
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module BcmsS3
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module BcmsS3
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ BcmsS3::Engine.routes.draw do
2
+ end
@@ -0,0 +1,6 @@
1
+ require "bcms_s3/engine"
2
+ require "bcms_s3/routes"
3
+
4
+ # This file name is different than bcms_s3 since we don't own the gem and need to publish it.
5
+ module BcmsS3
6
+ end
@@ -0,0 +1,27 @@
1
+ require 'browsercms'
2
+ require 'bcms_s3/s3_module'
3
+ require 'cms/attachments/s3_strategy'
4
+
5
+ module BcmsS3
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace BcmsS3
8
+ include Cms::Module
9
+
10
+ config.before_configuration do
11
+ config.cms.attachments.s3_credentials = "#{Rails.root}/config/s3.yml"
12
+ config.cms.attachments.storage = :s3
13
+ end
14
+
15
+ config.to_prepare do
16
+ Cms::ContentController.send(:include, Cms::S3::ContentController)
17
+ Cms::ApplicationController.send(:include, Cms::S3::ApplicationController)
18
+
19
+ # ensure heroku caching disabled by default
20
+ Cms::S3.heroku_caching = false if Cms::S3.heroku_caching.nil?
21
+
22
+ # function to set domain prefix without url to 'www' is disabled by default
23
+ Cms::S3.www_domain_prefix = false if Cms::S3.www_domain_prefix.nil?
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_s3
3
+
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+ module Cms
2
+ module S3
3
+ class << self
4
+ attr_accessor :heroku_caching
5
+ attr_accessor :www_domain_prefix
6
+ attr_accessor :options
7
+ end
8
+
9
+ module ContentController
10
+ def self.included(controller_class)
11
+ controller_class.alias_method_chain :render_page_with_caching, :s3
12
+ end
13
+ def render_page_with_caching_with_s3
14
+ render_page
15
+ response.headers['Cache-Control'] = 'public, max-age=300' if Cms::S3.heroku_caching
16
+ end
17
+
18
+ end
19
+
20
+ module ApplicationController
21
+ def self.included(controller_class)
22
+ controller_class.alias_method_chain :url_without_cms_domain_prefix, :www
23
+ end
24
+ def url_without_cms_domain_prefix_with_www
25
+ if Cms::S3.www_domain_prefix
26
+ request.url.sub(/#{cms_domain_prefix}\./,'www.')
27
+ else
28
+ request.url.sub(/#{cms_domain_prefix}\./,'')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+
@@ -0,0 +1,3 @@
1
+ module BcmsS3
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ module Cms
2
+ module Attachments
3
+
4
+ # Automatically used to serve files when the following configuration is set:
5
+ # config.cms.attachments.storage = :s3
6
+ class S3Strategy
7
+
8
+ # Redirects users to the file on S3.
9
+ # Issues:
10
+ # 1. No security, all files are assumed to be public
11
+ # 2. CNAMEs are not supported.
12
+ def self.send_attachment(attachment, controller)
13
+ controller.redirect_to attachment.url
14
+
15
+ # Possible s3_cname implementation
16
+ # if Cms::S3.options[:s3_cname]
17
+ # redirect_to("http://#{Cms::S3.options[:s3_cname]}/#{@attachment.file_location}")
18
+ # else
19
+ # redirect_to("http://#{Cms::S3.options[:bucket]}.s3.amazonaws.com/#{@attachment.file_location}")
20
+ # end
21
+ end
22
+
23
+ # For S3, this returns the relative path within the bucket.
24
+ # I.e. http://s3.amazonaws.com/:bucket/:attachments_storage_location/:path_to_file
25
+ def self.attachments_storage_location
26
+ "/attachments"
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bcms_s3 do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BcmsS3Test < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, BcmsS3
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_awss3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - BrowserMedia
9
+ - Anthony Underwood
10
+ - Neil Middleton
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-05-11 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: aws-sdk
18
+ requirement: &70240924799500 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70240924799500
27
+ - !ruby/object:Gem::Dependency
28
+ name: browsercms
29
+ requirement: &70240924798860 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 3.5.0.alpha
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70240924798860
38
+ description: A BrowserCMS module that stores attachments on Amazon S3 rather than
39
+ on the filesystem.
40
+ email: github@browsermedia.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files:
44
+ - README.markdown
45
+ files:
46
+ - app/assets/javascripts/bcms_s3/application.js
47
+ - app/assets/stylesheets/bcms_s3/application.css
48
+ - app/controllers/bcms_s3/application_controller.rb
49
+ - app/helpers/bcms_s3/application_helper.rb
50
+ - config/routes.rb
51
+ - lib/bcms_aws_s3.rb
52
+ - lib/bcms_s3/engine.rb
53
+ - lib/bcms_s3/routes.rb
54
+ - lib/bcms_s3/s3_module.rb
55
+ - lib/bcms_s3/version.rb
56
+ - lib/cms/attachments/s3_strategy.rb
57
+ - lib/tasks/bcms_s3_tasks.rake
58
+ - README.markdown
59
+ - Gemfile
60
+ - test/test_helper.rb
61
+ - test/unit/bcms_s3_test.rb
62
+ homepage: https://github.com/browsermedia/bcms_s3
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: 2749093695110080642
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ segments:
84
+ - 0
85
+ hash: 2749093695110080642
86
+ requirements: []
87
+ rubyforge_project: bcms_awss3
88
+ rubygems_version: 1.8.10
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: An S3 module for BrowserCMS
92
+ test_files:
93
+ - test/test_helper.rb
94
+ - test/unit/bcms_s3_test.rb