From 33977252c9f1c123e78de8e77a08fde0f4b98853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 20 Jul 2013 11:30:36 +0200 Subject: [PATCH 1/3] rollback to previous s3 syntax (ie. subdomains) --- app/models/upload.rb | 2 +- lib/s3_store.rb | 4 ---- spec/components/s3_store_spec.rb | 2 +- spec/models/upload_spec.rb | 20 +------------------- 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index fedb1ac4f..9d577f203 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -99,7 +99,7 @@ class Upload < ActiveRecord::Base end def self.is_on_s3?(url) - SiteSetting.enable_s3_uploads? && (url.start_with?(S3Store.base_url) || url.start_with?(S3Store.base_url_old)) + SiteSetting.enable_s3_uploads? && url.start_with?(S3Store.base_url) end def self.get_from_url(url) diff --git a/lib/s3_store.rb b/lib/s3_store.rb index a61d311e2..3079a9df2 100644 --- a/lib/s3_store.rb +++ b/lib/s3_store.rb @@ -13,10 +13,6 @@ module S3Store end def self.base_url - "//s3.amazonaws.com/#{SiteSetting.s3_upload_bucket}" - end - - def self.base_url_old "//#{SiteSetting.s3_upload_bucket.downcase}.s3.amazonaws.com" end diff --git a/spec/components/s3_store_spec.rb b/spec/components/s3_store_spec.rb index 7fd490e65..faa022dfa 100644 --- a/spec/components/s3_store_spec.rb +++ b/spec/components/s3_store_spec.rb @@ -25,7 +25,7 @@ describe S3Store do it 'returns the url of the S3 upload if successful' do # NOTE: s3 bucket's name are case sensitive so we can't use it as a subdomain... - S3Store.store_file(file, "SHA", 1).should == '//s3.amazonaws.com/S3_Upload_Bucket/1SHA.png' + S3Store.store_file(file, "SHA", 1).should == '//s3_upload_bucket.s3.amazonaws.com/1SHA.png' end after(:each) do diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index f0a07fcbb..30333aa18 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -164,7 +164,7 @@ describe Upload do it "identifies S3 uploads" do SiteSetting.stubs(:enable_s3_uploads).returns(true) SiteSetting.stubs(:s3_upload_bucket).returns("Bucket") - Upload.has_been_uploaded?("//s3.amazonaws.com/Bucket/1337.png").should == true + Upload.has_been_uploaded?("//bucket.s3.amazonaws.com/1337.png").should == true end it "identifies external urls" do @@ -174,24 +174,6 @@ describe Upload do end - context ".is_on_s3?" do - - before do - SiteSetting.stubs(:enable_s3_uploads).returns(true) - SiteSetting.stubs(:s3_upload_bucket).returns("BuCkEt") - end - - it "case-insensitively matches the old subdomain format" do - Upload.is_on_s3?("//bucket.s3.amazonaws.com/1337.png").should == true - end - - it "case-sensitively matches the new folder format" do - Upload.is_on_s3?("//s3.amazonaws.com/BuCkEt/1337.png").should == true - Upload.is_on_s3?("//s3.amazonaws.com/bucket/1337.png").should == false - end - - end - context ".get_from_url" do it "works only when the file has been uploaded" do From 613e31d3efebd031b70b2c319add56714007f38f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 20 Jul 2013 11:54:21 +0200 Subject: [PATCH 2/3] added a warning regarding the case of the s3_upload_bucket setting until we get proper setting validation. --- config/locales/server.en.yml | 2 +- config/locales/server.fr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 85b0fd274..2c09337f1 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -582,7 +582,7 @@ en: suggested_topics: "The number of suggested topics shown at the bottom of a topic" enable_s3_uploads: "Place uploads on Amazon S3" - s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into" + s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase (cf. http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html)" s3_access_key_id: "The Amazon S3 access key id that will be used to upload images" s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images" s3_region: "The Amazon S3 region name that will be used to upload images" diff --git a/config/locales/server.fr.yml b/config/locales/server.fr.yml index 00be8d321..05dd3a0c3 100644 --- a/config/locales/server.fr.yml +++ b/config/locales/server.fr.yml @@ -551,7 +551,7 @@ fr: suggested_topics: "Nombre de discussions suggerées en dessous d'une discussion" enable_s3_uploads: "S'il faut ou non uploader sur s3" - s3_upload_bucket: "Le bucket dans lequel uploader sur s3" + s3_upload_bucket: "Le nom du bucket s3 où seront uploader les fichiers. ATTENTION : le nom doit être en minuscule (cf. http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html)" s3_secret_access_key: "La clé secrète Amazon S3 qui va être utilisée pour uploader des images" s3_region: "Le nom de la région Amazon S3 qui va être utilisée pour uploader des images" From 945ee5dda0147c29b9fd6f77443322e42b1f0b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Sat, 20 Jul 2013 12:13:31 +0200 Subject: [PATCH 3/3] opps. missed a comment --- spec/components/s3_store_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/components/s3_store_spec.rb b/spec/components/s3_store_spec.rb index faa022dfa..1d8062407 100644 --- a/spec/components/s3_store_spec.rb +++ b/spec/components/s3_store_spec.rb @@ -24,7 +24,6 @@ describe S3Store do end it 'returns the url of the S3 upload if successful' do - # NOTE: s3 bucket's name are case sensitive so we can't use it as a subdomain... S3Store.store_file(file, "SHA", 1).should == '//s3_upload_bucket.s3.amazonaws.com/1SHA.png' end