diff --git a/adapter-pinecone/pom.xml b/adapter-pinecone/pom.xml index 73d8a5014..91ae70b94 100644 --- a/adapter-pinecone/pom.xml +++ b/adapter-pinecone/pom.xml @@ -49,7 +49,7 @@ io.pinecone pinecone-client - 0.2.3 + 0.7.4 diff --git a/adapter-pinecone/src/main/java/io/nosqlbench/adapter/pinecone/PineconeSpace.java b/adapter-pinecone/src/main/java/io/nosqlbench/adapter/pinecone/PineconeSpace.java index cfa6430f1..55f74281b 100644 --- a/adapter-pinecone/src/main/java/io/nosqlbench/adapter/pinecone/PineconeSpace.java +++ b/adapter-pinecone/src/main/java/io/nosqlbench/adapter/pinecone/PineconeSpace.java @@ -27,13 +27,19 @@ import io.pinecone.PineconeConnectionConfig; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class PineconeSpace { private final static Logger logger = LogManager.getLogger(PineconeSpace.class); private final String apiKey; + private final String apiKeyFile; private final String environment; private final String projectName; private final String name; @@ -51,7 +57,23 @@ public class PineconeSpace { * @param cfg The configuration ({@link NBConfiguration}) for this nb run */ public PineconeSpace(String name, NBConfiguration cfg) { - this.apiKey = cfg.get("apiKey"); + String apiKeyFromFile = null; + this.apiKeyFile = cfg.get("apiKeyFile"); + if(null != this.apiKeyFile && this.apiKeyFile.length() > 0) { + Optional apiKeyFileOpt = cfg.getOptional("apiKeyFile"); + if(apiKeyFileOpt.isPresent()) { + Path path = Paths.get(apiKeyFileOpt.get()); + try { + apiKeyFromFile = Files.readAllLines(path).getFirst(); + } catch (IOException e) { + String error = "Error while reading api key from file:" + path; + logger.error(error, e); + throw new RuntimeException(e); + } + } + } + + this.apiKey = (apiKeyFromFile != null) ? apiKeyFromFile : cfg.get("apiKey"); this.environment = cfg.get("environment"); this.projectName = cfg.get("projectName"); this.name = name; @@ -59,7 +81,7 @@ public class PineconeSpace { .withApiKey(apiKey) .withEnvironment(environment) .withProjectName(projectName); - logger.info(this.name + ": Creating new Pinecone Client with api key " + apiKey + ", environment " + logger.info(this.name + ": Creating new Pinecone Client with api key " + maskDigits(apiKey) + ", environment " + environment + " and project name " + projectName); this.client = new PineconeClient(config); } @@ -86,7 +108,10 @@ public class PineconeSpace { return ConfigModel.of(PineconeSpace.class) .add( - Param.required("apiKey",String.class) + Param.optional("apiKeyFile", String.class, "file to load the api key from") + ) + .add( + Param.optional("apiKey",String.class) .setDescription("the Pinecone API key to use to connect to the database") ) .add( @@ -100,4 +125,17 @@ public class PineconeSpace { .asReadOnly(); } + private static String maskDigits(String unmasked) { + int inputLength = (null == unmasked) ? 0 : unmasked.length(); + StringBuilder masked = new StringBuilder(inputLength); + for(char ch : unmasked.toCharArray()) { + if (Character.isDigit(ch)) { + masked.append("*"); + } else { + masked.append(ch); + } + } + return masked.toString(); + } + } diff --git a/adapter-pinecone/src/main/resources/pinecone.md b/adapter-pinecone/src/main/resources/pinecone.md index 1b56af9ad..766516c97 100644 --- a/adapter-pinecone/src/main/resources/pinecone.md +++ b/adapter-pinecone/src/main/resources/pinecone.md @@ -7,8 +7,8 @@ https://github.com/pinecone-io/pinecone-java-client The following parameters must be supplied to the adapter at runtime in order to successfully connect to an instance of the Pinecone database: -* api key - In order to use the pinecone database you must have an account. Once the account is created you can request - an api key. This key will need to be provided any time a database connection is desired. +* api key - In order to use the pinecone database you must have an account. Once the account is created you can [request + an api key](https://docs.pinecone.io/docs/quickstart#2-get-your-api-key). This key will need to be provided any time a database connection is desired. * environment - When an Index is created in the database the environment must be specified as well. The adapter will use the default value of us-east-1 if none is provided at runtime. * project name - A project name must also be provided at time of index creation. This name then needs to be provided