Sha256: 941522946d5328335dcaa5c947c28295e1e0f153c11c6ffcf0c94274bfe00d02

Contents?: true

Size: 1.56 KB

Versions: 210

Compression:

Stored size: 1.56 KB

Contents

require 'kconv'

module DPL
  class Provider
    class GCS < Provider
      requires 'gstore'
      requires 'mime-types'

      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

210 entries across 210 versions & 1 rubygems

Version Path
dpl-1.8.9.travis.1204.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1203.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1202.4 lib/dpl/provider/gcs.rb
dpl-1.8.8 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1201.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1187.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1183.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1179.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1167.4 lib/dpl/provider/gcs.rb
dpl-1.8.8.travis.1151.4 lib/dpl/provider/gcs.rb
dpl-1.8.7 lib/dpl/provider/gcs.rb
dpl-1.8.7.travis.1150.4 lib/dpl/provider/gcs.rb
dpl-1.8.7.travis.1149.4 lib/dpl/provider/gcs.rb
dpl-1.8.7.travis.1145.4 lib/dpl/provider/gcs.rb
dpl-1.8.7.travis.1144.4 lib/dpl/provider/gcs.rb
dpl-1.8.7.travis.1143.4 lib/dpl/provider/gcs.rb
dpl-1.8.7.travis.1125.4 lib/dpl/provider/gcs.rb
dpl-1.8.6.travis.1124.4 lib/dpl/provider/gcs.rb
dpl-1.8.6 lib/dpl/provider/gcs.rb
dpl-1.8.6.travis.1116.4 lib/dpl/provider/gcs.rb