1 var REST = library.REST.REST();
  2 
  3 function getKey(theKeyName) {
  4   theKeyName = !theKeyName ? "REST Api Key" : theKeyName;
  5   apiKeyManager.deleteApiKey(context.getParameter("key"));
  6   return apiKeyManager.getOrCreateApiKey(
  7     theKeyName,
  8     context.getUser().username
  9   );
 10 }
 11 
 12 /**
 13  * @name deleteApiKey
 14  * @class delete an Api Key.  Can delete any api key if global admin, only owned keys for other users
 15  * @description  This endpoint deletes an api key, restricted by permissions
 16  * @param [key] The key to remove
 17  * @returns {"success": true}
 18  *
 19  * @example /wf/restapi/v2/deleteApiKey?key=9F04CB70-B947-4DF2-BE7E-1D73E91DA2C2
 20  *
 21  * Parameters:
 22  *
 23  Response:
 24  {"success": true}
 25  */
 26 (function main() {
 27   var aKey = context.getParameter("key");
 28   if (aKey == null || aKey == "") {
 29     REST.pushError(REST.errors.e400, "missing key param");
 30     return REST.execute();
 31   } else if (
 32     !context.getUser().isGlobalAdmin() &&
 33     !apiKeyManager.isKeyOwner(aKey, context.getUser().username)
 34   ) {
 35     REST.pushError(
 36       REST.errors.e403,
 37       "Cannot delete API that is not owned by user (or are not a global admin)"
 38     );
 39     return REST.execute();
 40   }
 41   return REST.formatResponse({
 42     success: apiKeyManager.deleteApiKey(aKey),
 43   });
 44 })();
 45