Class: Nvoi::Utils::EnvResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/nvoi/utils/env_resolver.rb

Overview

EnvResolver handles environment variable resolution and injection

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ EnvResolver

Returns a new instance of EnvResolver.



7
8
9
# File 'lib/nvoi/utils/env_resolver.rb', line 7

def initialize(config)
  @config = config
end

Instance Method Details

#env_for_service(service_name) ⇒ Object

Returns environment variables for a specific service



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nvoi/utils/env_resolver.rb', line 12

def env_for_service(service_name)
  env = {
    "DEPLOY_ENV" => @config.deploy.application.environment
  }

  # Database env injection
  inject_database_env(env)

  # Global env vars
  @config.deploy.application.env&.each do |k, v|
    env[k] = v
  end

  # Global secrets
  @config.deploy.application.secrets&.each do |k, v|
    env[k] = v
  end

  # Service-specific env
  service = @config.deploy.application.app[service_name]
  if service
    service.env&.each do |k, v|
      env[k] = v
    end
  end

  env
end