docs: updated docs to reflect new SDK structure

This commit is contained in:
Daniel Hougaard
2024-05-23 04:45:33 +02:00
parent 663f8abc51
commit 3d65d121c0
6 changed files with 657 additions and 172 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ Initialize a new Node.js project with a default `package.json` file.
npm init -y npm init -y
``` ```
Install `express` and [infisical-node](https://github.com/Infisical/infisical-node), the client Node SDK for Infisical. Install `express` and [@infisical/sdk](https://www.npmjs.com/package/@infisical/sdk), the client Node SDK for Infisical.
```console ```console
npm install express @infisical/sdk npm install express @infisical/sdk
+10 -6
View File
@@ -5,7 +5,7 @@ title: "Python"
This guide demonstrates how to use Infisical to manage secrets for your Python stack from local development to production. It uses: This guide demonstrates how to use Infisical to manage secrets for your Python stack from local development to production. It uses:
- Infisical (you can use [Infisical Cloud](https://app.infisical.com) or a [self-hosted instance of Infisical](https://infisical.com/docs/self-hosting/overview)) to store your secrets. - Infisical (you can use [Infisical Cloud](https://app.infisical.com) or a [self-hosted instance of Infisical](https://infisical.com/docs/self-hosting/overview)) to store your secrets.
- The [infisical-python](https://github.com/Infisical/sdk/tree/main/crates/infisical-py) Python client SDK to fetch secrets back to your Python application on demand. - The [infisical-python](https://pypi.org/project/infisical-python/) Python client SDK to fetch secrets back to your Python application on demand.
## Project Setup ## Project Setup
@@ -36,23 +36,27 @@ python3 -m venv env
source env/bin/activate source env/bin/activate
``` ```
Install Flask and [infisical-python](https://github.com/Infisical/sdk/tree/main/crates/infisical-py), the client Python SDK for Infisical. Install Flask and [infisical-python](https://pypi.org/project/infisical-python/), the client Python SDK for Infisical.
```console ```console
pip install Flask infisical-python pip install flask infisical-python
``` ```
Finally, create an `app.py` file containing the application code. Finally, create an `app.py` file containing the application code.
```py ```py
from flask import Flask from flask import Flask
from infisical_client import ClientSettings, InfisicalClient, GetSecretOptions from infisical_client import ClientSettings, InfisicalClient, GetSecretOptions, AuthenticationOptions, UniversalAuthMethod
app = Flask(__name__) app = Flask(__name__)
client = InfisicalClient(ClientSettings( client = InfisicalClient(ClientSettings(
client_id="MACHINE_IDENTITY_CLIENT_ID", auth=AuthenticationOptions(
client_secret="MACHINE_IDENTITY_CLIENT_SECRET", universal_auth=UniversalAuthMethod(
client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
)
)
)) ))
@app.route("/") @app.route("/")
+146 -20
View File
@@ -21,21 +21,28 @@ namespace Example
static void Main(string[] args) static void Main(string[] args)
{ {
var settings = new ClientSettings ClientSettings settings = new ClientSettings
{
Auth = new AuthenticationOptions
{ {
ClientId = "CLIENT_ID", UniversalAuth = new UniversalAuthMethod
ClientSecret = "CLIENT_SECRET", {
// SiteUrl = "http://localhost:8080", <-- This line can be omitted if you're using Infisical Cloud. ClientId = "your-client-id",
}; ClientSecret = "your-client-secret"
var infisical = new InfisicalClient(settings); }
}
};
var options = new GetSecretOptions
var infisicalClient = new InfisicalClient(settings);
var getSecretOptions = new GetSecretOptions
{ {
SecretName = "TEST", SecretName = "TEST",
ProjectId = "PROJECT_ID", ProjectId = "PROJECT_ID",
Environment = "dev", Environment = "dev",
}; };
var secret = infisical.GetSecret(options); var secret = infisical.GetSecret(getSecretOptions);
Console.WriteLine($"The value of secret '{secret.SecretKey}', is: {secret.SecretValue}"); Console.WriteLine($"The value of secret '{secret.SecretKey}', is: {secret.SecretValue}");
@@ -52,8 +59,6 @@ This example demonstrates how to use the Infisical C# SDK in a C# application. T
# Installation # Installation
Run `npm` to add `@infisical/sdk` to your project.
```console ```console
$ dotnet add package Infisical.Sdk $ dotnet add package Infisical.Sdk
``` ```
@@ -70,14 +75,20 @@ namespace Example
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
ClientSettings settings = new ClientSettings
var settings = new ClientSettings {
Auth = new AuthenticationOptions
{ {
ClientId = "CLIENT_ID", UniversalAuth = new UniversalAuthMethod
ClientSecret = "CLIENT_SECRET", {
}; ClientId = "your-client-id",
ClientSecret = "your-client-secret"
}
}
};
var infisical = new InfisicalClient(settings); // <-- Your SDK instance!
var infisicalClient = new InfisicalClient(settings); // <-- Your SDK client is now ready to use
} }
} }
} }
@@ -87,14 +98,14 @@ namespace Example
<ParamField query="options" type="object"> <ParamField query="options" type="object">
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="ClientId" type="string" optional> <ParamField query="ClientId" deprecated type="string" optional>
Your machine identity client ID. Your machine identity client ID.
</ParamField> </ParamField>
<ParamField query="ClientSecret" type="string" optional> <ParamField query="ClientSecret" deprecated type="string" optional>
Your machine identity client secret. Your machine identity client secret.
</ParamField> </ParamField>
<ParamField query="AccessToken" type="string" optional> <ParamField query="AccessToken" deprecated type="string" optional>
An access token obtained from the machine identity login endpoint. An access token obtained from the machine identity login endpoint.
</ParamField> </ParamField>
@@ -103,13 +114,120 @@ namespace Example
If manually set to 0, caching will be disabled, this is not recommended. If manually set to 0, caching will be disabled, this is not recommended.
</ParamField> </ParamField>
<ParamField query="SiteUrl()" type="string" default="https://app.infisical.com" optional> <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`) Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`)
</ParamField> </ParamField>
<ParamField query="Auth" type="AuthenticationOptions">
The authentication object to use for the client. This is required unless you're using environment variables.
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### Authentication
The SDK supports a variety of authentication methods. The most common authentication method is Universal Auth, which uses a client ID and client secret to authenticate.
#### Universal Auth
**Using environment variables**
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_ID` - Your machine identity client ID.
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` - Your machine identity client secret.
**Using the SDK directly**
```csharp
ClientSettings settings = new ClientSettings
{
Auth = new AuthenticationOptions
{
UniversalAuth = new UniversalAuthMethod
{
ClientId = "your-client-id",
ClientSecret = "your-client-secret"
}
}
};
var infisicalClient = new InfisicalClient(settings);
```
#### GCP ID Token Auth
<Info>
Please note that this authentication method will only work if you're running your application on Google Cloud Platform.
Please [read more](/documentation/platform/identities/gcp-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_GCP_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```csharp
ClientSettings settings = new ClientSettings
{
Auth = new AuthenticationOptions
{
GcpIdToken = new GcpIdTokenAuthMethod
{
IdentityId = "your-machine-identity-id",
}
}
};
var infisicalClient = new InfisicalClient(settings);
```
#### GCP IAM Auth
**Using environment variables**
- `INFISICAL_GCP_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
- `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` - The path to your GCP service account key file.
**Using the SDK directly**
```csharp
ClientSettings settings = new ClientSettings
{
Auth = new AuthenticationOptions
{
GcpIam = new GcpIamAuthMethod
{
IdentityId = "your-machine-identity-id",
ServiceAccountKeyFilePath = "./path/to/your/service-account-key.json"
}
}
};
var infisicalClient = new InfisicalClient(settings);
```
#### AWS IAM Auth
<Info>
Please note that this authentication method will only work if you're running your application on AWS.
Please [read more](/documentation/platform/identities/aws-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```csharp
ClientSettings settings = new ClientSettings
{
Auth = new AuthenticationOptions
{
AwsIam = new AwsIamAuthMethod
{
IdentityId = "your-machine-identity-id",
}
}
};
var infisicalClient = new InfisicalClient(settings);
```
### Caching ### Caching
To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cacheTTL" option when creating the client. To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cacheTTL" option when creating the client.
@@ -155,6 +273,14 @@ Retrieve all secrets within the Infisical project and environment that client is
<ParamField query="IncludeImports" type="boolean" default="false" optional> <ParamField query="IncludeImports" type="boolean" default="false" optional>
Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference) Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference)
</ParamField> </ParamField>
<ParamField query="Recursive" type="boolean" default="false" optional>
Whether or not to fetch secrets recursively from the specified path. Please note that there's a 20-depth limit for recursive fetching.
</ParamField>
<ParamField query="ExpandSecretReferences" type="boolean" default="true" optional>
Whether or not to expand secret references in the fetched secrets. Read about [secret reference](/documentation/platform/secret-reference)
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
+136 -10
View File
@@ -19,12 +19,19 @@ import com.infisical.sdk.schema.*;
public class Example { public class Example {
public static void main(String[] args) { public static void main(String[] args) {
// Create a new Infisical Client
// Create the authentication settings for the client
ClientSettings settings = new ClientSettings(); ClientSettings settings = new ClientSettings();
settings.setClientID("MACHINE_IDENTITY_CLIENT_ID"); AuthenticationOptions authOptions = new AuthenticationOptions();
settings.setClientSecret("MACHINE_IDENTITY_CLIENT_SECRET"); UniversalAuthMethod authMethod = new UniversalAuthMethod();
settings.setCacheTTL(Long.valueOf(300)); // 300 seconds, 5 minutes
authMethod.setClientID("YOUR_IDENTITY_ID");
authMethod.setClientSecret("YOUR_CLIENT_SECRET");
authOptions.setUniversalAuth(authMethod);
settings.setAuth(authOptions);
// Create a new Infisical Client
InfisicalClient client = new InfisicalClient(settings); InfisicalClient client = new InfisicalClient(settings);
// Create the options for fetching the secret // Create the options for fetching the secret
@@ -68,11 +75,18 @@ import com.infisical.sdk.schema.*;
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
// Create the authentication settings for the client
ClientSettings settings = new ClientSettings(); ClientSettings settings = new ClientSettings();
settings.setClientID("MACHINE_IDENTITY_CLIENT_ID"); AuthenticationOptions authOptions = new AuthenticationOptions();
settings.setClientSecret("MACHINE_IDENTITY_CLIENT_SECRET"); UniversalAuthMethod authMethod = new UniversalAuthMethod();
authMethod.setClientID("YOUR_IDENTITY_ID");
authMethod.setClientSecret("YOUR_CLIENT_SECRET");
authOptions.setUniversalAuth(authMethod);
settings.setAuth(authOptions);
// Create a new Infisical Client
InfisicalClient client = new InfisicalClient(settings); // Your client! InfisicalClient client = new InfisicalClient(settings); // Your client!
} }
} }
@@ -82,15 +96,21 @@ public class App {
<ParamField query="options" type="object"> <ParamField query="options" type="object">
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="setClientID()" type="string" optional> <ParamField query="setClientID()" type="string" deprecated optional>
Your machine identity client ID. Your machine identity client ID.
**This field is deprecated and will be removed in future versions.** Please use the `setAuth()` method on the client settings instead.
</ParamField> </ParamField>
<ParamField query="setClientSecret()" type="string" optional> <ParamField query="setClientSecret()" deprecated type="string" optional>
Your machine identity client secret. Your machine identity client secret.
**This field is deprecated and will be removed in future versions.** Please use the `setAuth()` method on the client settings instead.
</ParamField> </ParamField>
<ParamField query="setAccessToken()" type="string" optional> <ParamField query="setAccessToken()" deprecatedtype="string" optional>
An access token obtained from the machine identity login endpoint. An access token obtained from the machine identity login endpoint.
**This field is deprecated and will be removed in future versions.** Please use the `setAuth()` method on the client settings instead.
</ParamField> </ParamField>
<ParamField query="setCacheTTL()" type="number" default="300" optional> <ParamField query="setCacheTTL()" type="number" default="300" optional>
@@ -101,10 +121,106 @@ public class App {
<ParamField query="setSiteURL()" type="string" default="https://app.infisical.com" optional> <ParamField query="setSiteURL()" type="string" default="https://app.infisical.com" optional>
Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`) Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`)
</ParamField> </ParamField>
<ParamField query="setAuth()" type="AuthenticationOptions">
The authentication object to use for the client. This is required unless you're using environment variables.
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### Authentication
The SDK supports a variety of authentication methods. The most common authentication method is Universal Auth, which uses a client ID and client secret to authenticate.
#### Universal Auth
**Using environment variables**
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_ID` - Your machine identity client ID.
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` - Your machine identity client secret.
**Using the SDK directly**
```java
ClientSettings settings = new ClientSettings();
AuthenticationOptions authOptions = new AuthenticationOptions();
UniversalAuthMethod authMethod = new UniversalAuthMethod();
authMethod.setClientID("YOUR_IDENTITY_ID");
authMethod.setClientSecret("YOUR_CLIENT_SECRET");
authOptions.setUniversalAuth(authMethod);
settings.setAuth(authOptions);
InfisicalClient client = new InfisicalClient(settings);
```
#### GCP ID Token Auth
<Info>
Please note that this authentication method will only work if you're running your application on Google Cloud Platform.
Please [read more](/documentation/platform/identities/gcp-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_GCP_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```java
ClientSettings settings = new ClientSettings();
AuthenticationOptions authOptions = new AuthenticationOptions();
GCPIDTokenAuthMethod authMethod = new GCPIDTokenAuthMethod();
authMethod.setIdentityID("YOUR_MACHINE_IDENTITY_ID");
authOptions.setGcpIDToken(authMethod);
settings.setAuth(authOptions);
InfisicalClient client = new InfisicalClient(settings);
```
#### GCP IAM Auth
**Using environment variables**
- `INFISICAL_GCP_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
- `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` - The path to your GCP service account key file.
**Using the SDK directly**
```java
ClientSettings settings = new ClientSettings();
AuthenticationOptions authOptions = new AuthenticationOptions();
GCPIamAuthMethod authMethod = new GCPIamAuthMethod();
authMethod.setIdentityID("YOUR_MACHINE_IDENTITY_ID");
authMethod.setServiceAccountKeyFilePath("./path/to/your/service-account-key.json");
authOptions.setGcpIam(authMethod);
settings.setAuth(authOptions);
InfisicalClient client = new InfisicalClient(settings);
```
#### AWS IAM Auth
<Info>
Please note that this authentication method will only work if you're running your application on AWS.
Please [read more](/documentation/platform/identities/aws-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```java
ClientSettings settings = new ClientSettings();
AuthenticationOptions authOptions = new AuthenticationOptions();
AWSIamAuthMethod authMethod = new AWSIamAuthMethod();
authMethod.setIdentityID("YOUR_MACHINE_IDENTITY_ID");
authOptions.setAwsIam(authMethod);
settings.setAuth(authOptions);
InfisicalClient client = new InfisicalClient(settings);
```
### Caching ### Caching
To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cacheTTL" option when creating the client. To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cacheTTL" option when creating the client.
@@ -119,6 +235,8 @@ options.setEnvironment("dev");
options.setProjectID("PROJECT_ID"); options.setProjectID("PROJECT_ID");
options.setPath("/foo/bar"); options.setPath("/foo/bar");
options.setIncludeImports(false); options.setIncludeImports(false);
options.setRecursive(false);
options.setExpandSecretReferences(true);
SecretElement[] secrets = client.listSecrets(options); SecretElement[] secrets = client.listSecrets(options);
``` ```
@@ -148,6 +266,14 @@ Retrieve all secrets within the Infisical project and environment that client is
<ParamField query="setIncludeImports()" type="boolean" default="false" optional> <ParamField query="setIncludeImports()" type="boolean" default="false" optional>
Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference) Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference)
</ParamField> </ParamField>
<ParamField query="setRecursive()" type="boolean" default="false" optional>
Whether or not to fetch secrets recursively from the specified path. Please note that there's a 20-depth limit for recursive fetching.
</ParamField>
<ParamField query="setExpandSecretReferences()" type="boolean" default="true" optional>
Whether or not to expand secret references in the fetched secrets. Read about [secret reference](/documentation/platform/secret-reference)
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
+128 -15
View File
@@ -4,7 +4,7 @@ sidebarTitle: "Node.js"
icon: "node" icon: "node"
--- ---
If you're working with Node.js, the official [infisical-node](https://github.com/Infisical/sdk/tree/main/languages/node) package is the easiest way to fetch and work with secrets for your application. If you're working with Node.js, the official [Infisical Node SDK](https://github.com/Infisical/sdk/tree/main/languages/node) package is the easiest way to fetch and work with secrets for your application.
- [NPM Package](https://www.npmjs.com/package/@infisical/sdk) - [NPM Package](https://www.npmjs.com/package/@infisical/sdk)
- [Github Repository](https://github.com/Infisical/sdk/tree/main/languages/node) - [Github Repository](https://github.com/Infisical/sdk/tree/main/languages/node)
@@ -21,14 +21,19 @@ const app = express();
const PORT = 3000; const PORT = 3000;
const client = new InfisicalClient({ const client = new InfisicalClient({
clientId: "YOUR_CLIENT_ID", siteUrl: "https://app.infisical.com", // Optional, defaults to https://app.infisical.com
clientSecret: "YOUR_CLIENT_SECRET", auth: {
universalAuth: {
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
}
},
logLevel: LogLevel.Error logLevel: LogLevel.Error
}); });
app.get("/", async (req, res) => { app.get("/", async (req, res) => {
// access value // Access the secret
const name = await client.getSecret({ const name = await client.getSecret({
environment: "dev", environment: "dev",
projectId: "PROJECT_ID", projectId: "PROJECT_ID",
@@ -72,8 +77,12 @@ Import the SDK and create a client instance with your [Machine Identity](/docume
import { InfisicalClient, LogLevel } from "@infisical/sdk"; import { InfisicalClient, LogLevel } from "@infisical/sdk";
const client = new InfisicalClient({ const client = new InfisicalClient({
clientId: "YOUR_CLIENT_ID", auth: {
clientSecret: "YOUR_CLIENT_SECRET", universalAuth: {
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
}
},
logLevel: LogLevel.Error logLevel: LogLevel.Error
}); });
``` ```
@@ -81,31 +90,40 @@ Import the SDK and create a client instance with your [Machine Identity](/docume
</Tab> </Tab>
<Tab title="ES5"> <Tab title="ES5">
```js ```js
const { InfisicalClient, LogLevel } = require("@infisical/sdk"); const { InfisicalClient } = require("@infisical/sdk");
const client = new InfisicalClient({ const client = new InfisicalClient({
clientId: "YOUR_CLIENT_ID", auth: {
clientSecret: "YOUR_CLIENT_SECRET", universalAuth: {
logLevel: LogLevel.Error clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
}
},
}); });
``` ```
</Tab> </Tab>
</Tabs> </Tabs>
#### Parameters ### Parameters
<ParamField query="options" type="object"> <ParamField query="options" type="object">
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="clientId" type="string" optional> <ParamField query="clientId" deprecated type="string" optional>
Your machine identity client ID. Your machine identity client ID.
**This field is deprecated and will be removed in future versions.** Please use the `auth.universalAuth.clientId` field instead.
</ParamField> </ParamField>
<ParamField query="clientSecret" type="string" optional> <ParamField query="clientSecret" deprecated type="string" optional>
Your machine identity client secret. Your machine identity client secret.
**This field is deprecated and will be removed in future versions.** Please use the `auth.universalAuth.clientSecret` field instead.
</ParamField> </ParamField>
<ParamField query="accessToken" type="string" optional> <ParamField query="accessToken" deprecated type="string" optional>
An access token obtained from the machine identity login endpoint. An access token obtained from the machine identity login endpoint.
**This field is deprecated and will be removed in future versions.** Please use the `auth.accessToken` field instead.
</ParamField> </ParamField>
<ParamField query="cacheTtl" type="number" default="300" optional> <ParamField query="cacheTtl" type="number" default="300" optional>
@@ -119,10 +137,97 @@ Import the SDK and create a client instance with your [Machine Identity](/docume
<ParamField query="logLevel" type="enum" default="Error" optional> <ParamField query="logLevel" type="enum" default="Error" optional>
The level of logs you wish to log The logs are derived from Rust, as we have written our base SDK in Rust. The level of logs you wish to log The logs are derived from Rust, as we have written our base SDK in Rust.
</ParamField> </ParamField>
<ParamField query="auth" type="AuthenticationOptions">
The authentication object to use for the client. This is required unless you're using environment variables.
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### Authentication
The SDK supports a variety of authentication methods. The most common authentication method is Universal Auth, which uses a client ID and client secret to authenticate.
#### Universal Auth
**Using environment variables**
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_ID` - Your machine identity client ID.
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` - Your machine identity client secret.
**Using the SDK directly**
```js
const client = new InfisicalClient({
auth: {
universalAuth: {
clientId: "YOUR_CLIENT_ID",
clientSecret: "YOUR_CLIENT_SECRET"
}
}
});
```
#### GCP ID Token Auth
<Info>
Please note that this authentication method will only work if you're running your application on Google Cloud Platform.
Please [read more](/documentation/platform/identities/gcp-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_GCP_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```js
const client = new InfisicalClient({
auth: {
gcpIdToken: {
identityId: "YOUR_IDENTITY_ID"
}
}
});
```
#### GCP IAM Auth
**Using environment variables**
- `INFISICAL_GCP_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
- `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` - The path to your GCP service account key file.
**Using the SDK directly**
```js
const client = new InfisicalClient({
auth: {
gcpIam: {
identityId: "YOUR_IDENTITY_ID",
serviceAccountKeyFilePath: "./path/to/your/service-account-key.json"
}
}
});
```
#### AWS IAM Auth
<Info>
Please note that this authentication method will only work if you're running your application on AWS.
Please [read more](/documentation/platform/identities/aws-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```js
const client = new InfisicalClient({
auth: {
awsIam: {
identityId: "YOUR_IDENTITY_ID"
}
}
});
```
### Caching ### Caching
To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cacheTtl" option when creating the client. To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cacheTtl" option when creating the client.
@@ -161,6 +266,14 @@ Retrieve all secrets within the Infisical project and environment that client is
Whether or not to set the fetched secrets to the process environment. If true, you can access the secrets like so `process.env["SECRET_NAME"]`. Whether or not to set the fetched secrets to the process environment. If true, you can access the secrets like so `process.env["SECRET_NAME"]`.
</ParamField> </ParamField>
<ParamField query="recursive" type="boolean" default="false" optional>
Whether or not to fetch secrets recursively from the specified path. Please note that there's a 20-depth limit for recursive fetching.
</ParamField>
<ParamField query="expandSecretReferences" type="boolean" default="true" optional>
Whether or not to expand secret references in the fetched secrets. Read about [secret reference](/documentation/platform/secret-reference)
</ParamField>
<ParamField query="includeImports" type="false" default="boolean" optional> <ParamField query="includeImports" type="false" default="boolean" optional>
Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference) Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference)
</ParamField> </ParamField>
+236 -120
View File
@@ -6,20 +6,24 @@ icon: "python"
If you're working with Python, the official [infisical-python](https://github.com/Infisical/sdk/edit/main/crates/infisical-py) package is the easiest way to fetch and work with secrets for your application. If you're working with Python, the official [infisical-python](https://github.com/Infisical/sdk/edit/main/crates/infisical-py) package is the easiest way to fetch and work with secrets for your application.
- [PyPi Package](https://pypi.org/project/infisical-python/) - [PyPi Package](https://pypi.org/project/infisical-python/)
- [Github Repository](https://github.com/Infisical/sdk/edit/main/crates/infisical-py) - [Github Repository](https://github.com/Infisical/sdk/edit/main/crates/infisical-py)
## Basic Usage ## Basic Usage
```py ```py
from flask import Flask from flask import Flask
from infisical_client import ClientSettings, InfisicalClient, GetSecretOptions from infisical_client import ClientSettings, InfisicalClient, GetSecretOptions, AuthenticationOptions, UniversalAuthMethod
app = Flask(__name__) app = Flask(__name__)
client = InfisicalClient(ClientSettings( client = InfisicalClient(ClientSettings(
client_id="MACHINE_IDENTITY_CLIENT_ID", auth=AuthenticationOptions(
client_secret="MACHINE_IDENTITY_CLIENT_SECRET", universal_auth=UniversalAuthMethod(
client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
)
)
)) ))
@app.route("/") @app.route("/")
@@ -38,7 +42,7 @@ def hello_world():
This example demonstrates how to use the Infisical Python SDK with a Flask application. The application retrieves a secret named "NAME" and responds to requests with a greeting that includes the secret value. This example demonstrates how to use the Infisical Python SDK with a Flask application. The application retrieves a secret named "NAME" and responds to requests with a greeting that includes the secret value.
<Warning> <Warning>
We do not recommend hardcoding your [Machine Identity Tokens](/platform/identities/overview). Setting it as an environment variable would be best. We do not recommend hardcoding your [Machine Identity Tokens](/platform/identities/overview). Setting it as an environment variable would be best.
</Warning> </Warning>
## Installation ## Installation
@@ -56,11 +60,15 @@ Note: You need Python 3.7+.
Import the SDK and create a client instance with your [Machine Identity](/api-reference/overview/authentication). Import the SDK and create a client instance with your [Machine Identity](/api-reference/overview/authentication).
```py ```py
from infisical_client import ClientSettings, InfisicalClient from infisical_client import ClientSettings, InfisicalClient, AuthenticationOptions, UniversalAuthMethod
client = InfisicalClient(ClientSettings( client = InfisicalClient(ClientSettings(
client_id="MACHINE_IDENTITY_CLIENT_ID", auth=AuthenticationOptions(
client_secret="MACHINE_IDENTITY_CLIENT_SECRET", universal_auth=UniversalAuthMethod(
client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
)
)
)) ))
``` ```
@@ -68,14 +76,20 @@ client = InfisicalClient(ClientSettings(
<ParamField query="options" type="object"> <ParamField query="options" type="object">
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="client_id" type="string" optional> <ParamField query="client_id" type="string" deprecated optional>
Your Infisical Client ID. Your Infisical Client ID.
**This field is deprecated and will be removed in future versions.** Please use the `auth` field instead.
</ParamField> </ParamField>
<ParamField query="client_secret" type="string" optional> <ParamField query="client_secret" type="string" deprecated optional>
Your Infisical Client Secret. Your Infisical Client Secret.
**This field is deprecated and will be removed in future versions.** Please use the `auth` field instead.
</ParamField> </ParamField>
<ParamField query="access_token" type="string" optional> <ParamField query="access_token" type="string" deprecated optional>
If you want to directly pass an access token obtained from the authentication endpoints, you can do so. If you want to directly pass an access token obtained from the authentication endpoints, you can do so.
**This field is deprecated and will be removed in future versions.** Please use the `auth` field instead.
</ParamField> </ParamField>
<ParamField query="cache_ttl" type="number" default="300" optional> <ParamField query="cache_ttl" type="number" default="300" optional>
@@ -85,18 +99,108 @@ client = InfisicalClient(ClientSettings(
<ParamField <ParamField
query="site_url" query="site_url"
type="string" type="string"
default="https://app.infisical.com" default="https://app.infisical.com"
optional optional
> >
Your self-hosted absolute site URL including the protocol (e.g. Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`)
`https://app.infisical.com`)
</ParamField> </ParamField>
<ParamField query="auth" type="AuthenticationOptions">
The authentication object to use for the client. This is required unless you're using environment variables.
</ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### Authentication
The SDK supports a variety of authentication methods. The most common authentication method is Universal Auth, which uses a client ID and client secret to authenticate.
#### Universal Auth
**Using environment variables**
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_ID` - Your machine identity client ID.
- `INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET` - Your machine identity client secret.
**Using the SDK directly**
```python3
from infisical_client import ClientSettings, InfisicalClient, AuthenticationOptions, UniversalAuthMethod
client = InfisicalClient(ClientSettings(
auth=AuthenticationOptions(
universal_auth=UniversalAuthMethod(
client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
)
)
))
```
#### GCP ID Token Auth
<Info>
Please note that this authentication method will only work if you're running your application on Google Cloud Platform.
Please [read more](/documentation/platform/identities/gcp-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_GCP_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```py
from infisical_client import ClientSettings, InfisicalClient, AuthenticationOptions, GCPIDTokenAuthMethod
client = InfisicalClient(ClientSettings(
auth=AuthenticationOptions(
gcp_id_token=GCPIDTokenAuthMethod(
identity_id="MACHINE_IDENTITY_ID",
)
)
))
```
#### GCP IAM Auth
**Using environment variables**
- `INFISICAL_GCP_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
- `INFISICAL_GCP_IAM_SERVICE_ACCOUNT_KEY_FILE_PATH` - The path to your GCP service account key file.
**Using the SDK directly**
```py
from infisical_client import ClientSettings, InfisicalClient, AuthenticationOptions, GCPIamAuthMethod
client = InfisicalClient(ClientSettings(
auth=AuthenticationOptions(
gcp_iam=GCPIamAuthMethod(
identity_id="MACHINE_IDENTITY_ID",
service_account_key_file_path="./path/to/service_account_key.json"
)
)
))
```
#### AWS IAM Auth
<Info>
Please note that this authentication method will only work if you're running your application on AWS.
Please [read more](/documentation/platform/identities/aws-auth) about this authentication method.
</Info>
**Using environment variables**
- `INFISICAL_AWS_IAM_AUTH_IDENTITY_ID` - Your Infisical Machine Identity ID.
**Using the SDK directly**
```py
from infisical_client import ClientSettings, InfisicalClient, AuthenticationOptions, AWSIamAuthMethod
client = InfisicalClient(ClientSettings(
auth=AuthenticationOptions(
aws_iam=AWSIamAuthMethod(identity_id="MACHINE_IDENTITY_ID")
)
))
```
### Caching ### Caching
To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cache_ttl" option when creating the client. To reduce the number of API requests, the SDK temporarily stores secrets it retrieves. By default, a secret remains cached for 5 minutes after it's first fetched. Each time it's fetched again, this 5-minute timer resets. You can adjust this caching duration by setting the "cache_ttl" option when creating the client.
@@ -133,6 +237,14 @@ Retrieve all secrets within the Infisical project and environment that client is
Whether or not to set the fetched secrets to the process environment. If true, you can access the secrets like so `process.env["SECRET_NAME"]`. Whether or not to set the fetched secrets to the process environment. If true, you can access the secrets like so `process.env["SECRET_NAME"]`.
</ParamField> </ParamField>
<ParamField query="recursive" type="boolean" default="false" optional>
Whether or not to fetch secrets recursively from the specified path. Please note that there's a 20-depth limit for recursive fetching.
</ParamField>
<ParamField query="expand_secret_references" type="boolean" default="true" optional>
Whether or not to expand secret references in the fetched secrets. Read about [secret reference](/documentation/platform/secret-reference)
</ParamField>
<ParamField query="include_imports" type="boolean" default="false" optional> <ParamField query="include_imports" type="boolean" default="false" optional>
Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference) Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference)
</ParamField> </ParamField>
@@ -156,26 +268,26 @@ By default, `getSecret()` fetches and returns a shared secret. If not found, it
#### Parameters #### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="secret_name" type="string" required> <ParamField query="secret_name" type="string" required>
The key of the secret to retrieve The key of the secret to retrieve
</ParamField> </ParamField>
<ParamField query="environment" type="string" required> <ParamField query="environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets should be fetched from.
</ParamField> </ParamField>
<ParamField query="project_id" type="string" required> <ParamField query="project_id" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="path" type="string" optional> <ParamField query="path" type="string" optional>
The path from where secret should be fetched from. The path from where secret should be fetched from.
</ParamField> </ParamField>
<ParamField query="type" type="string" optional> <ParamField query="type" type="string" optional>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "personal". The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "personal".
</ParamField> </ParamField>
<ParamField query="include_imports" type="boolean" default="false" optional> <ParamField query="include_imports" type="boolean" default="false" optional>
Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference) Whether or not to include imported secrets from the current path. Read about [secret import](/documentation/platform/secret-reference)
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### client.createSecret(options) ### client.createSecret(options)
@@ -194,26 +306,26 @@ Create a new secret in Infisical.
#### Parameters #### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="secret_name" type="string" required> <ParamField query="secret_name" type="string" required>
The key of the secret to create. The key of the secret to create.
</ParamField> </ParamField>
<ParamField query="secret_value" type="string" required> <ParamField query="secret_value" type="string" required>
The value of the secret. The value of the secret.
</ParamField> </ParamField>
<ParamField query="project_id" type="string" required> <ParamField query="project_id" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="environment" type="string" required> <ParamField query="environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets should be fetched from.
</ParamField> </ParamField>
<ParamField query="path" type="string" optional> <ParamField query="path" type="string" optional>
The path from where secret should be created. The path from where secret should be created.
</ParamField> </ParamField>
<ParamField query="type" type="string" optional> <ParamField query="type" type="string" optional>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### client.updateSecret(options) ### client.updateSecret(options)
@@ -232,26 +344,26 @@ Update an existing secret in Infisical.
#### Parameters #### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="secret_name" type="string" required> <ParamField query="secret_name" type="string" required>
The key of the secret to update. The key of the secret to update.
</ParamField> </ParamField>
<ParamField query="secret_value" type="string" required> <ParamField query="secret_value" type="string" required>
The new value of the secret. The new value of the secret.
</ParamField> </ParamField>
<ParamField query="project_id" type="string" required> <ParamField query="project_id" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="environment" type="string" required> <ParamField query="environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets should be fetched from.
</ParamField> </ParamField>
<ParamField query="path" type="string" optional> <ParamField query="path" type="string" optional>
The path from where secret should be updated. The path from where secret should be updated.
</ParamField> </ParamField>
<ParamField query="type" type="string" optional> <ParamField query="type" type="string" optional>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
### client.deleteSecret(options) ### client.deleteSecret(options)
@@ -269,23 +381,23 @@ Delete a secret in Infisical.
#### Parameters #### Parameters
<ParamField query="Parameters" type="object" optional> <ParamField query="Parameters" type="object" optional>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="secret_name" type="string"> <ParamField query="secret_name" type="string">
The key of the secret to update. The key of the secret to update.
</ParamField> </ParamField>
<ParamField query="project_id" type="string" required> <ParamField query="project_id" type="string" required>
The project ID where the secret lives in. The project ID where the secret lives in.
</ParamField> </ParamField>
<ParamField query="environment" type="string" required> <ParamField query="environment" type="string" required>
The slug name (dev, prod, etc) of the environment from where secrets should be fetched from. The slug name (dev, prod, etc) of the environment from where secrets should be fetched from.
</ParamField> </ParamField>
<ParamField query="path" type="string" optional> <ParamField query="path" type="string" optional>
The path from where secret should be deleted. The path from where secret should be deleted.
</ParamField> </ParamField>
<ParamField query="type" type="string" optional> <ParamField query="type" type="string" optional>
The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared". The type of the secret. Valid options are "shared" or "personal". If not specified, the default value is "shared".
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
## Cryptography ## Cryptography
@@ -299,9 +411,11 @@ key = client.createSymmetricKey()
``` ```
#### Returns (string) #### Returns (string)
`key` (string): A base64-encoded, 256-bit symmetric key, that can be used for encryption/decryption purposes. `key` (string): A base64-encoded, 256-bit symmetric key, that can be used for encryption/decryption purposes.
### Encrypt symmetric ### Encrypt symmetric
```py ```py
encryptOptions = EncryptSymmetricOptions( encryptOptions = EncryptSymmetricOptions(
key=key, key=key,
@@ -314,22 +428,22 @@ encryptedData = client.encryptSymmetric(encryptOptions)
#### Parameters #### Parameters
<ParamField query="Parameters" type="object" required> <ParamField query="Parameters" type="object" required>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="plaintext" type="string"> <ParamField query="plaintext" type="string">
The plaintext you want to encrypt. The plaintext you want to encrypt.
</ParamField> </ParamField>
<ParamField query="key" type="string" required> <ParamField query="key" type="string" required>
The symmetric key to use for encryption. The symmetric key to use for encryption.
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
#### Returns (object) #### Returns (object)
`tag` (string): A base64-encoded, 128-bit authentication tag.
`iv` (string): A base64-encoded, 96-bit initialization vector. `tag` (string): A base64-encoded, 128-bit authentication tag. `iv` (string): A base64-encoded, 96-bit initialization vector. `ciphertext` (string): A base64-encoded, encrypted ciphertext.
`ciphertext` (string): A base64-encoded, encrypted ciphertext.
### Decrypt symmetric ### Decrypt symmetric
```py ```py
decryptOptions = DecryptSymmetricOptions( decryptOptions = DecryptSymmetricOptions(
ciphertext=encryptedData.ciphertext, ciphertext=encryptedData.ciphertext,
@@ -344,22 +458,24 @@ decryptedString = client.decryptSymmetric(decryptOptions)
``` ```
#### Parameters #### Parameters
<ParamField query="Parameters" type="object" required> <ParamField query="Parameters" type="object" required>
<Expandable title="properties"> <Expandable title="properties">
<ParamField query="ciphertext" type="string"> <ParamField query="ciphertext" type="string">
The ciphertext you want to decrypt. The ciphertext you want to decrypt.
</ParamField> </ParamField>
<ParamField query="key" type="string" required> <ParamField query="key" type="string" required>
The symmetric key to use for encryption. The symmetric key to use for encryption.
</ParamField> </ParamField>
<ParamField query="iv" type="string" required> <ParamField query="iv" type="string" required>
The initialization vector to use for decryption. The initialization vector to use for decryption.
</ParamField> </ParamField>
<ParamField query="tag" type="string" required> <ParamField query="tag" type="string" required>
The authentication tag to use for decryption. The authentication tag to use for decryption.
</ParamField> </ParamField>
</Expandable> </Expandable>
</ParamField> </ParamField>
#### Returns (string) #### Returns (string)
`plaintext` (string): The decrypted plaintext. `plaintext` (string): The decrypted plaintext.