Class: DPL::Provider::GCS

Inherits:
DPL::Provider show all
Defined in:
lib/dpl/provider/gcs.rb

Instance Attribute Summary

Attributes inherited from DPL::Provider

#context, #options

Instance Method Summary collapse

Methods inherited from DPL::Provider

apt_get, #check_app, #cleanup, #commit_msg, context, #create_key, #deploy, #detect_encoding?, #encoding_for, #error, experimental, #initialize, #log, new, npm_g, #option, pip, requires, #run, #setup_git_credentials, #setup_git_ssh, #sha, shell, #uncleanup, #user_agent, #warn

Constructor Details

This class inherits a constructor from DPL::Provider

Instance Method Details

#check_authObject



20
21
22
# File 'lib/dpl/provider/gcs.rb', line 20

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

#clientObject



13
14
15
16
17
18
# File 'lib/dpl/provider/gcs.rb', line 13

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

#needs_key?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/dpl/provider/gcs.rb', line 9

def needs_key?
  false
end

#push_appObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dpl/provider/gcs.rb', line 28

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

#upload_path(filename) ⇒ Object



24
25
26
# File 'lib/dpl/provider/gcs.rb', line 24

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