private void addJenkinsServiceUrl(Map<String, String> annotations, String repoName) { String buildId = Systems.getEnvVarOrSystemProperty("BUILD_ID"); if (buildId != null) { annotations.put(Annotations.Builds.BUILD_ID, buildId); String serviceUrl = getExternalServiceURL(getConfig(Config.jenkinsService), "http"); if (serviceUrl != null) { String jobUrl = URLUtils.pathJoin(serviceUrl, "/job", repoName); jobUrl = URLUtils.pathJoin(jobUrl, buildId); annotations.put(Annotations.Builds.BUILD_URL, jobUrl); } } else { log.debug("No Jenkins annotation as no BUILD_ID could be found"); } }
/** * Prepares an url connection for authentication if necessary. * * @param connection the connection to be prepared * * @return the prepared conection */ public static URLConnection prepareForAuthentication(final URLConnection connection) { NullArgumentException.validateNotNull(connection, "url connection cannot be null"); if (connection.getURL().getUserInfo() != null) { // Need to decode username/password because it may contain encoded // characters (http://www.w3schools.com/tags/ref_urlencode.asp) // A common encoding is to provide a username as an email address // like user%40domain.org String decodedUserInfo = decode(connection.getURL().getUserInfo()); String base64Encoded = io.fabric8.utils.Base64Encoder.encode(decodedUserInfo); // sun bug 6459815: Long passwords cause Basic Auth to fail with a // java.net.Authenticator base64Encoded = base64Encoded.replaceAll("\n", ""); connection.setRequestProperty("Authorization", "Basic " + base64Encoded); } return connection; }
/** * Prepare url for authentication and ssl if necessary and returns the input stream from the url. * * @param url url to prepare * @param acceptAnyCertificate true if the certicate check should be skipped * @return input stream from url * @throws IOException re-thrown */ public static InputStream prepareInputStream(final URL url, final boolean acceptAnyCertificate) throws IOException { final URLConnection conn = url.openConnection(); prepareForAuthentication(conn); if (acceptAnyCertificate) { prepareForSSL(conn); } return conn.getInputStream(); }
private void addGitServiceUrl(Map<String, String> annotations, String repoName, String gitCommitId) { String username = getGitUserName(); // this requires online access to kubernetes so we should silently fail if no connection String gogsUrl = getExternalServiceURL(getConfig(Config.gitService), "http"); String rootGitUrl = URLUtils.pathJoin(gogsUrl, username, repoName); rootGitUrl = URLUtils.pathJoin(rootGitUrl, "commit", gitCommitId); if (Strings.isNotBlank(rootGitUrl)) { annotations.put(Annotations.Builds.GIT_URL, rootGitUrl); } }
protected String getAvatarUrl(String email) { String hash = MD5Util.md5Hex(email); if (Strings.isNotBlank(hash)) { return URLUtils.pathJoin(gravatarUrl, hash); } return null; }
/** * Returns the webhook URL for the given module. * * The module webhook might not use the correct public host name so lets convert it. */ public String getPublicWebhookUrl(ModuleDTO module) { if (module != null) { String webhooksUrl = module.getWebhooksUrl(); if (Strings.isNotBlank(webhooksUrl)) { int idx = webhooksUrl.indexOf("/api/v"); if (idx > 0) { return URLUtils.pathJoin(getAddress(), webhooksUrl.substring(idx)); } } return webhooksUrl; } return null; }
private String findGrafanaLink() { MavenProject project = getProject(); String defaultDashboard = detectDefaultDashboard(project); String query = ""; String projectName = null; String version = null; // TODO - use the docker names which may differ from project metadata! if (Strings.isNullOrBlank(projectName)) { projectName = project.getArtifactId(); } if (Strings.isNullOrBlank(version)) { version = project.getVersion(); } if (Strings.isNotBlank(projectName)) { query += "&var-project=" + projectName; } if (Strings.isNotBlank(version)) { query += "&var-version=" + version; } if (query.startsWith("&")) { query = "?" + query.substring(1); } return URLUtils.pathJoin("dashboard/file", defaultDashboard, query); }
/** * Returns the URL to the fabric8 console */ public static String getBuildConfigConsoleURL(KubernetesClient kubernetes, String consoleNamespace, BuildConfig buildConfig) { String name = getName(buildConfig); String namespace = getNamespace(buildConfig); if (Strings.isNullOrBlank(namespace)) { namespace = consoleNamespace; } String consoleURL = getFabric8ConsoleServiceUrl(kubernetes, namespace); if (Strings.isNotBlank(consoleURL)) { if (Strings.isNotBlank(name)) { return URLUtils.pathJoin(consoleURL, "workspaces", namespace, "projects",name); } return URLUtils.pathJoin(consoleURL, "workspaces", namespace); } return null; }
return URLUtils.pathJoin(publicUrl, u.getPath());
for (String prefix : prefixes) { if (url.startsWith(prefix)) { url = URLUtils.pathJoin("https://cdn.rawgit.com/", url.substring(prefix.length())); break; log.warn("No iconUrlPrefix defined or could be found via SCM in the pom.xml so cannot add an icon URL!"); } else { String answer = URLUtils.pathJoin(urlPrefix, getConfig(Config.branch), relativePath); return answer;
jobUrl = URLUtils.pathJoin(jenkinsUrl, "/job", name); String buildId = env.get("BUILD_ID"); if (Strings.isNotBlank(buildId)) { jobUrl = URLUtils.pathJoin(jobUrl, buildId); } else { listener.getLogger().println("Cannot find BUILD_ID to create a specific jenkins build URL. So using: " + jobUrl); gitUrl = URLUtils.pathJoin(gitUrl, "commit", gitCommitId);
jobUrl = URLUtils.pathJoin(jenkinsUrl, "/job", name); String buildId = env.get("BUILD_ID"); if (Strings.isNotBlank(buildId)) { jobUrl = URLUtils.pathJoin(jobUrl, buildId); } else { listener.getLogger().println("Cannot find BUILD_ID to create a specific jenkins build URL. So using: " + jobUrl); gitUrl = URLUtils.pathJoin(gitUrl, "commit", gitCommitId);
String webhookUrl = URLUtils.pathJoin(kubeAddress, "osapi", KubernetesHelper.defaultOsApiVersion, "buildConfigHooks", buildName, secret, type);