Skip to content

Commit

Permalink
Gracefully handle missing user id
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwbarnett committed Nov 5, 2021
1 parent 1f39762 commit 5e5240c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/chef/knife/ec_key_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ def insert_key_data_for_user(d)
end
ui.msg "Updating key data for user[#{d['name']}]"
new_id = if config[:skip_ids]
db[:users].where(:username => d['name']).first[:id]
db[:users].where(:username => d['name']).first&.[](:id)
else
d['id']
end

if new_id.nil?
Chef::Log.debug("Unable to find user id for #{d['name']}")
return
end

Chef::Log.debug("Found user id for #{d['name']}: #{new_id}")
upsert_key_record(key_record_for_db(d, new_id))
end
Expand Down

0 comments on commit 5e5240c

Please sign in to comment.