public URL getNamespacedUrl(String namespace) throws MalformedURLException { URL requestUrl = getRootUrl(); if (!isResourceNamespaced()) { //if resource is not namespaced don't even bother to check the namespace. } else if (Utils.isNotNullOrEmpty(namespace)) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "namespaces", namespace)); } requestUrl = new URL(URLUtils.join(requestUrl.toString(), resourceT)); return requestUrl; }
try { URI uri = new URI(parts[0]); if (containsQueryParam(uri)) { urlQueryParams = uri.getQuery(); urlWithoutQuery = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()) try { URI partUri = new URI(parts[i]); if (containsQueryParam(partUri)) { queryParams = getQueryParams(partUri, parts, i+1); appendQueryParametersFromOriginalUrl(sb, urlQueryParams, queryParams); String joined = sb.toString();
private String getUrlHelper(String portName) { ServiceLoader<ServiceToURLProvider> urlProvider = ServiceLoader.load(ServiceToURLProvider.class, Thread.currentThread().getContextClassLoader()); Iterator<ServiceToURLProvider> iterator = urlProvider.iterator(); List<ServiceToURLProvider> servicesList = new ArrayList<>(); while(iterator.hasNext()) { servicesList.add(iterator.next()); } // Sort all loaded implementations according to priority Collections.sort(servicesList, new ServiceToUrlSortComparator()); for(ServiceToURLProvider serviceToURLProvider : servicesList) { String url = serviceToURLProvider.getURL(getMandatory(), portName, namespace, new DefaultKubernetesClient(client, getConfig())); if(url != null && URLUtils.isValidURL(url)) { return url; } } return null; }
private URL getProcessUrl() throws MalformedURLException { URL requestUrl = getRootUrl(); if (getNamespace() != null) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "namespaces" , getNamespace())); } requestUrl = new URL(URLUtils.join(requestUrl.toString(), "processedtemplates")); return requestUrl; }
@Override public Status list(Integer limitVal, String continueVal) { try { URL requestUrl = getNamespacedUrl(); if(limitVal != null) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "?limit=" + limitVal.toString())); } else if(continueVal != null) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "?limit=" + limitVal.toString() + "&continue=" + continueVal)); } Request.Builder requestBuilder = new Request.Builder().get().url(requestUrl); return handleResponse(requestBuilder, Status.class); } catch (InterruptedException | ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(e); } }
public VersionInfo fetchVersion() { try { Request.Builder requestBuilder = new Request.Builder() .get() .url(URLUtils.join(config.getMasterUrl(), versionEndpoint)); Response response = client.newCall(requestBuilder.build()).execute(); ObjectMapper objectMapper = new ObjectMapper(); Map<String, String> myMap = objectMapper.readValue(response.body().string(), HashMap.class); return new VersionInfo(myMap); } catch(Exception e) { KubernetesClientException.launderThrowable(e); } return null; } }
public L list(Integer limitVal, String continueVal) throws KubernetesClientException { try { URL url = getNamespacedUrl(); if(limitVal != null && continueVal == null) { url = new URL(URLUtils.join(url.toString(), "?limit=" + limitVal.toString())); } else if(continueVal != null) { url = new URL(URLUtils.join(url.toString(), "?continue=" + continueVal + "&limit=" + limitVal.toString() )); } return listRequestHelper(url); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(forOperationType("list"), e); } }
public URL getRootUrl() { try { if (!Utils.isNullOrEmpty(apiGroupName)) { return new URL(URLUtils.join(config.getMasterUrl().toString(), "apis", apiGroupName, apiGroupVersion)); } return new URL(URLUtils.join(config.getMasterUrl().toString(), "api", apiGroupVersion)); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(e); } }
public URL getResourceUrl(String namespace, String name) throws MalformedURLException { if (name == null) { return getNamespacedUrl(namespace); } return new URL(URLUtils.join(getNamespacedUrl(namespace).toString(), name)); }
public URL getResourceUrl() throws MalformedURLException { if (name == null) { return getNamespacedUrl(); } return new URL(URLUtils.join(getNamespacedUrl().toString(), name)); }
@Override public Build instantiate(BuildRequest request) { try { updateApiVersion(request); URL instantiationUrl = new URL(URLUtils.join(getResourceUrl().toString(), "instantiate")); RequestBody requestBody = RequestBody.create(JSON, BaseOperation.JSON_MAPPER.writer().writeValueAsString(request)); Request.Builder requestBuilder = new Request.Builder().post(requestBody).url(instantiationUrl); return handleResponse(requestBuilder, Build.class); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
protected ResponseBody doGetLog(){ try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters())); Request.Builder requestBuilder = new Request.Builder().get().url(url); Request request = requestBuilder.build(); Response response = client.newCall(request).execute(); ResponseBody body = response.body(); assertResponseCode(request, response); return body; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("doGetLog"), t); } }
@Override public LogWatch watchLog(OutputStream out) { try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters() + "&follow=true")); Request request = new Request.Builder().url(url).get().build(); final LogWatchCallback callback = new LogWatchCallback(out); OkHttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build(); clone.newCall(request).enqueue(callback); callback.waitUntilReady(); return callback; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("watchLog"), t); } }
protected ResponseBody doGetLog(){ try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters())); Request.Builder requestBuilder = new Request.Builder().get().url(url); Request request = requestBuilder.build(); Response response = client.newCall(request).execute(); ResponseBody body = response.body(); assertResponseCode(request, response); return body; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("doGetLog"), t); } }
@Override public LogWatch watchLog(OutputStream out) { try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters() + "&follow=true")); Request request = new Request.Builder().url(url).get().build(); final LogWatchCallback callback = new LogWatchCallback(out); OkHttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build(); clone.newCall(request).enqueue(callback); callback.waitUntilReady(); return callback; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("watchLog"), t); } }
@Override public Void trigger(WebHookTrigger trigger) { try { //TODO: This needs some attention. String triggerUrl = URLUtils.join(getResourceUrl().toString(), "webhooks", secret, triggerType); RequestBody requestBody = RequestBody.create(JSON, BaseOperation.JSON_MAPPER.writer().writeValueAsBytes(trigger)); Request.Builder requestBuilder = new Request.Builder() .post(requestBody) .url(triggerUrl) .addHeader("X-Github-Event", "push"); handleResponse(requestBuilder, null); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } return null; }
@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false, refs = {@BuildableReference(Config.class)}) public OpenShiftConfig(String openShiftUrl, String oapiVersion, String masterUrl, String apiVersion, String namespace, Boolean trustCerts, Boolean disableHostnameVerification, String caCertFile, String caCertData, String clientCertFile, String clientCertData, String clientKeyFile, String clientKeyData, String clientKeyAlgo, String clientKeyPassphrase, String username, String password, String oauthToken, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, long rollingTimeout, long scaleTimeout, int loggingInterval, Integer maxConcurrentRequestsPerHost, String httpProxy, String httpsProxy, String[] noProxy, Map<Integer, String> errorMessages, String userAgent, TlsVersion[] tlsVersions, long buildTimeout, long websocketTimeout, long websocketPingInterval, String proxyUsername, String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, String impersonateUsername, String[] impersonateGroups, Map<String, List<String>> impersonateExtras) { super(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile, clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken, watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout, loggingInterval, maxConcurrentRequestsPerHost, httpProxy, httpsProxy, noProxy, errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword, trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups, impersonateExtras); this.oapiVersion = oapiVersion; this.openShiftUrl = openShiftUrl; this.buildTimeout = buildTimeout; if (this.openShiftUrl == null || this.openShiftUrl.isEmpty()) { this.openShiftUrl = URLUtils.join(getMasterUrl(), "oapi", this.oapiVersion); } if (!this.openShiftUrl.endsWith("/")) { this.openShiftUrl = this.openShiftUrl + "/"; } }
private String authorize() throws IOException { OkHttpClient.Builder builder = client.newBuilder(); builder.interceptors().remove(this); OkHttpClient clone = builder.build(); String credential = Credentials.basic(config.getUsername(), new String(config.getPassword())); URL url = new URL(URLUtils.join(config.getMasterUrl(), AUTHORIZE_PATH)); Response response = clone.newCall(new Request.Builder().get().url(url).header(AUTHORIZATION, credential).build()).execute(); response.body().close(); response = response.priorResponse() != null ? response.priorResponse() : response; response = response.networkResponse() != null ? response.networkResponse() : response; String token = response.header(LOCATION); if (token == null || token.isEmpty()) { throw new IOException("Unexpected response(" + response.code() + " " + response.message() + "), to the authorization request. Missing header:[" + LOCATION + "]!"); } token = token.substring(token.indexOf(BEFORE_TOKEN) + BEFORE_TOKEN.length()); token = token.substring(0, token.indexOf(AFTER_TOKEN)); return token; } }
private static String getDefaultOpenShiftUrl(Config config) { String openshiftUrl = Utils.getSystemPropertyOrEnvVar(OPENSHIFT_URL_SYTEM_PROPERTY); if (openshiftUrl != null) { // The OPENSHIFT_URL environment variable may be set to the root url (i.e. without the '/oapi/version' path) in some configurations if (isRootURL(openshiftUrl)) { openshiftUrl = URLUtils.join(openshiftUrl, "oapi", getDefaultOapiVersion(config)); } return openshiftUrl; } else { return URLUtils.join(config.getMasterUrl(), "oapi", getDefaultOapiVersion(config)); } }
private String getQueryParameters() throws MalformedURLException { StringBuilder sb = new StringBuilder(); sb.append(URLUtils.join(getResourceUrl().toString(), "instantiatebinary")); if (Utils.isNullOrEmpty(message)) { sb.append("?commit="); } else { sb.append("?commit=").append(message); } if (!Utils.isNullOrEmpty(authorName)) { sb.append("&revision.authorName=").append(authorName); } if (!Utils.isNullOrEmpty(authorEmail)) { sb.append("&revision.authorEmail=").append(authorEmail); } if (!Utils.isNullOrEmpty(committerName)) { sb.append("&revision.committerName=").append(committerName); } if (!Utils.isNullOrEmpty(committerEmail)) { sb.append("&revision.committerEmail=").append(committerEmail); } if (!Utils.isNullOrEmpty(commit)) { sb.append("&revision.commit=").append(commit); } if (!Utils.isNullOrEmpty(asFile)) { sb.append("&asFile=").append(asFile); } return sb.toString(); }