Skip to content

Commit

Permalink
wf: set DIGDAG_CONFIG_HOME env var
Browse files Browse the repository at this point in the history
This is to give the digdag cli a directory that it can use to store e.g.
local secrets.
  • Loading branch information
Daniel Norberg committed Nov 14, 2016
1 parent c0d5dc4 commit bfd2ec8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
34 changes: 24 additions & 10 deletions lib/td/command/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def workflow(op, capture_output=false, check_prereqs=true)
cmd << '-Dio.digdag.standards.td.client-configurator.enabled=true'
end

# Provide the digdag cli with a directory that can be used to e.g. store local secrets
FileUtils.mkdir_p digdag_config_dir
env['DIGDAG_CONFIG_HOME'] = digdag_config_dir

cmd << '-jar' << digdag_cli_path
unless op.argv.empty?
cmd << '--config' << digdag_config_path
Expand All @@ -53,16 +57,7 @@ def workflow(op, capture_output=false, check_prereqs=true)
$stderr.puts cmd.to_s
end

if capture_output
# TODO: use popen3 instead?
stdout_str, stderr_str, status = Open3.capture3(env, *cmd)
$stdout.write(stdout_str)
$stderr.write(stderr_str)
return status.exitstatus
else
Kernel::system(env, *cmd)
return $?.exitstatus
end
execute(capture_output, env, cmd)
}
end

Expand Down Expand Up @@ -96,6 +91,20 @@ def workflow_version(op)
workflow(version_op, capture_output=true, check_prereqs=false)
end

private
def execute(capture_output, env, cmd)
if capture_output
# TODO: use popen3 instead?
stdout_str, stderr_str, status = Open3.capture3(env, *cmd)
$stdout.write(stdout_str)
$stderr.write(stderr_str)
return status.exitstatus
else
Kernel::system(env, *cmd)
return $?.exitstatus
end
end

private
def system_java_cmd
if td_wf_java.nil? or td_wf_java.empty?
Expand Down Expand Up @@ -139,6 +148,11 @@ def digdag_dir
File.join(home_directory, '.td', 'digdag')
end

private
def digdag_config_dir
File.join(home_directory, '.td', 'digdag', 'config')
end

private
def digdag_tmp_dir
File.join(home_directory, '.td', 'digdag', 'tmp')
Expand Down
8 changes: 8 additions & 0 deletions spec/td/command/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ def with_env(name, var)
}
end

it 'provides a config directory' do
allow(TreasureData::Config).to receive(:cl_apikey) { true }
expect(command).to receive(:execute).with(true, hash_including('DIGDAG_CONFIG_HOME'), anything()) { |_, env, _|
expect(File.directory?(env['DIGDAG_CONFIG_HOME'])).to be true
}
command.workflow(init_option, capture_output=true, check_prereqs=false)
end

it 'complains if there is no apikey' do
allow(TreasureData::Config).to receive(:apikey) { nil}
expect{command.workflow(version_option)}.to raise_error(TreasureData::ConfigError)
Expand Down

0 comments on commit bfd2ec8

Please sign in to comment.