Skip to content
Merged
Prev Previous commit
Next Next commit
feedback review
  • Loading branch information
marceljk committed Aug 7, 2025
commit fbd3fc76c1bf081f0b173329367dc2c300844a5b
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
import java.util.concurrent.TimeUnit;
import okhttp3.*;


/** KeyFlowAuthenticator handles the Key Flow Authentication based on the Service Account Key. */
public class KeyFlowAuthenticator {
private final String REFRESH_TOKEN = "refresh_token";
private final String ASSERTION = "assertion";
private final String DEFAULT_TOKEN_ENDPOINT = "https://service-account.api.stackit.cloud/token";
private final long DEFAULT_TOKEN_LEEWAY = 60;
private final int CONNECT_TIMEOUT = 10;
private final int WRITE_TIMEOUT = 10;
private final int READ_TIMEOUT = 10;

private final OkHttpClient httpClient;
private final ServiceAccountKey saKey;
Expand Down Expand Up @@ -94,9 +98,9 @@ public KeyFlowAuthenticator(
this.gson = new Gson();
this.httpClient =
new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.build();

if (environmentVariables == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,17 @@ protected void loadPrivateKey(CoreConfiguration cfg, ServiceAccountKey saKey)
private String getPrivateKey(CoreConfiguration cfg)
throws CredentialsInFileNotFoundException, IOException {
// Explicit code config
// Set private key
// Get private key
if (Utils.isStringSet(cfg.getPrivateKey())) {
return cfg.getPrivateKey();
}
// Set private key path
// Get private key path
if (Utils.isStringSet(cfg.getPrivateKeyPath())) {
String privateKeyPath = cfg.getPrivateKeyPath();
return new String(
Files.readAllBytes(Paths.get(privateKeyPath)), StandardCharsets.UTF_8);
}
// Set credentials file
// Get credentials file
if (Utils.isStringSet(cfg.getCredentialsFilePath())) {
return readValueFromCredentialsFile(
cfg.getCredentialsFilePath(),
Expand All @@ -231,15 +231,18 @@ private String getPrivateKey(CoreConfiguration cfg)
}

// ENVs config
// Get private key
if (Utils.isStringSet(env.getStackitPrivateKey())) {
return env.getStackitPrivateKey().trim();
}
// Get private key path
if (Utils.isStringSet(env.getStackitPrivateKeyPath())) {
return new String(
Files.readAllBytes(Paths.get(env.getStackitPrivateKeyPath())),
StandardCharsets.UTF_8);
}

// Get credentialsFilePath
String credentialsFilePath =
Utils.isStringSet(env.getStackitCredentialsPath())
? env.getStackitCredentialsPath()
Expand Down