sambot 0.1.111 → 0.1.112

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04cf2aa5575db3b8d682df8834ee8219bfbf7ebf
4
- data.tar.gz: e664f1bfdb6988720af8966aa6bf9af92277502d
3
+ metadata.gz: 0de72fb94d33394f6a22bc622e7bb25bc006fad5
4
+ data.tar.gz: 2b9c9c892cf49945ef7fe560c4b018df0a59ff45
5
5
  SHA512:
6
- metadata.gz: 71f8344676808ea81f690b06891fb80820de093e37635b937613b8102e2f6b236d4f97b28d89d10ce5af5d6433340fd4a51d808d1c94e806cf97136f00244142
7
- data.tar.gz: a4a9d08a9e08102507cddc15f060a2cb398752067481dbc823e53fc023703a39966235a1b50dab517984e900e5c49c36d5f6edd585a2a3296595f702e5df8082
6
+ metadata.gz: 6752fc68229ee431c8c4d831d61ba300a2b35736f6c376457b344eb99c7f02b19fb8de1e7cc1d114c940148c77c0b212e3f0782077c2bd3e234e7f608cdea156
7
+ data.tar.gz: 745daed4cc978fe0c7eccf6c6623f7d8a1357965534efefa4d6d8dd09abab5e5fd92a5bd56a6e354e3d98deba0ab29e664ea2d58b0b052b7415e688218bbac15
@@ -4,6 +4,8 @@ module Sambot
4
4
  module DeveloperWorkflow
5
5
  class Proxy
6
6
 
7
+ CONFIG_PATH = '/tmp/haproxy.conf'
8
+
7
9
  def self.start(forwards)
8
10
  template_path = FileManagement::TemplateProvider.get_path('haproxy.conf.erb')
9
11
  input = File.read(template_path)
@@ -20,13 +22,12 @@ module Sambot
20
22
  UI.debug("Proxying #{service[:name]}.brighter.io:#{service[:local_port]} to #{service[:ip]}:#{service[:tunnel_port]}")
21
23
  end
22
24
  contents = eruby.evaluate({services: services})
23
- temp_config = Tempfile.new
24
- File.write(temp_config.path, contents)
25
- Runtime.sudo("haproxy -f #{temp_config.path}")
25
+ File.write(CONFIG_PATH, contents)
26
+ Runtime.sudo("haproxy -f #{CONFIG_PATH}")
26
27
  end
27
28
 
28
29
  def self.stop
29
-
30
+ Runtime.sudo("killall haproxy")
30
31
  end
31
32
 
32
33
  end
@@ -23,7 +23,7 @@ module Sambot
23
23
  'teamcity.brighter.io': { ip: '127.0.0.14', port: 443, local_port: 9014 },
24
24
  'splunk.brighter.io': { ip: '127.0.0.15', port: 443, local_port: 9015 },
25
25
  'jenkins.brighter.io': { ip: '127.0.0.16', port: 443, local_port: 9016 },
26
- 'vault.brighter.io': { ip: '127.0.0.17', port: 8200, local_port: 9017 }
26
+ 'vault.brighter.io': { ip: '127.0.0.1', port: 8200, local_port: 9017 }
27
27
  }
28
28
 
29
29
  def start(username, password, sudo_password)
@@ -36,13 +36,14 @@ module Sambot
36
36
  Proxy.start(FORWARDS)
37
37
  Networking.configure(FORWARDS)
38
38
  Tunnels.start(username, password, BASTION_HOST_IP, FORWARDS)
39
- #setup_secrets_management(username, password)
39
+ setup_secrets_management(username, password)
40
40
  UI.info("Your session has now started - run `sambot session stop` to close it")
41
41
  end
42
42
 
43
43
  def stop
44
44
  Tunnels.stop
45
45
  DNS.reset_hosts(FORWARDS)
46
+ Proxy.stop
46
47
  end
47
48
 
48
49
  private
@@ -65,11 +66,11 @@ module Sambot
65
66
  end
66
67
 
67
68
  def setup_secrets_management(username, password)
68
- unless Vault.has_environment_variables?('/etc/profile.d/')
69
+ unless Vault.has_environment_variables?
69
70
  UI.info("You have either not configured your workstation or you have not opened up a new shell to pick up the changes applied during configuration")
70
71
  end
71
72
  UI.debug "Authenticating with Hashicorp Vault in Rackspace DEV/QE"
72
- token = Vault.authenticate(username, password)
73
+ token = Vault.authenticate(username, password, FORWARDS)
73
74
  UI.debug "Saving your Vault authentication token to ~/.vault-token"
74
75
  Vault.save_token(token)
75
76
  end
@@ -7,34 +7,46 @@ module Sambot
7
7
  module DeveloperWorkflow
8
8
  class Vault
9
9
 
10
- TARGET = "https://vault.brighter.io:8200"
10
+ def self.authenticate(username, password, forwards)
11
+ secret = get_user_token(username, password, forwards)
12
+ secret.auth.client_token
13
+ end
11
14
 
12
- def self.authenticate(username, password)
13
- secret = nil
15
+ def self.get_user_token(username, password, forwards)
14
16
  ::Vault.configure do |config|
15
17
  sleep(3)
16
- config.address = TARGET
18
+ config.address = build_vault_address(forwards)
17
19
  config.ssl_verify = false
18
- secret = ::Vault.auth.ldap(username, password)
20
+ return ::Vault.auth.ldap(username, password)
19
21
  end
20
- secret.auth.client_token
21
22
  end
22
23
 
23
- def self.setup_environment(root = '/etc/profile.d/')
24
- save_environment_variable('VAULT_SKIP_VERIFY', true)
25
- save_environment_variable('VAULT_ADDR', TARGET)
24
+ def self.setup_environment(forwards, target = '~/.bash_profile')
25
+ save_environment_variable('VAULT_SKIP_VERIFY', true, target)
26
+ save_environment_variable('VAULT_ADDR', build_vault_address(forwards), target)
26
27
  end
27
28
 
28
- def self.save_environment_variable(key, value, path = '/etc/profile.d/')
29
- path = File.join(path, "#{key}.sh")
30
- file = Tempfile.new('foo')
31
- file.write("export #{key}=#{value}")
32
- Runtime.sudo("cp #{file.path} #{path}")
29
+ def self.build_vault_address(forwards)
30
+ "https://vault.brighter.io:#{forwards[:'vault.brighter.io'][:local_port]}"
31
+ end
32
+
33
+ def self.save_environment_variable(key, value, target = '~/.bash_profile')
34
+ contents = File.read(target)
35
+ contents = contents.gsub(/export #{key}=#{value}/, '') if has_environment_variable?(key, value, target)
36
+ contents << "export #{key}=#{value.to_s}\n"
37
+ File.write(target, contents)
33
38
  ENV[key] = value.to_s
34
39
  end
35
40
 
36
- def self.has_environment_variables?(path)
37
- File.exist?(File.join(path, "VAULT_SKIP_VERIFY.sh")) && File.exist?(File.join(path, "VAULT_ADDR.sh"))
41
+ def self.has_environment_variables?(forwards, target = '~/.bash_profile')
42
+ has_vault_skip_verify = has_environment_variable?('VAULT_SKIP_VERIFY', true, target)
43
+ has_vault_addr = has_environment_variable?('VAULT_ADDR', build_vault_address(forwards), target)
44
+ (has_vault_addr != nil) && (has_vault_skip_verify != nil)
45
+ end
46
+
47
+ def self.has_environment_variable?(key, value, target = '~/.bash_profile')
48
+ contents = File.read(target)
49
+ contents.match(/export #{key}=#{value}/)
38
50
  end
39
51
 
40
52
  def self.save_token(token, home_directory = '~')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sambot
4
- VERSION = '0.1.111'.freeze
4
+ VERSION = '0.1.112'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sambot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.111
4
+ version: 0.1.112
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Kouame