Beispiel #1
0
 public Sender(
     String url, String secret, CommandEnvironment env, ExecutorService executorService)
     throws SenderException {
   this.reporter = env.getReporter();
   this.secret = readSecret(secret, reporter);
   try {
     this.url = new URL(url);
     if (!this.secret.isEmpty()) {
       if (!(this.url.getProtocol().equals("https")
           || this.url.getHost().equals("localhost")
           || this.url.getHost().matches("^127.0.0.[0-9]+$"))) {
         reporter.handle(
             Event.warn(
                 "Using authentication over unsecure channel, " + "consider using HTTPS."));
       }
     }
   } catch (MalformedURLException e) {
     throw new SenderException("Invalid server url " + url, e);
   }
   this.buildId = env.getCommandId().toString();
   this.executorService = executorService;
   sendMessage("test", null); // test connecting to the server.
   reporter.handle(Event.info("Results are being streamed to " + url + "/result/" + buildId));
 }
Beispiel #2
0
 private static String readSecret(String secretFile, Reporter reporter) throws SenderException {
   if (secretFile.isEmpty()) {
     return "";
   }
   Path secretPath = new File(secretFile).toPath();
   if (!Files.isReadable(secretPath)) {
     throw new SenderException("Secret file " + secretFile + " doesn't exists or is unreadable");
   }
   try {
     if (Files.getPosixFilePermissions(secretPath).contains(PosixFilePermission.OTHERS_READ)
         || Files.getPosixFilePermissions(secretPath).contains(PosixFilePermission.GROUP_READ)) {
       reporter.handle(
           Event.warn(
               "Secret file "
                   + secretFile
                   + " is readable by non-owner. "
                   + "It is recommended to set its permission to 0600 (read-write only by the owner)."));
     }
     return new String(Files.readAllBytes(secretPath), StandardCharsets.UTF_8).trim();
   } catch (IOException e) {
     throw new SenderException("Invalid secret file " + secretFile, e);
   }
 }