Skip to content

Commit

Permalink
[logging] Do not print secrets while opening a connection to the Vect…
Browse files Browse the repository at this point in the history
…or database (#446)
  • Loading branch information
eolivelli authored Sep 20, 2023
1 parent e654304 commit 3ae4604
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/applications/webcrawler-source/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pipeline:
messages:
- role: system
content: |
An user is going to perform a questions, he documents below may help you in answering to their questions.
An user is going to perform a questions, The documents below may help you in answering to their questions.
Please try to leverage them in your answer as much as possible.
Take into consideration that the user is always asking questions about the LangStream project.
If you provide code or YAML snippets, please explicitly state that they are examples.
Expand Down
4 changes: 2 additions & 2 deletions examples/applications/webcrawler-source/crawler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pipeline:
reindex-interval-seconds: 3600
max-error-count: 5
max-urls: 1000
max-depth: 10
max-depth: 50
handle-robots-file: true
user-agent: "" # this is computed automatically, but you can override it
scan-html-documents: true
Expand All @@ -53,7 +53,7 @@ pipeline:
- name: "Detect language"
type: "language-detector"
configuration:
allowedLanguages: ["en"]
allowedLanguages: ["en", "fr"]
property: "language"
- name: "Split into chunks"
type: "text-splitter"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ protected TypeCodec<?> createCodec(

@Override
public void initialize(Map<String, Object> dataSourceConfig) {
log.info("Initializing AstraDBDataSource with config {}", dataSourceConfig);
log.info(
"Initializing CassandraDataSource with config {}",
ConfigurationUtils.redactSecrets(dataSourceConfig));
this.astraToken = ConfigurationUtils.getString("token", "", dataSourceConfig);
this.astraEnvironment =
ConfigurationUtils.getString("environment", "PROD", dataSourceConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package ai.langstream.api.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -252,4 +254,49 @@ public static void requiredListField(
"Expecting a list in the field '" + name + "' in " + definition.get());
}
}

/**
* Remove all the secrets from the configuration. This method is used to avoid logging secrets
*
* @param object
* @return the object without secrets
*/
public static Object redactSecrets(Object object) {
if (object == null) {
return null;
}

if (object instanceof List list) {
List<Object> other = new ArrayList<>(list.size());
list.forEach(o -> other.add(redactSecrets(o)));
return other;
}
if (object instanceof Set set) {
Set<Object> other = new HashSet<>(set.size());
set.forEach(o -> other.add(redactSecrets(o)));
return other;
}

if (object instanceof Map map) {
Map<Object, Object> other = new HashMap<>();
map.forEach(
(k, v) -> {
String keyLowercase = (String.valueOf(k)).toLowerCase();
if (keyLowercase.contains("password")
|| keyLowercase.contains("pwd")
|| keyLowercase.contains("secure")
|| keyLowercase.contains("secret")
|| keyLowercase.contains("serviceaccountjson")
|| keyLowercase.contains("access-key")
|| keyLowercase.contains("token")) {
other.put(k, "<REDACTED>");
} else {
other.put(k, redactSecrets(v));
}
});
return other;
}

return object;
}
}

0 comments on commit 3ae4604

Please sign in to comment.