Class: FRM::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/frm/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
3
4
5
|
# File 'lib/frm/base.rb', line 3
def initialize
@retries = 3
end
|
Instance Method Details
#compute_md5(string) ⇒ Object
7
8
9
|
# File 'lib/frm/base.rb', line 7
def compute_md5(string)
Digest::MD5.hexdigest(string)
end
|
#compute_sha1(string) ⇒ Object
11
12
13
|
# File 'lib/frm/base.rb', line 11
def compute_sha1(string)
Digest::SHA1.hexdigest(string)
end
|
#compute_sha2(string) ⇒ Object
15
16
17
|
# File 'lib/frm/base.rb', line 15
def compute_sha2(string)
Digest::SHA2.hexdigest(string)
end
|
#generate_gzip_pipe(contents) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/frm/base.rb', line 48
def generate_gzip_pipe(contents)
read_buffer, write_buffer = IO.pipe
gzip_writer = Zlib::GzipWriter.new write_buffer
gzip_writer.mtime = 1 gzip_writer.write contents
gzip_writer.close
read_buffer
end
|
#gpg_clearsign(message) ⇒ Object
TODO: there has to be a better way to use gpg withen ruby. found many broken solutions :\
33
34
35
|
# File 'lib/frm/base.rb', line 33
def gpg_clearsign(message)
run "echo '#{message}' | gpg --clearsign"
end
|
#gpg_detached(message) ⇒ Object
38
39
40
|
# File 'lib/frm/base.rb', line 38
def gpg_detached(message)
run "echo '#{message}' | gpg -abs"
end
|
#gpg_export_pubkey ⇒ Object
43
44
45
|
# File 'lib/frm/base.rb', line 43
def gpg_export_pubkey
run "gpg --armor --export"
end
|
#gunzip_pipe(gziped_pipe) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/frm/base.rb', line 57
def gunzip_pipe(gziped_pipe)
gzip_reader = Zlib::GzipReader.new gziped_pipe
unzipped_string = gzip_reader.read
gzip_reader.close
return unzipped_string
end
|
#handle_errors(&block) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/frm/base.rb', line 64
def handle_errors(&block)
retries = 0
begin
yield
rescue Object => error_object
if retries < @retries
sleep(2**retries * 1) retries += 1
STDERR.puts "encountered error #{error_object.inspect}, retrying attempt #{retries}."
retry
else
logger.error "encountered error #{error_object.inspect}, aborting."
raise error_object
end
end
end
|
#run(command) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/frm/base.rb', line 19
def run(command)
output = `#{command} 2>&1`.chomp
unless $?.success?
STDERR.puts "failed to run command: #{command}"
STDERR.puts "output was: "
STDERR.puts output
raise "failed to run command: #{command}"
end
return output
end
|