Module: Deb::S3::Utils

Included in:
Manifest, Package, Package, Release
Defined in:
lib/deb/s3/utils.rb

Class Method Summary collapse

Class Method Details

.access_policyObject



8
# File 'lib/deb/s3/utils.rb', line 8

def access_policy; @access_policy end

.access_policy=(v) ⇒ Object



9
# File 'lib/deb/s3/utils.rb', line 9

def access_policy= v; @access_policy = v end

.bucketObject



6
# File 'lib/deb/s3/utils.rb', line 6

def bucket; @bucket end

.bucket=(v) ⇒ Object



7
# File 'lib/deb/s3/utils.rb', line 7

def bucket= v; @bucket = v end

.debianize_op(op) ⇒ Object



23
24
25
26
27
# File 'lib/deb/s3/utils.rb', line 23

def debianize_op(op)
  # Operators in debian packaging are <<, <=, =, >= and >>
  # So any operator like < or > must be replaced
  {:< => "<<", :> => ">>"}[op.to_sym] or op
end

.gpg_optionsObject



12
# File 'lib/deb/s3/utils.rb', line 12

def gpg_options; @gpg_options end

.gpg_options=(v) ⇒ Object



13
# File 'lib/deb/s3/utils.rb', line 13

def gpg_options= v; @gpg_options = v end

.s3_escape(string) ⇒ Object

from fog, Fog::AWS.escape



36
37
38
39
40
# File 'lib/deb/s3/utils.rb', line 36

def s3_escape(string)
  string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
    "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
  }
end

.s3_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/deb/s3/utils.rb', line 42

def s3_exists?(path)
  AWS::S3::S3Object.exists?(path, Deb::S3::Utils.bucket)
end

.s3_read(path) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/deb/s3/utils.rb', line 46

def s3_read(path)
  return nil unless s3_exists?(path)
  s = ""
  AWS::S3::S3Object.stream(path, Deb::S3::Utils.bucket) do |chunk|
    s += chunk
  end
  s
end

.s3_remove(path) ⇒ Object



63
64
65
# File 'lib/deb/s3/utils.rb', line 63

def s3_remove(path)
  AWS::S3::S3Object.delete(path, Deb::S3::Utils.bucket) if s3_exists?(path)
end

.s3_store(path, filename = nil) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/deb/s3/utils.rb', line 55

def s3_store(path, filename=nil)
  filename = File.basename(path) unless filename
  File.open(path) do |file|
    AWS::S3::S3Object.store(filename, file,
      Deb::S3::Utils.bucket, :access => Deb::S3::Utils.access_policy)
  end
end

.safesystem(*args) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/deb/s3/utils.rb', line 15

def safesystem(*args)
  success = system(*args)
  if !success
    raise "'system(#{args.inspect})' failed with error code: #{$?.exitstatus}"
  end
  return success
end

.signing_keyObject



10
# File 'lib/deb/s3/utils.rb', line 10

def signing_key; @signing_key end

.signing_key=(v) ⇒ Object



11
# File 'lib/deb/s3/utils.rb', line 11

def signing_key= v; @signing_key = v end

.template(path) ⇒ Object



29
30
31
32
33
# File 'lib/deb/s3/utils.rb', line 29

def template(path)
  template_file = File.join(File.dirname(__FILE__), "templates", path)
  template_code = File.read(template_file)
  ERB.new(template_code, nil, "-")
end