Module: Daytona::EnvFile

Defined in:
lib/daytona/config.rb

Overview

Dotenv runs $(...) in a value through the shell while parsing, and the working directory is frequently a cloned repository, so parsing .env there would execute whatever its author put in it.

Defined Under Namespace

Classes: Parser

Class Method Summary collapse

Class Method Details

.parse(path) ⇒ Object

Read with the mode dotenv itself uses, so the accepted format does not narrow: bom skips a byte-order mark an editor on Windows may have written, and pinning utf-8 keeps the file readable under a POSIX locale, where the default external encoding would make one accented byte anywhere — a comment included — raise while it is scanned.



26
27
28
29
# File 'lib/daytona/config.rb', line 26

def self.parse(path)
  verify_suppression!
  Parser.call(File.read(path, mode: 'rb:bom|utf-8'))
end

.verify_suppression!Object

The subclass reaches into dotenv's internals rather than a public API, and dotenv has already reorganised them once inside the range the gemspec allows, so confirm the suppression actually holds in the process that relies on it rather than trusting the version pinned in CI. Checked here rather than on load: this is the operation the guard protects, so a lapse stops it, and a gem that never reads a .env still loads. A failure is not memoised, so it is raised again on the next attempt.



37
38
39
40
41
42
43
44
45
# File 'lib/daytona/config.rb', line 37

def self.verify_suppression!
  return if @verified

  probe = Parser.call('DAYTONA_PROBE=$(echo substituted)')['DAYTONA_PROBE']
  raise "dotenv command substitution is not suppressed (got #{probe.inspect})" unless
    probe == '$(echo substituted)'

  @verified = true
end