Commit 01275f09 authored by DJ Mountney's avatar DJ Mountney

Add some messaging when the encrypted contents don't change

And update the spec tests for the latest changes
parent 812b7e11
...@@ -22,23 +22,26 @@ module Gitlab ...@@ -22,23 +22,26 @@ module Gitlab
encrypted = Gitlab::Auth::Ldap::Config.encrypted_secrets encrypted = Gitlab::Auth::Ldap::Config.encrypted_secrets
return unless validate_config(encrypted) return unless validate_config(encrypted)
if ENV["EDITOR"].to_s.empty? if ENV["EDITOR"].blank?
puts 'No $EDITOR specified to open file. Please provide one when running the command:' puts 'No $EDITOR specified to open file. Please provide one when running the command:'
puts 'gitlab-rake gitlab:ldap:secret:edit EDITOR=vim' puts 'gitlab-rake gitlab:ldap:secret:edit EDITOR=vim'
return return
end end
temp_file = Tempfile.new(File.basename(encrypted.content_path), File.dirname(encrypted.content_path)) temp_file = Tempfile.new(File.basename(encrypted.content_path), File.dirname(encrypted.content_path))
contents_changed = false
encrypted.change do |contents| encrypted.change do |contents|
contents = encrypted_file_template unless File.exist?(encrypted.content_path) contents = encrypted_file_template unless File.exist?(encrypted.content_path)
File.write(temp_file.path, contents) File.write(temp_file.path, contents)
system(ENV['EDITOR'], temp_file.path) system(ENV['EDITOR'], temp_file.path)
changes = File.read(temp_file.path) changes = File.read(temp_file.path)
contents_changed = contents != changes
validate_contents(changes) validate_contents(changes)
changes changes
end end
puts "Contents were unchanged." unless contents_changed
puts "File encrypted and saved." puts "File encrypted and saved."
rescue Interrupt rescue Interrupt
puts "Aborted changing file: nothing saved." puts "Aborted changing file: nothing saved."
......
...@@ -32,7 +32,7 @@ RSpec.describe 'gitlab:ldap:secret rake tasks' do ...@@ -32,7 +32,7 @@ RSpec.describe 'gitlab:ldap:secret rake tasks' do
describe ':show' do describe ':show' do
it 'displays error when file does not exist' do it 'displays error when file does not exist' do
expect { run_rake_task('gitlab:ldap:secret:show') }.to output(/File .* does not exist. Use `rake gitlab:ldap:secret:edit` to change that./).to_stdout expect { run_rake_task('gitlab:ldap:secret:show') }.to output(/File .* does not exist. Use `gitlab-rake gitlab:ldap:secret:edit` to change that./).to_stdout
end end
it 'displays error when key does not exist' do it 'displays error when key does not exist' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment