Class: TerraspacePluginAzurerm::Interfaces::Helper::Secret::Fetcher

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Logging
Defined in:
lib/terraspace_plugin_azurerm/interfaces/helper/secret/fetcher.rb

Defined Under Namespace

Classes: Error, VaultNotConfiguredError, VaultNotFoundError

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(mod, options = {}) ⇒ Fetcher

Returns a new instance of Fetcher.



12
13
14
# File 'lib/terraspace_plugin_azurerm/interfaces/helper/secret/fetcher.rb', line 12

def initialize(mod, options={})
  @mod, @options = mod, options
end

Instance Method Details

#check_vault_configured!(vault) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/terraspace_plugin_azurerm/interfaces/helper/secret/fetcher.rb', line 30

def check_vault_configured!(vault)
  return if vault
  logger.error "ERROR: Vault has not been configured or vault option not passed in the azure_secret helper method.".color(:red)
  logger.error <<~EOL
    Please configure the Azure KeyVault you want to use.  Example:

    config/plugins/azurerm.rb

        TerraspacePluginAzurerm.configure do |config|
          config.secrets.vault = "REPLACE_WITH_YOUR_VAULT_NAME"
        end

    Docs: https://terraspace.cloud/docs/helpers/azure/secrets/
  EOL
  raise VaultNotConfiguredError.new
end

#fetch(name, opts = {}) ⇒ Object



16
17
18
19
# File 'lib/terraspace_plugin_azurerm/interfaces/helper/secret/fetcher.rb', line 16

def fetch(name, opts={})
  opts[:vault] ||= TerraspacePluginAzurerm.config.secrets.vault
  get_secret(name, opts)
end

#get_secret(name, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/terraspace_plugin_azurerm/interfaces/helper/secret/fetcher.rb', line 21

def get_secret(name, options={})
  vault = options[:vault]
  check_vault_configured!(vault)
  version = options[:version]
  version = "/#{version}" if version
  name = expansion(name) if expand?
  secret.show(name: name, vault: vault)
end