From af44628def5ccefe1c25bc2e53135eacde7baae4 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 23 Jun 2022 02:01:11 +0200 Subject: [PATCH] Hide token in exception message. --- .../statoolinfos/metrics/gitea/GiteaAPI.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaAPI.java b/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaAPI.java index e97994b..7a93e82 100644 --- a/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaAPI.java +++ b/src/fr/devinsy/statoolinfos/metrics/gitea/GiteaAPI.java @@ -52,20 +52,36 @@ public class GiteaAPI */ public GiteaAPI(final String url, final String token) throws IOException, ParseException { - this.url = StringUtils.removeEnd(url, "/"); - this.token = token; + try + { + this.url = StringUtils.removeEnd(url, "/"); + this.token = token; - // - String json = IOUtils.toString(new URL(this.url + "/api/v1/admin/users?limit=100000&token=" + token), Charset.defaultCharset()); - this.users = (JSONArray) (new JSONParser().parse(json)); + // + String json = IOUtils.toString(new URL(this.url + "/api/v1/admin/users?limit=100000&token=" + token), Charset.defaultCharset()); + this.users = (JSONArray) (new JSONParser().parse(json)); - // - json = IOUtils.toString(new URL(this.url + "/api/v1/admin/orgs?limit=100000&token=" + token), Charset.defaultCharset()); - this.organizations = (JSONArray) (new JSONParser().parse(json)); + // + json = IOUtils.toString(new URL(this.url + "/api/v1/admin/orgs?limit=100000&token=" + token), Charset.defaultCharset()); + this.organizations = (JSONArray) (new JSONParser().parse(json)); - // - json = IOUtils.toString(new URL(this.url + "/api/v1/repos/search?limit=100000&token=" + token), Charset.defaultCharset()); - this.repositories = (JSONArray) ((JSONObject) (new JSONParser().parse(json))).get("data"); + // + json = IOUtils.toString(new URL(this.url + "/api/v1/repos/search?limit=100000&token=" + token), Charset.defaultCharset()); + this.repositories = (JSONArray) ((JSONObject) (new JSONParser().parse(json))).get("data"); + } + catch (IOException exception) + { + String message = exception.getMessage(); + if (message.matches(".*token=\\w+.*")) + { + message = message.replaceAll("token=\\w+", "token=*******"); + throw new IOException(message); + } + else + { + throw exception; + } + } } /**