This is an automated email from the ASF dual-hosted git repository. dpavlov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
commit 9d819fe4c3865e475fc4a92c4ee0c673f5bda94e Author: Dmitriy Pavlov <[email protected]> AuthorDate: Wed Sep 12 18:37:28 2018 +0300 IGNITE-9377 Set up pwd, minor changes, 404 failure handling --- .../java/org/apache/ignite/ci/HelperConfig.java | 4 +++ .../org/apache/ignite/ci/conf/PasswordEncoder.java | 13 +++++++--- .../java/org/apache/ignite/ci/util/HttpUtil.java | 29 +++++++++++++--------- ignite-tc-helper-web/src/main/webapp/index.html | 2 +- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java index 37880c1..14660e7 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java @@ -181,6 +181,10 @@ public class HelperConfig { if (!filled) return null; + return userPwdToToken(user, pwd); + } + + @NotNull public static String userPwdToToken(String user, String pwd) { return Base64Util.encodeUtf8String(user + ":" + pwd); } diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/PasswordEncoder.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/PasswordEncoder.java index 65fcb63..0e489f1 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/PasswordEncoder.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/PasswordEncoder.java @@ -89,12 +89,19 @@ public class PasswordEncoder { return parseHexBinary(Strings.padStart(Integer.toHexString(length), 2, '0')); } - public static void main(String[] args) { + public static void main1(String[] args) { String pass = "mmm"; String encode = encode(pass); - System.err.println("Encoded: " + - HelperConfig.ENCODED_PASSWORD + "=" + encode); + System.err.println("Encoded: " + HelperConfig.ENCODED_PASSWORD + "=" + encode); String decode = decode(encode); Preconditions.checkState(decode.equals(pass)); } + + public static void main(String[] args) { + String tok = HelperConfig.userPwdToToken("ignitetcbot", "mmm"); + String encode = encode(tok); + System.err.println("Encoded: " + HelperConfig.JIRA_AUTH_TOKEN + "=" + encode); + String decode = decode(encode); + Preconditions.checkState(decode.equals(tok)); + } } diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java index 45f249b..1184869 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java @@ -40,35 +40,36 @@ import org.slf4j.LoggerFactory; * Methods for sending HTTP requests */ public class HttpUtil { + /** Logger. */ private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class); private static String readIsToString(InputStream inputStream) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(inputStream)); String inputLine; - StringBuilder response = new StringBuilder(); + StringBuilder res = new StringBuilder(); while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - response.append("\n"); + res.append(inputLine); + res.append("\n"); } - return response.toString(); + return res.toString(); } /** * Send GET request to the TeamCity url. * - * @param basicAuthToken Authorization token. + * @param basicAuthTok Authorization token. * @param url URL. * @return Input stream from connection. * @throws IOException If failed. */ - public static InputStream sendGetWithBasicAuth(String basicAuthToken, String url) throws IOException { + public static InputStream sendGetWithBasicAuth(String basicAuthTok, String url) throws IOException { final Stopwatch started = Stopwatch.createStarted(); URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection)obj.openConnection(); - con.setRequestProperty("Authorization", "Basic " + basicAuthToken); + con.setRequestProperty("Authorization", "Basic " + basicAuthTok); con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Keep-Alive", "header"); con.setRequestProperty("accept-charset", StandardCharsets.UTF_8.toString()); @@ -109,8 +110,8 @@ public class HttpUtil { } } - public static String sendPostAsString(String basicAuthToken, String url, String body) throws IOException { - try (InputStream inputStream = sendPostWithBasicAuth(basicAuthToken, url, body)){ + public static String sendPostAsString(String basicAuthTok, String url, String body) throws IOException { + try (InputStream inputStream = sendPostWithBasicAuth(basicAuthTok, url, body)){ return readIsToString(inputStream); } } @@ -156,6 +157,10 @@ public class HttpUtil { if (resCode == 401) throw new ServiceUnauthorizedException("Service " + con.getURL() + " returned forbidden error."); + if (resCode == 404) + throw new FileNotFoundException("Service " + con.getURL() + " returned not found error." + + readIsToString(con.getErrorStream())); + throw new IllegalStateException("Invalid Response Code : " + resCode + ":\n" + readIsToString(con.getErrorStream())); } @@ -163,19 +168,19 @@ public class HttpUtil { /** * Send POST request to the GitHub url. * - * @param githubAuthToken Authorization token. + * @param githubAuthTok Authorization token. * @param url URL. * @param body Request POST params. * @return Response body from given url. * @throws IOException If failed. */ - public static String sendPostAsStringToGit(String githubAuthToken, String url, String body) throws IOException { + public static String sendPostAsStringToGit(String githubAuthTok, String url, String body) throws IOException { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection)obj.openConnection(); Charset charset = StandardCharsets.UTF_8; con.setRequestProperty("accept-charset", charset.toString()); - con.setRequestProperty("Authorization", "token " + githubAuthToken); + con.setRequestProperty("Authorization", "token " + githubAuthTok); con.setRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Keep-Alive", "header"); con.setRequestProperty("content-type", "application/json"); diff --git a/ignite-tc-helper-web/src/main/webapp/index.html b/ignite-tc-helper-web/src/main/webapp/index.html index 481706e..4a7c77d 100644 --- a/ignite-tc-helper-web/src/main/webapp/index.html +++ b/ignite-tc-helper-web/src/main/webapp/index.html @@ -123,7 +123,7 @@ function showRunAllForm(result) { res+="Server: <input type='text' name='serverId' value=" + serverId +" readonly>" ; res+="Pull Request #<input type='text' name='prId' onkeypress='return trigBuild(event)'> "; - res+="<button onclick='trigBuild()'>Run All</button>"; + res+="<button onclick='trigBuild()'>Run All</button><br>"; } $("#runAll").html(res);
