Class: CodexNotify::ConfigMigrator

Inherits:
Object
  • Object
show all
Defined in:
lib/codex_notify/config_migrator.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

PROFILE_KEYS =
{
  'SLACK_BOT_TOKEN__' => 'token',
  'SLACK_CHANNEL__' => 'channel'
}.freeze
ENV_POLICIES =
%w[legacy restricted].freeze

Instance Method Summary collapse

Constructor Details

#initialize(legacy_checkout_root: nil, environment: ENV, stdout: $stdout, stderr: $stderr) ⇒ ConfigMigrator

Returns a new instance of ConfigMigrator.



22
23
24
25
26
27
# File 'lib/codex_notify/config_migrator.rb', line 22

def initialize(legacy_checkout_root: nil, environment: ENV, stdout: $stdout, stderr: $stderr)
  @legacy_checkout_root = Pathname(legacy_checkout_root).expand_path if legacy_checkout_root
  @environment = environment
  @stdout = stdout
  @stderr = stderr
end

Instance Method Details

#run(env_path: nil, config_path: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/codex_notify/config_migrator.rb', line 29

def run(env_path: nil, config_path: nil)
  source = source_path(env_path)
  target = target_path(config_path)
  validate_paths(source, target)

  ConfigDiagnostics.warn_if_env_file_insecure(source, stderr: @stderr)
  values = Dotenv.parse(source.to_s)
  document = build_document(values)
  write_config(target, YAML.dump(document))
  @stdout.puts("Created trusted config file #{target}.")
  @stdout.puts('Verify the destination settings, then remove migrated secrets from the legacy env file manually.')
  0
rescue TrustedConfigLoader::Error => e
  raise Error, e.message
rescue SystemCallError => e
  raise Error, "could not migrate configuration: #{e.class}"
end