Skip to content

Commit

Permalink
[astra] Rework all the examples to not ask clientId/secret
Browse files Browse the repository at this point in the history
  • Loading branch information
eolivelli committed Nov 20, 2023
1 parent 52b0ce8 commit 9487d6a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 21 deletions.
2 changes: 0 additions & 2 deletions examples/applications/astradb-sink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Export some ENV variables in order to configure access to the database:

```
export ASTRA_TOKEN=...
export ASTRA_CLIENT_ID=...
export ASTRA_SECRET=...
export ASTRA_DATABASE=...
```

Expand Down
4 changes: 2 additions & 2 deletions examples/applications/astradb-sink/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ configuration:
name: "AstraDatasource"
configuration:
service: "astra"
clientId: "${ secrets.astra.clientId }"
secret: "${ secrets.astra.secret }"
clientId: "token"
secret: "${ secrets.astra.token }"
token: "${ secrets.astra.token }"
database: "${ secrets.astra.database }"
environment: "${ secrets.astra.environment }"
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ configuration:
name: "AstraDatasource"
configuration:
service: "astra"
clientId: "{{secrets.astra-langchain.clientId}}"
secret: "{{secrets.astra-langchain.secret}}"
clientId: "token"
secret: "{{secrets.astra-langchain.token}}"
database: "{{secrets.astra-langchain.database}}"
database-id: "{{secrets.astra-langchain.database-id}}"
token: "{{secrets.astra-langchain.token}}"
Expand Down
8 changes: 4 additions & 4 deletions examples/applications/chatbot-rag-memory/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ configuration:
name: "AstraDatasource"
configuration:
service: "astra"
clientId: "${secrets.astra.clientId}"
secret: "${secrets.astra.secret}"
clientId: "token"
secret: "${ secrets.astra.token }"
token: "${secrets.astra.token}"
database: "${secrets.astra.database}"
environment: "${secrets.astra.environment}"
- type: "vector-database"
name: "AstraVector"
configuration:
service: "astra"
clientId: "${secrets.astra.clientId}"
secret: "${secrets.astra.secret}"
clientId: "token"
secret: "${ secrets.astra.token }"
token: "${secrets.astra.token}"
database: "${secrets.astra.database}"
environment: "${secrets.astra.environment}"
4 changes: 2 additions & 2 deletions examples/applications/langchain-chat/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ configuration:
name: "AstraDatasource"
configuration:
service: "astra"
clientId: "${secrets.astra-langchain.clientId}"
secret: "${secrets.astra-langchain.secret}"
clientId: "token"
secret: "${ secrets.astra-langchain.token }"
database: "${secrets.astra-langchain.database}"
database-id: "${secrets.astra-langchain.database-id}"
token: "${secrets.astra-langchain.token}"
Expand Down
4 changes: 2 additions & 2 deletions examples/applications/query-astradb/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ configuration:
name: "AstraDatasource"
configuration:
service: "astra"
clientId: "${ secrets.astra.clientId }"
secret: "${ secrets.astra.secret }"
clientId: "token"
secret: "${ secrets.astra.token }"
secureBundle: "${ secrets.astra.secureBundle }"
database: "${ secrets.astra.database }"
token: "${ secrets.astra.token }"
Expand Down
4 changes: 2 additions & 2 deletions examples/applications/webcrawler-source/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ configuration:
name: "AstraDatasource"
configuration:
service: "astra"
clientId: "${secrets.astra.clientId}"
secret: "${secrets.astra.secret}"
clientId: "token"
secret: "${secrets.astra.token}"
secureBundle: "${secrets.astra.secureBundle}"
database: "${secrets.astra.database}"
token: "${secrets.astra.token}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,21 @@ private CqlSession buildCqlSession(Map<String, Object> dataSourceConfig) {
if (password == null) {
password = ConfigurationUtils.getString("secret", null, dataSourceConfig);
}

// in AstraDB you can use "token" as clientId and the AstraCS token as password
if (username == null && astraToken != null && !astraToken.isEmpty()) {
username = "token";
}
if (password == null) {
password = astraToken;
}

String secureBundle = ConfigurationUtils.getString("secureBundle", "", dataSourceConfig);
List<String> contactPoints = ConfigurationUtils.getList("contact-points", dataSourceConfig);
String loadBalancingLocalDc =
ConfigurationUtils.getString("loadBalancing-localDc", "", dataSourceConfig);
int port = ConfigurationUtils.getInteger("port", 9042, dataSourceConfig);
log.info("Username/ClientId: {}", username);
log.info("Contact points: {}", contactPoints);
log.info("Secure Bundle: {}", secureBundle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public void initialise(Map<String, Object> agentConfiguration) {
ConfigurationUtils.getString(
"port", "9042", datasource));

String token =
ConfigurationUtils.getString("token", "", datasource);
String secureBundleString =
ConfigurationUtils.getString(
"secureBundle", "", datasource);
Expand All @@ -107,9 +109,7 @@ public void initialise(Map<String, Object> agentConfiguration) {
"cloud.secureConnectBundle", secureBundleString);
} else {
// AstraDB, token/database/databaseId
String token =
ConfigurationUtils.getString(
"token", "", datasource);

String database =
ConfigurationUtils.getString(
"database", "", datasource);
Expand Down Expand Up @@ -145,14 +145,14 @@ public void initialise(Map<String, Object> agentConfiguration) {
ConfigurationUtils.getString(
"username",
ConfigurationUtils.getString(
"clientId", "", datasource),
"clientId", "token", datasource),
datasource));
configuration.put(
"auth.password",
ConfigurationUtils.getString(
"password",
ConfigurationUtils.getString(
"secret", "", datasource),
"secret", token, datasource),
datasource));

break;
Expand Down

0 comments on commit 9487d6a

Please sign in to comment.