1
1
package com .datastax .astra .sdk .config ;
2
2
3
- import static com .datastax .astra .sdk .utils .AstraRc .readRcVariable ;
4
3
import static com .datastax .stargate .sdk .utils .Assert .hasLength ;
5
- import static com .datastax .stargate .sdk .utils .Assert .notNull ;
6
4
import static com .datastax .stargate .sdk .utils .Utils .readEnvVariable ;
7
5
8
6
import java .io .File ;
@@ -924,20 +922,21 @@ public AstraClientConfig() {
924
922
stargateConfig = new StargateClientConfig ();
925
923
926
924
// Loading ~/.astrarc section default if present
927
- if (AstraRc .exists ()) {
928
- loadFromAstraRc (AstraRc . load (), AstraRc . ASTRARC_DEFAULT );
925
+ if (AstraRc .isDefaultConfigFileExists ()) {
926
+ loadFromAstraRc ();
929
927
}
930
928
931
929
// Authentication
932
930
readEnvVariable (ASTRA_DB_APPLICATION_TOKEN ).ifPresent (this ::withToken );
933
931
readEnvVariable (ASTRA_DB_CLIENT_ID ).ifPresent (this ::withClientId );
934
932
readEnvVariable (ASTRA_DB_CLIENT_SECRET ).ifPresent (this ::withClientSecret );
935
- readEnvVariable (ASTRA_DB_SCB_FOLDER ).ifPresent (this ::withCqlSecureConnectBundleFolder );
936
933
937
934
// Database
938
935
readEnvVariable (ASTRA_DB_ID ).ifPresent (this ::withDatabaseId );
939
936
readEnvVariable (ASTRA_DB_REGION ).ifPresent (this ::withDatabaseRegion );
940
937
readEnvVariable (ASTRA_DB_KEYSPACE ).ifPresent (this ::withCqlKeyspace );
938
+ readEnvVariable (ASTRA_DB_SCB_FOLDER ).ifPresent (this ::withCqlSecureConnectBundleFolder );
939
+
941
940
}
942
941
943
942
// ------------------------------------------------
@@ -947,20 +946,19 @@ public AstraClientConfig() {
947
946
/**
948
947
* Some settings can be loaded from ~/.astrarc in you machine.
949
948
*
950
- * @param arc AstraRc
951
- * @param sectionName String
952
949
* @return AstraClientBuilder
950
+ * configuration
953
951
*/
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 );
964
962
return this ;
965
963
}
966
964
@@ -972,11 +970,5 @@ public AstraClientConfig loadFromAstraRc(AstraRc arc, String sectionName) {
972
970
public AstraClient build () {
973
971
return new AstraClient (this );
974
972
}
975
-
976
-
977
-
978
973
979
-
980
-
981
-
982
974
}
0 commit comments