diff --git a/core/src/main/java/cloud/stackit/sdk/core/auth/SetupAuth.java b/core/src/main/java/cloud/stackit/sdk/core/auth/SetupAuth.java index c23eaea..bee989c 100644 --- a/core/src/main/java/cloud/stackit/sdk/core/auth/SetupAuth.java +++ b/core/src/main/java/cloud/stackit/sdk/core/auth/SetupAuth.java @@ -39,7 +39,7 @@ public class SetupAuth { * @throws CredentialsInFileNotFoundException when no configuration is set or can be found */ public SetupAuth() throws CredentialsInFileNotFoundException { - this(new CoreConfiguration.Builder().build(), new EnvironmentVariables()); + this(new CoreConfiguration(), new EnvironmentVariables()); } /** @@ -66,7 +66,7 @@ public SetupAuth(CoreConfiguration cfg) throws IOException, CredentialsInFileNot protected SetupAuth(CoreConfiguration cfg, EnvironmentVariables environmentVariables) throws CredentialsInFileNotFoundException { - this.cfg = cfg != null ? cfg : new CoreConfiguration.Builder().build(); + this.cfg = cfg != null ? cfg : new CoreConfiguration(); this.env = environmentVariables != null ? environmentVariables : new EnvironmentVariables(); } diff --git a/core/src/main/java/cloud/stackit/sdk/core/config/CoreConfiguration.java b/core/src/main/java/cloud/stackit/sdk/core/config/CoreConfiguration.java index f100526..caa5ed3 100644 --- a/core/src/main/java/cloud/stackit/sdk/core/config/CoreConfiguration.java +++ b/core/src/main/java/cloud/stackit/sdk/core/config/CoreConfiguration.java @@ -3,27 +3,17 @@ import java.util.Map; public class CoreConfiguration { - private final Map defaultHeader; - private final String serviceAccountKey; - private final String serviceAccountKeyPath; - private final String privateKeyPath; - private final String privateKey; - private final String customEndpoint; - private final String credentialsFilePath; - private final String tokenCustomUrl; - private final Long tokenExpirationLeeway; - - CoreConfiguration(Builder builder) { - this.defaultHeader = builder.defaultHeader; - this.serviceAccountKey = builder.serviceAccountKey; - this.serviceAccountKeyPath = builder.serviceAccountKeyPath; - this.privateKeyPath = builder.privateKeyPath; - this.privateKey = builder.privateKey; - this.customEndpoint = builder.customEndpoint; - this.credentialsFilePath = builder.credentialsFilePath; - this.tokenCustomUrl = builder.tokenCustomUrl; - this.tokenExpirationLeeway = builder.tokenExpirationLeeway; - } + private Map defaultHeader; + private String serviceAccountKey; + private String serviceAccountKeyPath; + private String privateKeyPath; + private String privateKey; + private String customEndpoint; + private String credentialsFilePath; + private String tokenCustomUrl; + private Long tokenExpirationLeeway; + + public CoreConfiguration() {} public Map getDefaultHeader() { return defaultHeader; @@ -61,64 +51,48 @@ public Long getTokenExpirationLeeway() { return tokenExpirationLeeway; } - public static class Builder { - private Map defaultHeader; - private String serviceAccountKey; - private String serviceAccountKeyPath; - private String privateKeyPath; - private String privateKey; - private String customEndpoint; - private String credentialsFilePath; - private String tokenCustomUrl; - private Long tokenExpirationLeeway; - - public Builder defaultHeader(Map defaultHeader) { - this.defaultHeader = defaultHeader; - return this; - } - - public Builder serviceAccountKey(String serviceAccountKey) { - this.serviceAccountKey = serviceAccountKey; - return this; - } - - public Builder serviceAccountKeyPath(String serviceAccountKeyPath) { - this.serviceAccountKeyPath = serviceAccountKeyPath; - return this; - } - - public Builder privateKeyPath(String privateKeyPath) { - this.privateKeyPath = privateKeyPath; - return this; - } - - public Builder privateKey(String privateKey) { - this.privateKey = privateKey; - return this; - } - - public Builder customEndpoint(String customEndpoint) { - this.customEndpoint = customEndpoint; - return this; - } - - public Builder credentialsFilePath(String credentialsFilePath) { - this.credentialsFilePath = credentialsFilePath; - return this; - } - - public Builder tokenCustomUrl(String tokenCustomUrl) { - this.tokenCustomUrl = tokenCustomUrl; - return this; - } - - public Builder tokenExpirationLeeway(Long tokenExpirationLeeway) { - this.tokenExpirationLeeway = tokenExpirationLeeway; - return this; - } - - public CoreConfiguration build() { - return new CoreConfiguration(this); - } + public CoreConfiguration defaultHeader(Map defaultHeader) { + this.defaultHeader = defaultHeader; + return this; + } + + public CoreConfiguration serviceAccountKey(String serviceAccountKey) { + this.serviceAccountKey = serviceAccountKey; + return this; + } + + public CoreConfiguration serviceAccountKeyPath(String serviceAccountKeyPath) { + this.serviceAccountKeyPath = serviceAccountKeyPath; + return this; + } + + public CoreConfiguration privateKeyPath(String privateKeyPath) { + this.privateKeyPath = privateKeyPath; + return this; + } + + public CoreConfiguration privateKey(String privateKey) { + this.privateKey = privateKey; + return this; + } + + public CoreConfiguration customEndpoint(String customEndpoint) { + this.customEndpoint = customEndpoint; + return this; + } + + public CoreConfiguration credentialsFilePath(String credentialsFilePath) { + this.credentialsFilePath = credentialsFilePath; + return this; + } + + public CoreConfiguration tokenCustomUrl(String tokenCustomUrl) { + this.tokenCustomUrl = tokenCustomUrl; + return this; + } + + public CoreConfiguration tokenExpirationLeeway(Long tokenExpirationLeeway) { + this.tokenExpirationLeeway = tokenExpirationLeeway; + return this; } } diff --git a/core/src/test/java/cloud/stackit/sdk/core/KeyFlowAuthenticatorTest.java b/core/src/test/java/cloud/stackit/sdk/core/KeyFlowAuthenticatorTest.java index 0465171..2ca7c24 100644 --- a/core/src/test/java/cloud/stackit/sdk/core/KeyFlowAuthenticatorTest.java +++ b/core/src/test/java/cloud/stackit/sdk/core/KeyFlowAuthenticatorTest.java @@ -116,9 +116,7 @@ void getAccessToken_response200_noException() // Config HttpUrl url = mockWebServer.url("/token"); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey); @@ -143,9 +141,7 @@ void getAccessToken_expiredToken_noException() // Config HttpUrl url = mockWebServer.url("/token"); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey); keyFlowAuthenticator.setToken(expiredKey); @@ -162,9 +158,7 @@ void createAccessToken_response200WithEmptyBody_throwsException() { // Config CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer // Init keyFlowAuthenticator KeyFlowAuthenticator keyFlowAuthenticator = @@ -182,9 +176,7 @@ void createAccessToken_response400_throwsApiException() { // Config CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer // Init keyFlowAuthenticator KeyFlowAuthenticator keyFlowAuthenticator = @@ -206,9 +198,7 @@ void createAccessToken_response200WithValidResponse_noException() // Config HttpUrl url = mockWebServer.url("/token"); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer // Init keyFlowAuthenticator KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey); @@ -229,9 +219,7 @@ void createAccessTokenWithRefreshToken_response200WithValidResponse_noException( // Config HttpUrl url = mockWebServer.url("/token"); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer // Prepare keyFlowAuthenticator KeyFlowAuthenticator keyFlowAuthenticator = new KeyFlowAuthenticator(cfg, defaultSaKey); @@ -251,9 +239,7 @@ void createAccessTokenWithRefreshToken_response200WithEmptyBody_throwsException( // Config CoreConfiguration cfg = - new CoreConfiguration.Builder() - .tokenCustomUrl(url.toString()) // Use mockWebServer - .build(); + new CoreConfiguration().tokenCustomUrl(url.toString()); // Use mockWebServer // Prepare keyFlowAuthenticator KeyFlowAuthenticator keyFlowAuthenticator = diff --git a/core/src/test/java/cloud/stackit/sdk/core/auth/SetupAuthTest.java b/core/src/test/java/cloud/stackit/sdk/core/auth/SetupAuthTest.java index 6e1d0ec..8946567 100644 --- a/core/src/test/java/cloud/stackit/sdk/core/auth/SetupAuthTest.java +++ b/core/src/test/java/cloud/stackit/sdk/core/auth/SetupAuthTest.java @@ -76,8 +76,7 @@ void getAccessToken_withRunningInit_returnsInterceptor() throws IOException { ServiceAccountKey saKey = createDummyServiceAccount("privateKey"); String initSaKeyJson = new Gson().toJson(saKey); - CoreConfiguration config = - new CoreConfiguration.Builder().serviceAccountKey(initSaKeyJson).build(); + CoreConfiguration config = new CoreConfiguration().serviceAccountKey(initSaKeyJson); SetupAuth setupAuth = new SetupAuth(config); setupAuth.init(); @@ -96,9 +95,8 @@ void setupKeyFlow_readServiceAccountFromPath() // Create config and read setup auth with the previous created saKey CoreConfiguration cfg = - new CoreConfiguration.Builder() - .serviceAccountKeyPath(saKeyPath.toAbsolutePath().toString()) - .build(); + new CoreConfiguration() + .serviceAccountKeyPath(saKeyPath.toAbsolutePath().toString()); ServiceAccountKey parsedSaKey = new SetupAuth().setupKeyFlow(cfg); assertEquals(initSaKey, parsedSaKey); @@ -112,8 +110,7 @@ void setupKeyFlow_readServiceAccountFromConfig() String initSaKeyJson = new Gson().toJson(initSaKey); // Create config and read setup auth with the previous created saKey - CoreConfiguration cfg = - new CoreConfiguration.Builder().serviceAccountKey(initSaKeyJson).build(); + CoreConfiguration cfg = new CoreConfiguration().serviceAccountKey(initSaKeyJson); ServiceAccountKey parsedSaKey = new SetupAuth().setupKeyFlow(cfg); assertEquals(initSaKey, parsedSaKey); @@ -129,7 +126,7 @@ void setupKeyFlow_readServiceAccountFromKeyEnv() throws IOException { when(envs.getStackitServiceAccountKey()).thenReturn(initSaKeyJson); // Create config and read setup auth with the previous created saKey - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); ServiceAccountKey parsedSaKey = new SetupAuth(cfg, envs).setupKeyFlow(cfg); assertEquals(initSaKey, parsedSaKey); @@ -151,7 +148,7 @@ void setupKeyFlow_readServiceAccountFromKeyPathEnv() throws IOException { .thenReturn(keyPathFile.toAbsolutePath().toString()); // Create config and read setup auth with the previous created saKey - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); ServiceAccountKey parsedSaKey = new SetupAuth(cfg, envs).setupKeyFlow(cfg); assertEquals(initSaKey, parsedSaKey); @@ -169,12 +166,11 @@ void setupKeyFlow_readServiceAccountFromPathWithoutPrivateKey_throwsException() // Create config and read setup auth with the previous created saKey CoreConfiguration cfg = - new CoreConfiguration.Builder() + new CoreConfiguration() .serviceAccountKeyPath(saKeyPath.toAbsolutePath().toString()) .credentialsFilePath( // make sure that the defaultCredentialsFile is not // used - invalidCredentialsFilePath) - .build(); + invalidCredentialsFilePath); SetupAuth auth = new SetupAuth(); assertThrows(PrivateKeyNotFoundException.class, () -> auth.setupKeyFlow(cfg)); @@ -189,12 +185,11 @@ void setupKeyFlow_readServiceAccountFromConfigWithoutPrivateKey_throwsException( // Create config and read setup auth with the previous created saKey CoreConfiguration cfg = - new CoreConfiguration.Builder() + new CoreConfiguration() .serviceAccountKey(initSaKeyJson) .credentialsFilePath( // make sure that the defaultCredentialsFile is not // used - invalidCredentialsFilePath) - .build(); + invalidCredentialsFilePath); SetupAuth auth = new SetupAuth(); assertThrows(PrivateKeyNotFoundException.class, () -> auth.setupKeyFlow(cfg)); @@ -207,7 +202,7 @@ void loadPrivateKey_setPrivateKeyFromConfig() ServiceAccountKey saKey = createDummyServiceAccount(null); SetupAuth setupAuth = new SetupAuth(); - CoreConfiguration cfg = new CoreConfiguration.Builder().privateKey(prvKey).build(); + CoreConfiguration cfg = new CoreConfiguration().privateKey(prvKey); assertNull(saKey.getCredentials().getPrivateKey()); assertDoesNotThrow(() -> setupAuth.loadPrivateKey(cfg, saKey)); @@ -223,7 +218,7 @@ void loadPrivateKey_doesNotOverwriteExistingPrivateKey() // Create Service Account ServiceAccountKey saKey = createDummyServiceAccount(initialPrivateKey); SetupAuth setupAuth = new SetupAuth(); - CoreConfiguration cfg = new CoreConfiguration.Builder().privateKey(cfgPrivateKey).build(); + CoreConfiguration cfg = new CoreConfiguration().privateKey(cfgPrivateKey); assertEquals(initialPrivateKey, saKey.getCredentials().getPrivateKey()); assertDoesNotThrow(() -> setupAuth.loadPrivateKey(cfg, saKey)); @@ -243,9 +238,7 @@ void loadPrivateKey_setPrivateKeyPath() ServiceAccountKey saKey = createDummyServiceAccount(null); SetupAuth setupAuth = new SetupAuth(); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .privateKeyPath(tempPrvKeyFile.toAbsolutePath().toString()) - .build(); + new CoreConfiguration().privateKeyPath(tempPrvKeyFile.toAbsolutePath().toString()); assertNull(saKey.getCredentials().getPrivateKey()); assertDoesNotThrow(() -> setupAuth.loadPrivateKey(cfg, saKey)); @@ -280,9 +273,8 @@ void loadPrivateKey_setPrivateKeyPathViaCredentialsFile() ServiceAccountKey saKey = createDummyServiceAccount(null); SetupAuth setupAuth = new SetupAuth(); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .credentialsFilePath(tempCredentialsFile.toAbsolutePath().toString()) - .build(); + new CoreConfiguration() + .credentialsFilePath(tempCredentialsFile.toAbsolutePath().toString()); assertNull(saKey.getCredentials().getPrivateKey()); assertDoesNotThrow(() -> setupAuth.loadPrivateKey(cfg, saKey)); @@ -310,9 +302,8 @@ void loadPrivateKey_setPrivateKeyViaCredentialsFile() SetupAuth setupAuth = new SetupAuth(); CoreConfiguration cfg = - new CoreConfiguration.Builder() - .credentialsFilePath(tempCredentialsFile.toAbsolutePath().toString()) - .build(); + new CoreConfiguration() + .credentialsFilePath(tempCredentialsFile.toAbsolutePath().toString()); assertNull(saKey.getCredentials().getPrivateKey()); assertDoesNotThrow(() -> setupAuth.loadPrivateKey(cfg, saKey)); @@ -325,7 +316,7 @@ void loadPrivateKey_setPrivateKeyViaEnv() throws IOException { ServiceAccountKey saKey = createDummyServiceAccount(null); when(envs.getStackitPrivateKey()).thenReturn(prvKey); - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); SetupAuth setupAuth = new SetupAuth(cfg, envs); assertNull(saKey.getCredentials().getPrivateKey()); @@ -344,7 +335,7 @@ void loadPrivateKey_setPrivateKeyPathViaEnv() throws IOException { when(envs.getStackitPrivateKeyPath()) .thenReturn(tempPrvKeyFile.toAbsolutePath().toString()); - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); SetupAuth setupAuth = new SetupAuth(cfg, envs); assertNull(saKey.getCredentials().getPrivateKey()); @@ -370,7 +361,7 @@ void loadPrivateKey_setPrivateKeyViaCredentialsFileInEnv() // Create dummy service account and config ServiceAccountKey saKey = createDummyServiceAccount(null); - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); SetupAuth setupAuth = new SetupAuth(cfg, envs); when(envs.getStackitCredentialsPath()) .thenReturn(tempCredentialsFile.toAbsolutePath().toString()); @@ -396,7 +387,7 @@ void loadPrivateKey_invalidPrivateKeyPath_throwsException() ServiceAccountKey saKey = createDummyServiceAccount(null); SetupAuth setupAuth = new SetupAuth(); - CoreConfiguration cfg = new CoreConfiguration.Builder().privateKeyPath(invalidPath).build(); + CoreConfiguration cfg = new CoreConfiguration().privateKeyPath(invalidPath); assertNull(saKey.getCredentials().getPrivateKey()); assertThrows(PrivateKeyNotFoundException.class, () -> setupAuth.loadPrivateKey(cfg, saKey)); diff --git a/core/src/test/java/cloud/stackit/sdk/core/config/CoreConfigurationTest.java b/core/src/test/java/cloud/stackit/sdk/core/config/CoreConfigurationTest.java index 4c0e37b..d02897a 100644 --- a/core/src/test/java/cloud/stackit/sdk/core/config/CoreConfigurationTest.java +++ b/core/src/test/java/cloud/stackit/sdk/core/config/CoreConfigurationTest.java @@ -12,7 +12,7 @@ class CoreConfigurationTest { void getDefaultHeader() { HashMap map = new HashMap(); map.put("key", "value"); - CoreConfiguration cfg = new CoreConfiguration.Builder().defaultHeader(map).build(); + CoreConfiguration cfg = new CoreConfiguration().defaultHeader(map); Map cfgHeader = cfg.getDefaultHeader(); assertEquals(map, cfgHeader); @@ -22,7 +22,7 @@ void getDefaultHeader() { void getServiceAccountKey() { final String saKey = ""; - CoreConfiguration cfg = new CoreConfiguration.Builder().serviceAccountKey(saKey).build(); + CoreConfiguration cfg = new CoreConfiguration().serviceAccountKey(saKey); String cfgSaKey = cfg.getServiceAccountKey(); @@ -33,8 +33,7 @@ void getServiceAccountKey() { void getServiceAccountKeyPath() { final String saKeyPath = ""; - CoreConfiguration cfg = - new CoreConfiguration.Builder().serviceAccountKeyPath(saKeyPath).build(); + CoreConfiguration cfg = new CoreConfiguration().serviceAccountKeyPath(saKeyPath); String cfgSaKeyPath = cfg.getServiceAccountKeyPath(); @@ -45,8 +44,7 @@ void getServiceAccountKeyPath() { void getPrivateKeyPath() { final String privateKeyPath = ""; - CoreConfiguration cfg = - new CoreConfiguration.Builder().privateKeyPath(privateKeyPath).build(); + CoreConfiguration cfg = new CoreConfiguration().privateKeyPath(privateKeyPath); String cfgPrivateKeyPath = cfg.getPrivateKeyPath(); @@ -57,7 +55,7 @@ void getPrivateKeyPath() { void getPrivateKey() { final String privateKey = ""; - CoreConfiguration cfg = new CoreConfiguration.Builder().privateKey(privateKey).build(); + CoreConfiguration cfg = new CoreConfiguration().privateKey(privateKey); String cfgPrivateKey = cfg.getPrivateKey(); @@ -68,8 +66,7 @@ void getPrivateKey() { void getCustomEndpoint() { final String customEndpoint = ""; - CoreConfiguration cfg = - new CoreConfiguration.Builder().customEndpoint(customEndpoint).build(); + CoreConfiguration cfg = new CoreConfiguration().customEndpoint(customEndpoint); String cfgCustomEndpoint = cfg.getCustomEndpoint(); @@ -80,8 +77,7 @@ void getCustomEndpoint() { void getCredentialsFilePath() { final String credFilePath = ""; - CoreConfiguration cfg = - new CoreConfiguration.Builder().credentialsFilePath(credFilePath).build(); + CoreConfiguration cfg = new CoreConfiguration().credentialsFilePath(credFilePath); String cfgCredentialsFilePath = cfg.getCredentialsFilePath(); @@ -92,8 +88,7 @@ void getCredentialsFilePath() { void getTokenCustomUrl() { final String tokenCustomUrl = ""; - CoreConfiguration cfg = - new CoreConfiguration.Builder().tokenCustomUrl(tokenCustomUrl).build(); + CoreConfiguration cfg = new CoreConfiguration().tokenCustomUrl(tokenCustomUrl); String cfgTokenUrl = cfg.getTokenCustomUrl(); @@ -104,8 +99,7 @@ void getTokenCustomUrl() { void getTokenExpirationLeeway() { final long tokenExpireLeeway = 100; - CoreConfiguration cfg = - new CoreConfiguration.Builder().tokenExpirationLeeway(tokenExpireLeeway).build(); + CoreConfiguration cfg = new CoreConfiguration().tokenExpirationLeeway(tokenExpireLeeway); Long cfgTokenExpirationLeeway = cfg.getTokenExpirationLeeway(); @@ -114,7 +108,7 @@ void getTokenExpirationLeeway() { @Test void getDefaultHeader_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); Map defaultHeader = cfg.getDefaultHeader(); assertNull(defaultHeader); @@ -122,7 +116,7 @@ void getDefaultHeader_not_set() { @Test void getServiceAccountKey_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String serviceAccountKey = cfg.getServiceAccountKey(); assertNull(serviceAccountKey); @@ -130,7 +124,7 @@ void getServiceAccountKey_not_set() { @Test void getServiceAccountKeyPath_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String serviceAccountKeyPath = cfg.getServiceAccountKeyPath(); assertNull(serviceAccountKeyPath); @@ -138,7 +132,7 @@ void getServiceAccountKeyPath_not_set() { @Test void getPrivateKeyPath_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String privateKeyPath = cfg.getPrivateKeyPath(); assertNull(privateKeyPath); @@ -146,7 +140,7 @@ void getPrivateKeyPath_not_set() { @Test void getPrivateKey_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String privateKey = cfg.getPrivateKey(); assertNull(privateKey); @@ -154,7 +148,7 @@ void getPrivateKey_not_set() { @Test void getCustomEndpoint_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String customEndpoint = cfg.getCustomEndpoint(); assertNull(customEndpoint); @@ -162,7 +156,7 @@ void getCustomEndpoint_not_set() { @Test void getCredentialsFilePath_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String credentialsFilePath = cfg.getCredentialsFilePath(); assertNull(credentialsFilePath); @@ -170,7 +164,7 @@ void getCredentialsFilePath_not_set() { @Test void getTokenCustomUrl_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); String tokenCustomUrl = cfg.getTokenCustomUrl(); assertNull(tokenCustomUrl); @@ -178,7 +172,7 @@ void getTokenCustomUrl_not_set() { @Test void getTokenExpirationLeeway_not_set() { - CoreConfiguration cfg = new CoreConfiguration.Builder().build(); + CoreConfiguration cfg = new CoreConfiguration(); Long tokenExpirationLeeway = cfg.getTokenExpirationLeeway(); assertNull(tokenExpirationLeeway); diff --git a/examples/authentication/src/main/java/cloud/stackit/sdk/authentication/examples/AuthenticationExample.java b/examples/authentication/src/main/java/cloud/stackit/sdk/authentication/examples/AuthenticationExample.java index cc10d65..95bcd8e 100644 --- a/examples/authentication/src/main/java/cloud/stackit/sdk/authentication/examples/AuthenticationExample.java +++ b/examples/authentication/src/main/java/cloud/stackit/sdk/authentication/examples/AuthenticationExample.java @@ -7,19 +7,17 @@ class AuthenticationExample { public static void main(String[] args) { String SERVICE_ACCOUNT_KEY_PATH = "/path/to/your/sa/key.json"; - String SERIVCE_ACCOUNT_MAIL = "name-1234@sa.stackit.cloud"; + String SERVICE_ACCOUNT_MAIL = "name-1234@sa.stackit.cloud"; CoreConfiguration config = - new CoreConfiguration.Builder() - .serviceAccountKeyPath(SERVICE_ACCOUNT_KEY_PATH) - .build(); + new CoreConfiguration().serviceAccountKeyPath(SERVICE_ACCOUNT_KEY_PATH); try { DefaultApi api = new DefaultApi(config); /* list all organizations */ ListOrganizationsResponse response = - api.listOrganizations(null, SERIVCE_ACCOUNT_MAIL, null, null, null); + api.listOrganizations(null, SERVICE_ACCOUNT_MAIL, null, null, null); System.out.println(response); } catch (Exception e) {