package io.kubernetes.client.util;

import io.kubernetes.client.ApiClient;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.IOException;

public class Config {
    private static final String SERVICEACCOUNT_ROOT =
        "/var/run/secrets/kubernetes.io/serviceaccount";
    private static final String SERVICEACCOUNT_CA_PATH =
        SERVICEACCOUNT_ROOT + "/ca.crt";
    private static final String SERVICEACCOUNT_TOKEN_PATH =
        SERVICEACCOUNT_ROOT + "/token";

    public static ApiClient fromCluster() throws IOException {
        String host = System.getenv("KUBERNETES_SERVICE_HOST");
        String port = System.getenv("KUBERNETES_SERVICE_PORT");

        FileInputStream caCert = new FileInputStream(SERVICEACCOUNT_CA_PATH);
        BufferedReader tokenReader = new BufferedReader(new FileReader(SERVICEACCOUNT_TOKEN_PATH));
        StringBuilder builder = new StringBuilder();
        for (String line = tokenReader.readLine(); line != null; line = tokenReader.readLine()) {
            builder.append(line);
        }
        ApiClient result = new ApiClient();
        result.setBasePath("https://" + host + ":" + port);
        result.setSslCaCert(caCert);
        result.setAccessToken(builder.toString());

        return result;
    }
}
@@ -1306,10 +1306,1032 @@
 t;%0A    %7D
+%0A%0A    public static ApiClient fromUrl(String url) %7B%0A        return fromUrl(url, true);%0A    %7D%0A%0A    public static ApiClient fromUrl(String url, boolean validateSSL) %7B%0A        return new ApiClient()%0A            .setBasePath(url)%0A            .setVerifyingSsl(validateSSL);%0A    %7D%0A%0A    public static ApiClient fromUserPassword(String url, String user, String password) %7B%0A        return fromUserPassword(url, user, password, true);%0A    %7D%0A%0A    public static ApiClient fromUserPassword(String url, String user, String password, boolean validateSSL) %7B%0A        ApiClient client = fromUrl(url, validateSSL);%0A        client.setUsername(user);%0A        client.setPassword(password);%0A        return client;%0A    %7D%0A%0A    public static ApiClient fromToken(String url, String token) %7B%0A        return fromToken(url, token, true);%0A    %7D%0A%0A    public static ApiClient fromToken(String url, String token, boolean validateSSL) %7B%0A        ApiClient client = fromUrl(url, validateSSL);%0A        client.setAccessToken(token);%0A        return client;%0A    %7D
 %0A%7D

Add a bunch of simplified helper methods for creating clients from different information.