package ekoshkin.teamcity.clouds.kubernetes.auth;

import io.fabric8.kubernetes.client.ConfigBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * Created by ekoshkin (koshkinev@gmail.com) on 14.06.17.
 */
public class DefaultServiceAccountAuthStrategy implements KubeAuthStrategy {
    @NotNull
    @Override
    public String getId() {
        return null;
    }

    @NotNull
    @Override
    public String getDisplayName() {
        return null;
    }

    @Nullable
    @Override
    public String getDescription() {
        return null;
    }

    @Override
    public void apply(@NotNull ConfigBuilder clientConfig) {

    }
}

@@ -55,50 +55,275 @@
 ort 
-io.fabric8.kubernetes.client.ConfigBuilder
+ekoshkin.teamcity.clouds.kubernetes.KubeCloudException;%0Aimport ekoshkin.teamcity.clouds.kubernetes.connector.KubeApiConnection;%0Aimport io.fabric8.kubernetes.client.ConfigBuilder;%0Aimport jetbrains.buildServer.util.FileUtil;%0Aimport jetbrains.buildServer.util.StringUtil
 ;%0Aim
@@ -406,16 +406,66 @@
 lable;%0A%0A
+import java.io.File;%0Aimport java.io.IOException;%0A%0A
 /**%0A * C
@@ -599,16 +599,141 @@
 ategy %7B%0A
+    private static final String DEFAULT_SERVICE_ACCOUNT_TOKEN_FILE = %22/var/run/secrets/kubernetes.io/serviceaccount/token%22;%0A%0A
     @Not
@@ -786,36 +786,49 @@
 %0A        return 
-null
+%22service-account%22
 ;%0A    %7D%0A%0A    @No
@@ -891,36 +891,57 @@
 %0A        return 
-null
+%22Default Service Account%22
 ;%0A    %7D%0A%0A    @Nu
@@ -1022,24 +1022,37 @@
 ull;%0A    %7D%0A%0A
+    @NotNull%0A
     @Overrid
@@ -1068,12 +1068,21 @@
 lic 
-void
+ConfigBuilder
  app
@@ -1119,20 +1119,615 @@
 ntConfig
-) %7B%0A
+, @NotNull KubeApiConnection connection) %7B%0A        String defaultServiceAccountAuthToken = getDefaultServiceAccountAuthToken();%0A        if(StringUtil.isEmpty(defaultServiceAccountAuthToken)) throw new KubeCloudException(%22Can't locate default Kubernetes service account token.%22);%0A        return clientConfig.withOauthToken(defaultServiceAccountAuthToken);%0A    %7D%0A%0A    @Nullable%0A    private String getDefaultServiceAccountAuthToken() %7B%0A        try %7B%0A            return FileUtil.readText(new File(DEFAULT_SERVICE_ACCOUNT_TOKEN_FILE));%0A        %7D catch (IOException e) %7B%0A            return null;%0A        %7D
 %0A    %7D%0A%7D

read default serice account token