Class: Sambot::Testing::VaultHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/sambot/testing/vault_helper.rb

Constant Summary collapse

VAULT_CONFIG_BINARY =
'vault-config'
WORKING_DIR =
'/tmp/sambot/testing/vault'
VAULT_POLICIES_REPO =
'[email protected]:ads-devops/vault-policies.git'

Class Method Summary collapse

Class Method Details

.generate_wrapped_tokenObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sambot/testing/vault_helper.rb', line 15

def generate_wrapped_token
  ::Vault.configure do |config|
    config.address = 'http://127.0.0.1:8200'
    config.token = 'root'
    config.ssl_verify = false
  end
  token = ''
  begin
    token = Vault.auth_token.create(wrap_ttl: "72h", role: 'nightswatch-ro', policy: 'nightswatch-ro').wrap_info.token
  rescue
  end
  token
end

.load_secrets(config, src = 'local_testing') ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/sambot/testing/vault_helper.rb', line 41

def load_secrets(config, src = 'local_testing')
  UI.info("Reading secrets from the configuration file")
  if config.secrets.nil? || config.secrets.empty?
    UI.info("No secrets were found in the secrets configuration file")
    return 0
  else
    store_secrets(config.secrets, src)
  end
end

.setupObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sambot/testing/vault_helper.rb', line 29

def setup
  FileUtils.rm_r(WORKING_DIR) if Dir.exist?(WORKING_DIR)
  FileUtils.mkpath WORKING_DIR
  Dir.chdir WORKING_DIR do
    `git clone --depth=1 --single-branch -q #{VAULT_POLICIES_REPO}`
    Dir.chdir 'vault-policies/dev/vault-config' do
      FS.copy(VAULT_CONFIG_BINARY)
      `./#{VAULT_CONFIG_BINARY} config`
    end
  end
end