ServiceAccountKeyManager { public void deleteKey(String keyName) throws IOException { LOG.info("[AUDIT] Deleting service account key: {}", keyName); try { iam.projects().serviceAccounts().keys() .delete(keyName) .execute(); } catch (GoogleJsonResponseException e) { if (e.getStatusCode() == 403 || e.getStatusCode() == 404) { LOG.debug("Couldn't find key to delete {}", keyName, e); return; } LOG.warn("[AUDIT] Failed to delete key {}", keyName, e); throw e; } catch (IOException e) { LOG.warn("[AUDIT] Failed to delete key {}", keyName, e); throw e; } } ServiceAccountKeyManager(Iam iam); ServiceAccountKey createJsonKey(String serviceAccount); ServiceAccountKey createP12Key(String serviceAccount); boolean serviceAccountExists(String serviceAccount); boolean keyExists(String keyName); void tryDeleteKey(String keyName); void deleteKey(String keyName);  }
@Test(expected = GoogleJsonResponseException.class) public void deleteKeyShouldThrowUnknownExceptions() throws Exception { when(delete.execute()).thenThrow(INTERNAL_SERVER_ERROR); sakm.deleteKey("foo"); verify(iam.projects().serviceAccounts().keys()).delete("foo"); }
@Test public void deleteKeyShouldIgnorePermissionDenied() throws Exception { when(delete.execute()).thenThrow(PERMISSION_DENIED); sakm.deleteKey("foo"); verify(iam.projects().serviceAccounts().keys()).delete("foo"); }
@Test public void deleteKeyShouldIgnoreNotFound() throws Exception { when(delete.execute()).thenThrow(NOT_FOUND); sakm.deleteKey("foo"); verify(iam.projects().serviceAccounts().keys()).delete("foo"); }