diff --git a/.travis.yml b/.travis.yml index fcf5119..a4c405d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ services: - redis-server before_script: - cp config.yml.example.$BACKEND config.yml - - mkdir -p tmp && echo "swifttoken" > tmp/swift_token.txt script: ruby spec/$BACKEND/* branches: only: @@ -22,6 +21,5 @@ notifications: on_failure: always env: - BACKEND=s3 - - BACKEND=swift # Run on Docker infrastructure sudo: false diff --git a/Gemfile.lock b/Gemfile.lock index 690eb2c..27e904a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,3 @@ DEPENDENCIES sinatra sinatra-contrib webmock - -BUNDLED WITH - 1.16.0 diff --git a/config.yml.example.swift b/config.yml.example.swift deleted file mode 100644 index 40fa39f..0000000 --- a/config.yml.example.swift +++ /dev/null @@ -1,18 +0,0 @@ -development: &defaults - maintenance: false - swift: &swift_defaults - host: "https://swift.example.com" - redis: - host: localhost - port: 6379 - -test: - <<: *defaults - swift: - host: "https://swift.example.com" - -staging: - <<: *defaults - -production: - <<: *defaults diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb deleted file mode 100644 index cdef119..0000000 --- a/lib/remote_storage/swift.rb +++ /dev/null @@ -1,63 +0,0 @@ -require "rest_client" -require "active_support/core_ext/time/conversions" -require "active_support/core_ext/numeric/time" -require "active_support/core_ext/hash" -require "remote_storage/rest_provider" - -module RemoteStorage - class Swift - include RestProvider - - private - - # Add quotes around the ETag - def format_etag(etag) - %Q("#{etag}") - end - - def base_url - @base_url ||= settings.swift["host"] - end - - def container_url_for(user) - "#{base_url}/rs:documents:#{settings.environment.to_s}/#{user}" - end - - def default_headers - {"x-auth-token" => swift_token} - end - - def reload_swift_token - server.logger.debug "Reloading swift token. Old token: #{settings.swift_token}" - # Remove the line break from the token file. The line break that the - # token script is adding to the file was causing Sentry to reject the - # token field - settings.swift_token = File.read(swift_token_path).rstrip - settings.swift_token_loaded_at = Time.now - server.logger.debug "Reloaded swift token. New token: #{settings.swift_token}" - end - - def swift_token_path - "tmp/swift_token.txt" - end - - def swift_token - reload_swift_token if Time.now - settings.swift_token_loaded_at > 1800 - - settings.swift_token - end - - def deal_with_unauthorized_requests(&block) - begin - block.call - rescue RestClient::Unauthorized => ex - Raven.capture_exception( - ex, - tags: { swift_token: settings.swift_token[0..19], # send the first 20 characters - swift_token_loaded_at: settings.swift_token_loaded_at } - ) - server.halt 500 - end - end - end -end diff --git a/liquor-cabinet.rb b/liquor-cabinet.rb index 8746a42..3217d4f 100644 --- a/liquor-cabinet.rb +++ b/liquor-cabinet.rb @@ -4,7 +4,6 @@ require "json" require "sinatra/base" require 'sinatra/config_file' require "sinatra/reloader" -require "remote_storage/swift" require "remote_storage/s3" class LiquorCabinet < Sinatra::Base @@ -20,10 +19,6 @@ class LiquorCabinet < Sinatra::Base register Sinatra::ConfigFile set :environments, %w{development test production staging} config_file 'config.yml' - if settings.respond_to? :swift - set :swift_token, File.read("tmp/swift_token.txt") - set :swift_token_loaded_at, Time.now - end end configure :development do @@ -130,9 +125,7 @@ class LiquorCabinet < Sinatra::Base def storage @storage ||= begin - if settings.respond_to? :swift - RemoteStorage::Swift.new(settings, self) - elsif settings.respond_to? :s3 + if settings.respond_to? :s3 RemoteStorage::S3.new(settings, self) else puts <<-EOF diff --git a/spec/swift/app_spec.rb b/spec/swift/app_spec.rb deleted file mode 100644 index 9871b4b..0000000 --- a/spec/swift/app_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -require_relative "../spec_helper" - -describe "Swift provider" do - def container_url_for(user) - "#{app.settings.swift["host"]}/rs:documents:test/#{user}" - end - - def storage_class - RemoteStorage::Swift - end - - before do - stub_request(:put, "#{container_url_for("phil")}/food/aguacate"). - to_return(status: 200, headers: { etag: "0815etag", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - # Write new content with an If-Match header (a new Etag is returned) - stub_request(:put, "#{container_url_for("phil")}/food/aguacate"). - with(body: "aye"). - to_return(status: 200, headers: { etag: "0915etag", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:put, "#{container_url_for("phil")}/public/shares/example.jpg"). - to_return(status: 200, headers: { etag: '"0817etag"', content_type: "image/jpeg", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:put, "#{container_url_for("phil")}/public/shares/example_partial.jpg"). - to_return(status: 200, headers: { etag: '"0817etag"', content_type: "image/jpeg", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:head, "#{container_url_for("phil")}/food/aguacate"). - to_return(status: 200, headers: { last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:get, "#{container_url_for("phil")}/food/aguacate"). - to_return(status: 200, body: "rootbody", headers: { etag: "0817etag", content_type: "text/plain; charset=utf-8" }) - stub_request(:delete, "#{container_url_for("phil")}/food/aguacate"). - to_return(status: 200, headers: { etag: "0815etag" }) - stub_request(:get, "#{container_url_for("phil")}/public/shares/example.jpg"). - to_return(status: 200, body: "", headers: { etag: '"0817etag"', content_type: "image/jpeg" }) - stub_request(:get, "#{container_url_for("phil")}/public/shares/example_partial.jpg"). - to_return(status: 206, body: "", headers: { etag: '"0817etag"', content_type: "image/jpeg", content_range: "bytes 0-16/128" }) - - # Write new content to check the metadata in Redis - stub_request(:put, "#{container_url_for("phil")}/food/banano"). - with(body: "si"). - to_return(status: 200, headers: { etag: "0815etag", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:put, "#{container_url_for("phil")}/food/banano"). - with(body: "oh, no"). - to_return(status: 200, headers: { etag: "0817etag", last_modified: "Fri, 04 Mar 2016 12:20:20 GMT" }) - - stub_request(:put, "#{container_url_for("phil")}/food/camaron"). - to_return(status: 200, headers: { etag: "0816etag", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:delete, "#{container_url_for("phil")}/food/camaron"). - to_return(status: 200, headers: { etag: "0816etag" }) - - stub_request(:put, "#{container_url_for("phil")}/food/desayunos/bolon"). - to_return(status: 200, headers: { etag: "0817etag", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - stub_request(:delete, "#{container_url_for("phil")}/food/desayunos/bolon"). - to_return(status: 200, headers: { etag: "0817etag" }) - - # objects in root dir - stub_request(:put, "#{container_url_for("phil")}/bamboo.txt"). - to_return(status: 200, headers: { etag: "0818etag", last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) - - # 404 - stub_request(:head, "#{container_url_for("phil")}/food/steak"). - to_return(status: 404) - stub_request(:get, "#{container_url_for("phil")}/food/steak"). - to_return(status: 404) - stub_request(:delete, "#{container_url_for("phil")}/food/steak"). - to_return(status: 404) - end - - it_behaves_like 'a REST adapter' -end