Working with Hitachi HCP

HCP is an affordable on-premise alternative to Amazon S3. At Indiana we're looking at using it for our deployment, specifically to avoid being tied to a shared file system.

Configuration

If you're using Avalon 7+, these settings need to point to HCP:

config/settings.yml
 minio:
   endpoint: http://hcp.internal.example.edu
   public_host: http://hcp.external.example.edu # if different from endpoint
   access: <access key>
   secret: <secret key>

 Problem

aws-sdk Ruby implementation appends an Accept-Encoding="" header to every request, which HCP doesn't accept. We need to change this header to Accept-Encoding="identity" for all but the presigned URLs. The following code requires aws-sdk v3 to work.

config/initializer/aws.rb
  # Add header for HCP compatibility
  module Seahorse
    module Client
      module Plugins
        class AcceptEncoding < Plugin

          # @api private
          class Handler < Client::Handler

            def call(context)
              context.http_request.headers['Accept-Encoding'] = 'identity'
              @handler.call(context)
            end
          end

          handler(Handler, step: :sign, priority: 0)
        end
      end
    end
  end

  Aws::S3::Client.add_plugin Seahorse::Client::Plugins::AcceptEncoding

  # Exclude this header from the signature calculation otherwise S3 will not accept the presigned_url
  Aws::S3::Presigner::BLACKLISTED_HEADERS = Aws::S3::Presigner::BLACKLISTED_HEADERS + ["accept-encoding"]