FIX: Update api_key rake task for recent changes

FIX: Update api_key rake task for recent changes

New usage:

rake api_key:get_or_create_master["Onboarding Key"]
diff --git a/lib/tasks/api.rake b/lib/tasks/api.rake
index 8bff7dd5a2..bf8c37ecd3 100644
--- a/lib/tasks/api.rake
+++ b/lib/tasks/api.rake
@@ -1,8 +1,9 @@
 # frozen_string_literal: true
 
-desc "generate api key if missing, return existing if already there"
-task "api_key:get" => :environment do
-  api_key = ApiKey.create_master_key
+desc "find or generate a master api key with given description"
+task "api_key:get_or_create_master", [:description] => :environment do |task, args|
+  raise "Supply a description for the key" if !args[:description]
+  api_key = ApiKey.find_or_create_by!(description: args[:description], revoked_at: nil, user_id: nil)
 
-    puts api_key.key
+  puts api_key.key
 end

GitHub sha: 63bd0749

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: