socotra-build 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/socotra-build.rb +82 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 2ac75a353775383f8d6b53507060c24c69391e83
|
|
4
|
+
data.tar.gz: 1f01ee8ac98cb82d17f868ff2bbf0bca359b7d37
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6fd5ca577efe09382a0f3b6283aa660c39755654c8df2f48b29d28c8a948bba5aa93454b0b26e0e0fbe50c2f1bdf0e13638647d137d3b4cec6799bad815d3671
|
|
7
|
+
data.tar.gz: 77a1b811efb47d0e5be4982341a717e4276db858637be688ff8528b952d21429cd9adb20f2b75102c82afe74c1d34b1851e6e970c01c102ec8696d1d6bef2222
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'open3'
|
|
2
|
+
|
|
3
|
+
def self.safe_retry(cmd, description, error_message="command failed", raise_on_fail=true, tries=3)
|
|
4
|
+
begin
|
|
5
|
+
status, output = system_safe(cmd, description, error_message, raise_on_fail=raise_on_fail, log_level="WARNING")
|
|
6
|
+
rescue
|
|
7
|
+
if (tries -= 1) > 0
|
|
8
|
+
puts "\n#{cmd} failed, retry attempt #{tries}\n"
|
|
9
|
+
sleep 5
|
|
10
|
+
retry unless (tries).zero?
|
|
11
|
+
else
|
|
12
|
+
puts "ERROR: see logs/#{description}_out.log and #{description}_err.log for details"
|
|
13
|
+
if raise_on_fail
|
|
14
|
+
raise "ERROR: #{error_message}"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
return status
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.system_safe(cmd, cmd_description, error_message, raise_on_fail=true, log_level="ERROR")
|
|
23
|
+
puts "executing command: #{cmd}\n"
|
|
24
|
+
start = Time.now.to_i
|
|
25
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
|
26
|
+
elapsed = Time.now.to_i - start
|
|
27
|
+
|
|
28
|
+
File.open("logs/#{cmd_description}_out.log" , 'w') { |file| file.write(stdout) }
|
|
29
|
+
File.open("logs/#{cmd_description}_err.log" , 'w') { |file| file.write(stderr) }
|
|
30
|
+
|
|
31
|
+
puts "\t#{cmd_description} took #{elapsed} seconds"
|
|
32
|
+
puts "\tLogs available here: #{cmd_description}_err.log and #{cmd_description}_out.log\n\n"
|
|
33
|
+
|
|
34
|
+
if not status.success? and raise_on_fail
|
|
35
|
+
puts "#{log_level}: see logs/#{cmd_description}_out.log and #{cmd_description}_err.log for details"
|
|
36
|
+
raise "#{log_level}: #{error_message}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
return [status.success?, stdout]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.system_unsafe(cmd)
|
|
43
|
+
success = system(cmd)
|
|
44
|
+
return success
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.get_secret(key, subkey, log_identifier)
|
|
48
|
+
cmd = "vault read -field=#{subkey} #{key}"
|
|
49
|
+
status, secret = system_safe(cmd, log_identifier, "Get secret failed")
|
|
50
|
+
secret = secret.strip
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.put_secret(key, subkey_value_map, log_identifier)
|
|
54
|
+
cmd = "vault write #{key} #{subkey_value_map}"
|
|
55
|
+
system_safe(cmd, log_identifier, "Put secret failed")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.generate_aws_keys(key, log_identifier)
|
|
59
|
+
cmd = "vault read #{key}"
|
|
60
|
+
|
|
61
|
+
status, output = system_safe(cmd, log_identifier, "AWS key generation failed")
|
|
62
|
+
|
|
63
|
+
cmd = "echo '#{output}' |grep access_key|awk '{print $2'}"
|
|
64
|
+
status, account_access_key = system_safe(cmd, "get_generated_access_key", "Getting account access key failed")
|
|
65
|
+
|
|
66
|
+
account_access_key = account_access_key.strip
|
|
67
|
+
|
|
68
|
+
cmd = "echo '#{output}' |grep secret_key|awk '{print $2'}"
|
|
69
|
+
status, account_secret_key = system_safe(cmd, "get_generated_access_key", "Getting account access key failed")
|
|
70
|
+
account_secret_key = account_secret_key.strip
|
|
71
|
+
|
|
72
|
+
cmd = "echo '#{output}' |grep lease_id|awk '{print $2'}"
|
|
73
|
+
status, lease_id = system_safe(cmd, "get_generated_access_key", "Getting account access key failed")
|
|
74
|
+
lease_id = lease_id.strip
|
|
75
|
+
|
|
76
|
+
return account_access_key, account_secret_key, lease_id
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.revoke_lease(lease_id, log_identifier)
|
|
80
|
+
cmd = "vault revoke #{lease_id}"
|
|
81
|
+
system_safe(cmd, log_identifier, "Revoking lease failed")
|
|
82
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: socotra-build
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chris Antenesse
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-06-21 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Common functions for build
|
|
14
|
+
email: chris.antenesse@socotra.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/socotra-build.rb
|
|
20
|
+
homepage: http://rubygems.org/gems/socotra
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubyforge_project:
|
|
40
|
+
rubygems_version: 2.5.2
|
|
41
|
+
signing_key:
|
|
42
|
+
specification_version: 4
|
|
43
|
+
summary: Build library
|
|
44
|
+
test_files: []
|
|
45
|
+
has_rdoc:
|