Secrets
Get, list, create, update and delete secrets.
Using the environment client SDK, you can also interact directly with the secrets.
Get
Get single secret by its name.
Parameters
This takes two paramters.
Prop
Type
Example
const { data, error } = await stashbase.secrets.get('DATABASE_URL', true)
// check for error
if (error) {
// handle error
} else {
// do something with the data
}Get metadata
Get operational metadata for a single secret by name.
Parameters
This method takes one parameter.
Prop
Type
Example
const { data, error } = await stashbase.secrets.getMetadata('DATABASE_URL')
if (error) {
// handle error
} else {
// do something with the metadata
console.log(data)
}List
List all secrets in the selected environment.
Parameters
This method takes single optional object parameter.
Prop
Type
Options
An object with the following properties:
Prop
Type
Example
const { data, error } = await stashbase.secrets.list({ expandRefs: true })
// check for error
if (error) {
// handle error
} else {
// do something with the data
}List metadata
List operational metadata for all visible secrets in the selected environment.
Parameters
This method does not take parameters.
Example
const { data, error } = await stashbase.secrets.listMetadata()
if (error) {
// handle error
} else {
// do something with the metadata list
console.log(data)
}List only
List only selected secrets.
Parameters
This method takes two parameters.
Prop
Type
Options
An object with the following properties:
Prop
Type
Example
const { data, error } = await stashbase.secrets.listExclude(['DATABASE_USER', 'DATABASE_PASSWORD'])
// check for error
if (error) {
// handle error
} else {
// do something with the data
}List exclude
List all secrets in the selected environment except the selected ones.
Parameters
This method takes object parameter with the following properties:
Prop
Type
Options
An object with the following properties:
Prop
Type
Example
const { data, error } = await stashbase.secrets.listOnly(['DATABASE_USER', 'DATABASE_PASSWORD'])
// check for error
if (error) {
// handle error
} else {
// do something with the data
}Create
With this method you can easily create new secrets in the selected environment.
The data proprety returns createdCount and duplicateSecrets array of strings.
Parameters
This method takes a single array parameter:
Prop
Type
Data
An array of objects CreateSecretsItem containing the following properties:
Prop
Type
Example
const { data, error } = await stashbase.secrets.create([
{
name: 'NAME',
value: 'Some value',
comment: 'This is comment for this secret.',
},
{ name: 'NAME_2', value: 'Some value 2' },
])
// check for error
if (error) {
// handle error
} else {
// do something with the data
console.log(data.createdCount)
console.log(data.duplicateSecrets)
}Set
With this method you can easily set secrets.
One key differnet from the create method is the fact that this method will create the secret if it does not exist or update if it exists.
The data proprety returnes createdCount and updatedCount propreties.
Parameters
This method takes a single array parameter:
Prop
Type
Data
An array of objects SetSecretsItem containing the following properties:
Prop
Type
Example
const { error } = await stashbase.secrets.set([
{
name: 'API_URL',
value: 'https://api.example.com',
},
{
name: 'DATABASE_URL',
value: 'postgres://user:password@localhost:5432/dbname',
},
])
// check for error
if (error) {
// handle error
} else {
// ok
}Update
Update existing secrets.
The data proprety returns updatedCount and notFoundSecrets array of strings.
Parameters
This method takes a single array parameter:
Prop
Type
Data
An array of objects UpdateSecretsItem where name is the currrent name of the secret to update and at least one of the additional properties is required:
Prop
Type
Example
const { data, error } = await envApi.secrets.update([
{
name: 'APP_URL',
comment: 'New comment',
value: 'https://api.example.com',
newName: 'NEW_KEY',
},
])Delete
Delete existing secrets.
The data proprety returns deletedCount and notFoundsecrets array of strings.
Parameters
This method takes a single array parameter:
Prop
Type
Example
const { data, error } = await stashbase.secrets.delete(['DATABASE_URL', 'STRIPE_API_KEY'])
// check for error
if (error) {
// handle error
} else {
// ok
console.log(data.deletedCount)
console.log(data.notFoundSecrets)
}Delete all
Delete all secrets in the environment
The data proprety returns object with property deletedCount (number).
Parameters
This method takes no parameters.
Example
const { data, error } = await stashbase.secrets.deleteAll()
// check for error
if (error) {
// handle error
} else {
// ok
console.log(data.deletedCount)
}