Sha256: b9ac841a8d36546caeb067bfdaf7d7231e816d87f4961d5dce7faf59e7dd2b12

Contents?: true

Size: 1.58 KB

Versions: 219

Compression:

Stored size: 1.58 KB

Contents

require 'kconv'

module DPL
  class Provider
    class GCS < Provider
      requires 'gstore'
      requires 'mime-types', version: '~> 2.0'

      def needs_key?
        false
      end

      def client
        @client ||= GStore::Client.new(
          :access_key => option(:access_key_id),
          :secret_key => option(:secret_access_key)
        )
      end

      def check_auth
        log "Logging in with Access Key: #{option(:access_key_id)[-4..-1].rjust(20, '*')}"
      end

      def upload_path(filename)
        [options[:upload_dir], filename].compact.join("/")
      end

      def push_app
        glob_args = ["**/*"]
        glob_args << File::FNM_DOTMATCH if options[:dot_match]
        Dir.chdir(options.fetch(:local_dir, Dir.pwd)) do
          Dir.glob(*glob_args) do |filename|
            next if File.directory?(filename)
            content_type = MIME::Types.type_for(filename).first.to_s
            opts                  = { :"Content-Type" => content_type }.merge(encoding_option_for(filename))
            opts["Cache-Control"] = options[:cache_control] if options[:cache_control]
            opts["x-goog-acl"]    = options[:acl] if options[:acl]

            client.put_object(
              option(:bucket),
              upload_path(filename),
              { :data => File.read(filename), :headers => opts }
            )
          end
        end
      end

      private
      def encoding_option_for(path)
        if detect_encoding? && encoding_for(path)
          {"Content-Encoding" => encoding_for(path)}
        else
          {}
        end
      end

    end
  end
end

Version data entries

219 entries across 219 versions & 2 rubygems

Version Path
dpl-1.8.32.travis.1900.4 lib/dpl/provider/gcs.rb
dpl-1.8.32.travis.1899.3 lib/dpl/provider/gcs.rb
dpl-1.8.31.travis.1897.3 lib/dpl/provider/gcs.rb
dpl-1.8.31.travis.1898.3 lib/dpl/provider/gcs.rb
dpl-1.8.31 lib/dpl/provider/gcs.rb
dpl-1.8.31.travis.1895.3 lib/dpl/provider/gcs.rb
dpl-1.8.31.travis.1892.3 lib/dpl/provider/gcs.rb
dpl-1.8.31.travis.1882.3 lib/dpl/provider/gcs.rb
dpl-1.8.30 lib/dpl/provider/gcs.rb
dpl-1.8.30.travis.1881.3 lib/dpl/provider/gcs.rb
dpl-1.8.30.travis.1873.3 lib/dpl/provider/gcs.rb
dpl-1.8.30.travis.1853.3 lib/dpl/provider/gcs.rb
dpl-1.8.30.travis.1849.3 lib/dpl/provider/gcs.rb
dpl-1.8.30.travis.1843.3 lib/dpl/provider/gcs.rb
dpl-1.8.29.travis.1841.3 lib/dpl/provider/gcs.rb
dpl-1.8.29 lib/dpl/provider/gcs.rb
dpl-1.8.28 lib/dpl/provider/gcs.rb
dpl-1.8.29.travis.1816.3 lib/dpl/provider/gcs.rb
dpl-1.8.28.travis.1813.3 lib/dpl/provider/gcs.rb
dpl-1.8.28.travis.1809.3 lib/dpl/provider/gcs.rb