mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Finish Python SDK docs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
---
|
||||
title: "Node"
|
||||
icon: "node"
|
||||
---
|
||||
|
||||
If you're working with Node.js, the official [infisical-node](https://github.com/Infisical/infisical-node) package is the easiest way to fetch and work with secrets for your application.
|
||||
@@ -7,8 +8,8 @@ If you're working with Node.js, the official [infisical-node](https://github.com
|
||||
## Basic Usage
|
||||
|
||||
```js
|
||||
import InfisicalClient from "infisical-node";
|
||||
import express from "express";
|
||||
import InfisicalClient from "infisical-node";
|
||||
const app = express();
|
||||
const PORT = 3000;
|
||||
|
||||
@@ -40,8 +41,8 @@ This example demonstrates how to use the Infisical SDK with an Express applicati
|
||||
|
||||
Run `npm` to add `infisical-node` to your project.
|
||||
|
||||
```bash
|
||||
npm install infisical-node --save
|
||||
```console
|
||||
$ npm install infisical-node --save
|
||||
```
|
||||
|
||||
## Configuration
|
||||
@@ -75,39 +76,54 @@ Import the SDK and create a client instance with your Infisical token.
|
||||
|
||||
</Tabs>
|
||||
|
||||
<ResponseField name="options" type="object">
|
||||
### Parameters
|
||||
|
||||
<ParamField query="options" type="object">
|
||||
<Expandable title="properties">
|
||||
<ResponseField name="token" type="string">
|
||||
<ParamField query="token" type="string" optional>
|
||||
An [Infisical Token](/getting-started/dashboard/token) scoped to a project
|
||||
and environment
|
||||
</ResponseField>
|
||||
<ResponseField
|
||||
name="siteURL"
|
||||
</ParamField>
|
||||
<ParamField
|
||||
query="siteURL"
|
||||
type="string"
|
||||
default="https://app.infisical.com"
|
||||
optional
|
||||
>
|
||||
Your self-hosted absolute site URL including the protocol (e.g.
|
||||
`https://app.infisical.com`)
|
||||
</ResponseField>
|
||||
<ResponseField name="cacheTTL" type="number" default="300">
|
||||
</ParamField>
|
||||
<ParamField query="cacheTTL" type="number" default="300" optional>
|
||||
Time-to-live (in seconds) for refreshing cached secrets. Default: `300`.
|
||||
</ResponseField>
|
||||
<ResponseField name="debug" type="boolean" default="false">
|
||||
</ParamField>
|
||||
<ParamField query="debug" type="boolean" default="false" optional>
|
||||
Whether or not debug mode is on
|
||||
</ResponseField>
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
</ParamField>
|
||||
|
||||
## Caching
|
||||
|
||||
The SDK caches every secret and updates it periodically based on the provided `cacheTTL`. For example, if `cacheTTL` of `300` is provided, then a secret will be refetched 5 minutes after the first fetch; if the fetch fails, the cached secret is returned.
|
||||
|
||||
<Tip>
|
||||
For optimal performance, we recommend creating a single instance of the Infisical client and exporting it to be used across your entire app to take advantage of caching benefits.
|
||||
</Tip>
|
||||
|
||||
## Working with Secrets
|
||||
|
||||
### infisical.getSecret(secretName, options)
|
||||
### client.getAllSecrets()
|
||||
|
||||
```js
|
||||
const secret = await infisical.getSecret("API_KEY");
|
||||
const secrets = await client.getAllSecrets();
|
||||
```
|
||||
|
||||
Retrieve all secrets within the Infisical project and environment that client is connected to
|
||||
|
||||
### client.getSecret(secretName, options)
|
||||
|
||||
```js
|
||||
const secret = await client.getSecret("API_KEY");
|
||||
const value = secret.secretValue; // get its value
|
||||
```
|
||||
|
||||
@@ -115,79 +131,82 @@ Retrieve a secret from Infisical.
|
||||
|
||||
By default, `getSecret()` fetches and returns a personal secret. If not found, it returns a shared secret, or tries to retrieve the value from `process.env`. If a secret is fetched, `getSecret()` caches it to reduce excessive calls and re-fetches periodically based on the `cacheTTL` option (default is `300` seconds) when initializing the client — for more information, see the caching section.
|
||||
|
||||
### Parameters
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
<ParamField query="secretName" type="string" required>
|
||||
The key of the secret to retrieve
|
||||
</ResponseField>
|
||||
<ResponseField name="options" type="object">
|
||||
</ParamField>
|
||||
<ParamField query="options" type="object" optional>
|
||||
<Expandable title="properties">
|
||||
<ResponseField name="type" type="string">
|
||||
"personal" (default) or "shared".
|
||||
</ResponseField>
|
||||
<ParamField query="type" type="string" default="personal" optional>
|
||||
The type of the secret. Valid options are "shared" or "personal"
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
</ParamField>
|
||||
|
||||
### infisical.createSecret(secretName, secretValue, options)
|
||||
### client.createSecret(secretName, secretValue, options)
|
||||
|
||||
```js
|
||||
const newApiKey = await infisical.createSecret("API_KEY", "FOO");
|
||||
const newApiKey = await client.createSecret("API_KEY", "FOO");
|
||||
```
|
||||
|
||||
Create a new secret in Infisical.
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
<ParamField query="secretName" type="string" required>
|
||||
The key of the secret to create
|
||||
</ResponseField>
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
</ParamField>
|
||||
<ParamField query="secretName" type="string" required>
|
||||
The value of the secret to create
|
||||
</ResponseField>
|
||||
<ResponseField name="options" type="object">
|
||||
</ParamField>
|
||||
<ParamField query="options" type="object" default="object" optional>
|
||||
<Expandable title="properties">
|
||||
<ResponseField name="type" type="string">
|
||||
"shared" (default) or "personal". A personal secret can only be created if a shared secret with the same name exists.
|
||||
</ResponseField>
|
||||
<ParamField query="type" type="string" default="shared" optional>
|
||||
The type of the secret. Valid options are "shared" or "personal". A personal secret can only be created if a shared secret with the same name exists.
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
</ParamField>
|
||||
|
||||
### infisical.updateSecret(secretName, secretValue, options)
|
||||
### client.updateSecret(secretName, secretValue, options)
|
||||
|
||||
```js
|
||||
const updatedApiKey = await infisical.updateSecret("API_KEY", "BAR");
|
||||
const updatedApiKey = await client.updateSecret("API_KEY", "BAR");
|
||||
```
|
||||
|
||||
Update an existing secret in Infisical.
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
The key of the secret to update
|
||||
</ResponseField>
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
The new value of the secret
|
||||
</ResponseField>
|
||||
<ResponseField name="options" type="object">
|
||||
<Expandable title="properties">
|
||||
<ResponseField name="type" type="string">
|
||||
"shared" (default) or "personal".
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
### Parameters
|
||||
|
||||
### infisical.deleteSecret(secretName, options)
|
||||
<ParamField query="secretName" type="string" required>
|
||||
The key of the secret to update
|
||||
</ParamField>
|
||||
<ParamField query="secretName" type="string" required>
|
||||
The new value of the secret
|
||||
</ParamField>
|
||||
<ParamField query="options" type="object" default="object" optional>
|
||||
<Expandable title="properties">
|
||||
<ParamField query="type" type="string" default="shared" optional>
|
||||
The type of the secret. Valid options are "shared" or "personal"
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
</ParamField>
|
||||
|
||||
### client.deleteSecret(secretName, options)
|
||||
|
||||
```js
|
||||
const deletedSecret = await infisical.deleteSecret("API_KEY");
|
||||
const deletedSecret = await client.deleteSecret("API_KEY");
|
||||
```
|
||||
|
||||
Delete a secret in Infisical.
|
||||
|
||||
<ResponseField name="secretName" type="string" required>
|
||||
<ParamField query="secretName" type="string" required>
|
||||
The key of the secret to delete
|
||||
</ResponseField>
|
||||
<ResponseField name="options" type="object">
|
||||
</ParamField>
|
||||
<ParamField query="options" type="object" default="object" optional>
|
||||
<Expandable title="properties">
|
||||
<ResponseField name="type" type="string">
|
||||
"shared" (default) or "personal". Note that deleting a shared secret also deletes all associated personal secrets.
|
||||
</ResponseField>
|
||||
<ParamField query="type" type="string" default="shared" optional>
|
||||
The type of the secret. Valid options are "shared" or "personal". Note that deleting a shared secret also deletes all associated personal secrets.
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
</ResponseField>
|
||||
</ParamField>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user