As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 4de0ee3b authored by Jacob Vosmaer's avatar Jacob Vosmaer
Browse files

Use Tempfile instead of `sed -i`

The syntax for `sed -i` is incompatible between GNU sed and
BSD sed. By Tempfile from the Ruby standard library we can
avoid using the `-i` option of sed.
parent c4c0885a
No related branches found
No related tags found
No related merge requests found
require 'tempfile'
require_relative 'gitlab_config'
require_relative 'gitlab_logger'
Loading
Loading
@@ -35,8 +36,10 @@ class GitlabKeys
def rm_key
$logger.info "Removing key #{@key_id}"
cmd = "sed -i '/shell #{@key_id}\"/d' #{auth_file}"
system(cmd)
Tempfile.open('authorized_keys') do |temp|
cmd = "sed '/shell #{@key_id}\"/d' #{auth_file} > #{temp.path} && mv #{temp.path} #{auth_file}"
system(cmd)
end
end
def clear
Loading
Loading
Loading
Loading
@@ -31,9 +31,12 @@ describe GitlabKeys do
describe :rm_key do
let(:gitlab_keys) { build_gitlab_keys('rm-key', 'key-741', 'ssh-rsa AAAAB3NzaDAxx2E') }
let(:temp_file) { mock(:temp_file, path: 'tmp_path') }
before { Tempfile.should_receive(:open).and_yield(temp_file) }
it "should receive valid cmd" do
valid_cmd = "sed -i '/shell key-741\"/d' #{GitlabConfig.new.auth_file}"
auth_file = GitlabConfig.new.auth_file
valid_cmd = "sed '/shell key-741\"/d' #{auth_file} > tmp_path && mv tmp_path #{auth_file}"
gitlab_keys.should_receive(:system).with(valid_cmd)
gitlab_keys.send :rm_key
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment