Developer SDKs

Sample code and integration instructions for the Secrets Manager SDK

Installation

Java
JavaScript
Python
.Net
GoLang
Java

Add the following dependency to your project:

  • core-16.0.0.jar

Other, non-Keeper dependencies needed:

  • org.jetbrains.kotlin:kotlin-stdlib-jdk8

  • org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1

  • org.bouncycastle:bc-fips:1.0.2.1

JavaScript

Coming Soon

Python

Coming Soon

.Net

Coming Soon

GoLang
import (
ksm "keepersecurity.com/keepercommandersm"
klog "keepersecurity.com/keepercommandersm/logger"
)

Authentication

The Secrets Manager SDK authenticates to the Keeper Vault using either the One Time Access Token or using the generated keys within the local configuration file. To generate a new One Time Access Token please follow the Setup Instructions page.

Initialization

Java
JavaScript
Python
.Net
GoLang
Java
import com.keepersecurity.secretsManager.core.*;
import static com.keepersecurity.secretsManager.core.SecretsManager.initializeStorage;
import static com.keepersecurity.secretsManager.core.SecretsManager.getSecrets;
import static com.keepersecurity.secretsManager.core.SecretsManager.updateSecret;
import static com.keepersecurity.secretsManager.core.SecretsManager.downloadFile;
import static com.keepersecurity.secretsManager.core.SecretsManager.getRecordField;
import static com.keepersecurity.secretsManager.core.SecretsManager.updateRecordField;
import java.io.FileOutputStream;
...
// oneTimeToken is used only once to initialize the storage
// after the first run, subsequent calls will use config.txt
String oneTimeToken = "EvdTdbH1xbHuRcja7QG3wMOyLUbvoQgF9WkkrHTdkh8";
KeyValueStorage storage = new LocalConfigStorage("config.txt");
try {
initializeStorage(storage, oneTimeToken, "keepersecurity.com");
SecretsManagerOptions options = new SecretsManagerOptions(storage);
KeeperSecrets secrets = getSecrets(options);
System.out.println(secrets.getRecords());
// get the password from the first record
KeeperRecord firstRecord = secrets.getRecords().get(0);
String firstRecordPassword = getRecordField(firstRecord, "password");
System.out.println(firstRecordPassword);
} catch (Exception e) {
System.out.println(e.getMessage());
}
JavaScript
Coming Soon
Python
Coming Soon
.Net
Coming Soon
GoLang
package main
import (
"fmt"
"time"
ksm "keepersecurity.com/keepercommandersm"
klog "keepersecurity.com/keepercommandersm/logger"
)
func main() {
klog.SetLogLevel(klog.DebugLevel)
server := "https://keepersecurity.com"
clientKey := "EvdTdbH1xbHuRcja7QG3wMOyLUbvoQgF9WkkrHTdkh8"
c := ksm.NewCommanderFromSettings(clientKey, server, verifySslCerts)
if allRecords, err := c.GetSecrets([]string{}); err == nil {
for _, r := range allRecords {
klog.Println("\tPassword: " + r.Password())
}
} else {
klog.Error("error retrieving all records: " + err.Error())
}
}

Retrieve All Secrets

Java
JavaScript
Python
.Net
GoLang
Java
KeeperSecrets secrets = getSecrets(options);
List<KeeperRecord> records = secrets.getRecords();
JavaScript
Coming Soon
Python
Coming Soon
.Net
Coming Soon
GoLang
allRecords, err := c.GetSecrets([]string{})

Retrieve Individual Secret

Java
JavaScript
Python
.Net
GoLang
Java
KeeperSecrets secrets = getSecrets(options, Arrays.asList("UlzQ-jKQTgQcEvpJI9vxxQ"));
List<KeeperRecord> records = secrets.getRecords();
JavaScript
Coming Soon
Python
Coming Soon
.Net
Coming Soon
GoLang
record, err := c.GetSecrets([]string{"UlzQ-jKQTgQcEvpJI9vxxQ"}

Download a File Attachment

Java
JavaScript
Python
.Net
GoLang
Java
// download the first file from the first record
KeeperFile file = secrets.getRecords().get(0).getFiles().get(0);
byte[] fileBytes = downloadFile(file);
try (FileOutputStream fos = new FileOutputStream(file.getData().getName())) {
fos.write(fileBytes);
}
JavaScript
Coming Soon
Python
Coming Soon
.Net
Coming Soon
GoLang
allRecords, err := c.GetSecrets([]string{})
record := allRecords[0]
file := record.Files[0]
f.SaveFile("/tmp/"+f.Name, true)

Update a Secret

Java
JavaScript
Python
.Net
GoLang
Java
// update the password on the first record
updateRecordField(firstRecord, "password", "aP1$t367QOCvL$eM$bG#");
updateSecret(options, firstRecord);
JavaScript
Coming Soon
Python
secret = Commander.get_secrets(['uid1'])[0]
secret.password = 'NewPassword123$'
Commander.save(secret)
.Net
Coming Soon
GoLang
allRecords, err := c.GetSecrets([]string{})
record := allRecords[0]
record.SetPassword("aP1$t367QOCvL$eM$bG#")

Script Integration

Keeper Secrets Manager CLI provides a wrapper function that executes any arbitrary system call and replaces environmental variables with values from the Keeper Vault.

Secrets Manager CLI Exec Command

.Net Vault SDK

Keeper also provides a .Net based Commander tool with a developer SDK for basic vault access and administrative functions that are outside of the scope of Secrets Manager:

https://github.com/Keeper-Security/keeper-sdk-dotnet

PowerShell CLI

Keeper's PowerShell command-line tool (PowerCommander) provides basic vault access and administrative functions:

https://github.com/Keeper-Security/keeper-sdk-dotnet/tree/release/PowerCommander For more advanced command line capabilities, please refer to the Python-based Commander CLI.