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



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

def access_policy; @access_policy end

.access_policy=(v) ⇒ Object



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

def access_policy= v; @access_policy = v end

.bucketObject



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

def bucket; @bucket end

.bucket=(v) ⇒ Object



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

def bucket= v; @bucket = v end

.debianize_op(op) ⇒ Object



27
28
29
30
31
# File 'lib/deb/s3/utils.rb', line 27

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



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

def gpg_options; @gpg_options end

.gpg_options=(v) ⇒ Object



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

def gpg_options= v; @gpg_options = v end

.prefixObject



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

def prefix; @prefix end

.prefix=(v) ⇒ Object



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

def prefix= v; @prefix = v end

.s3Object



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

def s3; @s3 end

.s3=(v) ⇒ Object



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

def s3= v; @s3 = v end

.s3_escape(string) ⇒ Object

from fog, Fog::AWS.escape



44
45
46
47
48
# File 'lib/deb/s3/utils.rb', line 44

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

.s3_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/deb/s3/utils.rb', line 50

def s3_exists?(path)
  Deb::S3::Utils.s3.buckets[Deb::S3::Utils.bucket].objects[s3_path(path)].exists?
end

.s3_path(path) ⇒ Object



39
40
41
# File 'lib/deb/s3/utils.rb', line 39

def s3_path(path)
  File.join(*[Deb::S3::Utils.prefix, path].compact)
end

.s3_read(path) ⇒ Object



54
55
56
57
# File 'lib/deb/s3/utils.rb', line 54

def s3_read(path)
  return nil unless s3_exists?(path)
  Deb::S3::Utils.s3.buckets[Deb::S3::Utils.bucket].objects[s3_path(path)].read
end

.s3_remove(path) ⇒ Object



68
69
70
# File 'lib/deb/s3/utils.rb', line 68

def s3_remove(path)
  Deb::S3::Utils.s3.buckets[Deb::S3::Utils.bucket].objects[s3_path(path)].delete if s3_exists?(path)
end

.s3_store(path, filename = nil) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/deb/s3/utils.rb', line 59

def s3_store(path, filename=nil)
  filename = File.basename(path) unless filename
  File.open(path) do |file|
    o = Deb::S3::Utils.s3.buckets[Deb::S3::Utils.bucket].objects[s3_path(filename)]
    o.write(file)
    o.acl = Deb::S3::Utils.access_policy
  end
end

.safesystem(*args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/deb/s3/utils.rb', line 19

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

.signing_keyObject



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

def signing_key; @signing_key end

.signing_key=(v) ⇒ Object



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

def signing_key= v; @signing_key = v end

.template(path) ⇒ Object



33
34
35
36
37
# File 'lib/deb/s3/utils.rb', line 33

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