Skip to content

Commit 0c56030

Browse files
committed
Refactoring + new commands
1 parent c1044b7 commit 0c56030

24 files changed

+596
-514
lines changed

astra-sdk/src/main/java/com/datastax/astra/sdk/config/AstraClientConfig.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.datastax.astra.sdk.config;
22

3-
import static com.datastax.astra.sdk.utils.AstraRc.readRcVariable;
43
import static com.datastax.stargate.sdk.utils.Assert.hasLength;
5-
import static com.datastax.stargate.sdk.utils.Assert.notNull;
64
import static com.datastax.stargate.sdk.utils.Utils.readEnvVariable;
75

86
import java.io.File;
@@ -924,20 +922,21 @@ public AstraClientConfig() {
924922
stargateConfig = new StargateClientConfig();
925923

926924
// Loading ~/.astrarc section default if present
927-
if (AstraRc.exists()) {
928-
loadFromAstraRc(AstraRc.load(), AstraRc.ASTRARC_DEFAULT);
925+
if (AstraRc.isDefaultConfigFileExists()) {
926+
loadFromAstraRc();
929927
}
930928

931929
// Authentication
932930
readEnvVariable(ASTRA_DB_APPLICATION_TOKEN).ifPresent(this::withToken);
933931
readEnvVariable(ASTRA_DB_CLIENT_ID).ifPresent(this::withClientId);
934932
readEnvVariable(ASTRA_DB_CLIENT_SECRET).ifPresent(this::withClientSecret);
935-
readEnvVariable(ASTRA_DB_SCB_FOLDER).ifPresent(this::withCqlSecureConnectBundleFolder);
936933

937934
// Database
938935
readEnvVariable(ASTRA_DB_ID).ifPresent(this::withDatabaseId);
939936
readEnvVariable(ASTRA_DB_REGION).ifPresent(this::withDatabaseRegion);
940937
readEnvVariable(ASTRA_DB_KEYSPACE).ifPresent(this::withCqlKeyspace);
938+
readEnvVariable(ASTRA_DB_SCB_FOLDER).ifPresent(this::withCqlSecureConnectBundleFolder);
939+
941940
}
942941

943942
// ------------------------------------------------
@@ -947,20 +946,19 @@ public AstraClientConfig() {
947946
/**
948947
* Some settings can be loaded from ~/.astrarc in you machine.
949948
*
950-
* @param arc AstraRc
951-
* @param sectionName String
952949
* @return AstraClientBuilder
950+
* configuration
953951
*/
954-
public AstraClientConfig loadFromAstraRc(AstraRc arc, String sectionName) {
955-
notNull(arc, "AstraRc");
956-
hasLength(sectionName, "sectionName");
957-
readRcVariable(arc, ASTRA_DB_ID, sectionName).ifPresent(this::withDatabaseId);
958-
readRcVariable(arc, ASTRA_DB_REGION, sectionName).ifPresent(this::withDatabaseRegion);
959-
readRcVariable(arc, ASTRA_DB_APPLICATION_TOKEN, sectionName).ifPresent(this::withToken);
960-
readRcVariable(arc, ASTRA_DB_CLIENT_ID, sectionName).ifPresent(this::withClientId);
961-
readRcVariable(arc, ASTRA_DB_CLIENT_SECRET, sectionName).ifPresent(this::withClientSecret);
962-
readRcVariable(arc, ASTRA_DB_KEYSPACE, sectionName).ifPresent(this::withCqlKeyspace);
963-
readRcVariable(arc, ASTRA_DB_SCB_FOLDER, sectionName).ifPresent(this::withCqlSecureConnectBundleFolder);
952+
public AstraClientConfig loadFromAstraRc() {
953+
AstraRc arc = new AstraRc();
954+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_ID).ifPresent(this::withDatabaseId);
955+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_ID).ifPresent(this::withDatabaseId);
956+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_REGION).ifPresent(this::withDatabaseRegion);
957+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_APPLICATION_TOKEN).ifPresent(this::withToken);
958+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_CLIENT_ID).ifPresent(this::withClientId);
959+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_CLIENT_SECRET).ifPresent(this::withClientSecret);
960+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_KEYSPACE).ifPresent(this::withCqlKeyspace);
961+
arc.getSectionKey(AstraRc.ASTRARC_DEFAULT, ASTRA_DB_SCB_FOLDER).ifPresent(this::withCqlSecureConnectBundleFolder);
964962
return this;
965963
}
966964

@@ -972,11 +970,5 @@ public AstraClientConfig loadFromAstraRc(AstraRc arc, String sectionName) {
972970
public AstraClient build() {
973971
return new AstraClient(this);
974972
}
975-
976-
977-
978973

979-
980-
981-
982974
}

0 commit comments

Comments
 (0)