Class: Sambot::Testing::VaultHelper
- Inherits:
-
Object
- Object
- Sambot::Testing::VaultHelper
- 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
- .generate_wrapped_token ⇒ Object
- .load_secrets(config, src = 'local_testing') ⇒ Object
- .setup ⇒ Object
Class Method Details
.generate_wrapped_token ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sambot/testing/vault_helper.rb', line 17 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 wrap_info = Vault.auth_token.create('wrap_ttl': '72h', role: 'nightswatch-ro', policies: ['nightswatch-ro']).wrap_info token = wrap_info.token rescue end token end |
.load_secrets(config, src = 'local_testing') ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/sambot/testing/vault_helper.rb', line 48 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 |
.setup ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sambot/testing/vault_helper.rb', line 32 def setup FileUtils.rm_r(WORKING_DIR) if Dir.exist?(WORKING_DIR) FileUtils.mkpath WORKING_DIR UI.info("Created #{WORKING_DIR}") Dir.chdir WORKING_DIR do UI.info('Cloning the Vault policies for inclusion into the Vault Docker instance') `git clone --depth=1 --single-branch -q #{VAULT_POLICIES_REPO}` Dir.chdir 'vault-policies/dev/vault-config' do FS.copy(VAULT_CONFIG_BINARY) UI.info('Applying the Vault policies') `VC_VAULT_ADDR=http://127.0.0.1:8200 VC_VAULT_TOKEN=root ./#{VAULT_CONFIG_BINARY} config` UI.info('The Vault policies have been applied') end end end |