Class: AnalyticsOps::Configuration::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/analytics_ops/configuration/loader.rb

Overview

Bounded safe-YAML reader with allowlisted environment interpolation.

Constant Summary collapse

MAX_BYTES =
1_048_576
MAX_NESTING =
50
VARIABLE =
/\$\{([A-Z][A-Z0-9_]*)\}/

Instance Method Summary collapse

Constructor Details

#initialize(environment: ENV) ⇒ Loader

Returns a new instance of Loader.



15
16
17
# File 'lib/analytics_ops/configuration/loader.rb', line 15

def initialize(environment: ENV)
  @environment = environment
end

Instance Method Details

#load(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/analytics_ops/configuration/loader.rb', line 19

def load(path)
  source = read(path)
  raise ConfigurationError, "ERB is not allowed in Analytics Ops configuration" if source.include?("<%")

  reject_duplicate_mapping_keys!(source)

  parsed = Psych.safe_load(
    source,
    permitted_classes: [],
    permitted_symbols: [],
    aliases: false,
    filename: path.to_s,
    fallback: {}
  )

  Validator.new(interpolate(parsed)).call
rescue Psych::Exception => error
  raise ConfigurationError,
        "Invalid YAML in #{Redaction.message(path)}: #{Redaction.message(error.message)}"
end