From f137087ef14e96231ab91956404ae9a073d71992 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Thu, 27 Apr 2023 15:53:23 +0300 Subject: [PATCH] Finish Python SDK docs --- docs/getting-started/quickstart.mdx | 2 + docs/sdks/languages/go.mdx | 1 + docs/sdks/languages/java.mdx | 1 + docs/sdks/languages/node.mdx | 135 +++++++++++++---------- docs/sdks/languages/python.mdx | 163 +++++++++++++++++++++++++++- docs/sdks/languages/ruby.mdx | 1 + docs/sdks/languages/rust.mdx | 1 + docs/sdks/overview.mdx | 7 +- 8 files changed, 247 insertions(+), 64 deletions(-) diff --git a/docs/getting-started/quickstart.mdx b/docs/getting-started/quickstart.mdx index 7fca86d4d..dba032e6e 100644 --- a/docs/getting-started/quickstart.mdx +++ b/docs/getting-started/quickstart.mdx @@ -49,6 +49,8 @@ These examples demonstrate how to store and fetch environment variables from [In [Infisical SDKs](/sdks/overview) let your app fetch back secrets using an [Infisical Token](/getting-started/dashboard/token) that is scoped to a project and environment in Infisical. In this example, we demonstrate how to use the [Node SDK](/sdks/languages/node). + Using Python? We have a [Python SDK](/sdks/languages/python) as well. + ### Obtain an [Infisical Token](/getting-started/dashboard/token) Head to your project settings to create a token scoped to the project and environment you wish to fetch secrets from. diff --git a/docs/sdks/languages/go.mdx b/docs/sdks/languages/go.mdx index 0ff2a2dde..b470c5b7d 100644 --- a/docs/sdks/languages/go.mdx +++ b/docs/sdks/languages/go.mdx @@ -1,5 +1,6 @@ --- title: "Go" +icon: "golang" --- Coming soon. diff --git a/docs/sdks/languages/java.mdx b/docs/sdks/languages/java.mdx index 2dd2c3c1d..7bc371bae 100644 --- a/docs/sdks/languages/java.mdx +++ b/docs/sdks/languages/java.mdx @@ -1,5 +1,6 @@ --- title: "Java" +icon: "java" --- Coming soon. diff --git a/docs/sdks/languages/node.mdx b/docs/sdks/languages/node.mdx index 4d75168bc..7f0176f91 100644 --- a/docs/sdks/languages/node.mdx +++ b/docs/sdks/languages/node.mdx @@ -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. - +### Parameters + + - + An [Infisical Token](/getting-started/dashboard/token) scoped to a project and environment - - + Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`) - - + + Time-to-live (in seconds) for refreshing cached secrets. Default: `300`. - - + + Whether or not debug mode is on - + - + ## 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. + + 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. + + ## 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 - + The key of the secret to retrieve - - + + - - "personal" (default) or "shared". - + + The type of the secret. Valid options are "shared" or "personal" + - + -### 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. - + The key of the secret to create - - + + The value of the secret to create - - + + - - "shared" (default) or "personal". A personal secret can only be created if a shared secret with the same name exists. - + + 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. + - + -### 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. - - The key of the secret to update - - - The new value of the secret - - - - - "shared" (default) or "personal". - - - +### Parameters -### infisical.deleteSecret(secretName, options) + + The key of the secret to update + + + The new value of the secret + + + + + The type of the secret. Valid options are "shared" or "personal" + + + + +### client.deleteSecret(secretName, options) ```js -const deletedSecret = await infisical.deleteSecret("API_KEY"); +const deletedSecret = await client.deleteSecret("API_KEY"); ``` Delete a secret in Infisical. - + The key of the secret to delete - - + + - - "shared" (default) or "personal". Note that deleting a shared secret also deletes all associated personal secrets. - + + The type of the secret. Valid options are "shared" or "personal". Note that deleting a shared secret also deletes all associated personal secrets. + - + diff --git a/docs/sdks/languages/python.mdx b/docs/sdks/languages/python.mdx index 3a9b82152..27ba41271 100644 --- a/docs/sdks/languages/python.mdx +++ b/docs/sdks/languages/python.mdx @@ -1,8 +1,169 @@ --- title: "Python" +icon: "python" --- -Coming soon. +If you're working with Python, the official [infisical-python](https://github.com/Infisical/infisical-python) package is the easiest way to fetch and work with secrets for your application. + +## Basic Usage + +```py +from flask import Flask +from infisical import InfisicalClient + +app = Flask(__name__) + +client = InfisicalClient(token="your_infisical_token") + +@app.route("/") +def hello_world(): + # access value + name = client.get_secret("NAME") + return f"Hello! My name is: {name.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. + + + We do not recommend hardcoding your [Infisical + Token](/getting-started/dashboard/token). Setting it as an environment + variable would be best. + + +## Installation + +Run `pip` to add `infisical-python` to your project + +```console +$ pip install infisical +``` + +Note: You need Python 3.7+. + +## Configuration + +Import the SDK and create a client instance with your Infisical token. + +```py +from infisical import InfisicalClient + +client = InfisicalClient(token="your_infisical_token") +``` + +### Parameters + + + An [Infisical Token](/getting-started/dashboard/token) scoped to a project + and environment + + + Your self-hosted absolute site URL including the protocol (e.g. + `https://app.infisical.com`) + + + Time-to-live (in seconds) for refreshing cached secrets. Default: `300`. + + + Whether or not debug mode is on + + +## Caching + +The SDK caches every secret and updates it periodically based on the provided `cache_ttl`. For example, if `cache_ttl` 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. + + + 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. + + +## Working with Secrets + +### client.get_all_secrets() + +```py +secrets = client.get_all_secrets() +``` + +Retrieve all secrets within the Infisical project and environment that client is connected to + +### client.get_secret(secret_name, options) + +```py +secret = client.get_secret("API_KEY") +value = secret.secret_value # get its value +``` + +By default, `get_secret()` fetches and returns a personal secret. If not found, it returns a shared secret, or tries to retrieve the value from `os.environ`. If a secret is fetched, `get_secret()` 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 + + + The key of the secret to retrieve + + + The type of the secret. Valid options are "shared" or "personal" + + +### client.create_secret(secret_name, secret_value, options) + +```py +new_api_key = client.create_secret("API_KEY", "FOO"); +``` + +Create a new secret in Infisical. + +### Parameters + + + The key of the secret to create + + + The value of the secret to create + + + 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. + + +### client.update_secret(secret_name, secret_value, options) + +```py +updated_api_key = client.update_secret("API_KEY", "BAR"); +``` + +Update an existing secret in Infisical. + +### Parameters + + + The key of the secret to update + + + The new value of the secret + + + The type of the secret. Valid options are "shared" or "personal" + + +### client.delete_secret(secret_name, options) + +```py +deleted_secret = client.delete_secret("API_KEY"); +``` + +Delete a secret in Infisical. + +### Parameters + + + The key of the secret to delete + + + The type of the secret. Valid options are "shared" or "personal" + Follow this GitHub [issue](https://github.com/Infisical/infisical/issues/433) to stay updated. diff --git a/docs/sdks/languages/ruby.mdx b/docs/sdks/languages/ruby.mdx index 80dab508a..1233e44bd 100644 --- a/docs/sdks/languages/ruby.mdx +++ b/docs/sdks/languages/ruby.mdx @@ -1,5 +1,6 @@ --- title: "Ruby" +icon: "gem" --- Coming soon. diff --git a/docs/sdks/languages/rust.mdx b/docs/sdks/languages/rust.mdx index 8fa9b3b5b..5d5b770ca 100644 --- a/docs/sdks/languages/rust.mdx +++ b/docs/sdks/languages/rust.mdx @@ -1,5 +1,6 @@ --- title: "Rust" +icon: "rust" --- Coming soon. diff --git a/docs/sdks/overview.mdx b/docs/sdks/overview.mdx index fd27ad902..e1d85dae2 100644 --- a/docs/sdks/overview.mdx +++ b/docs/sdks/overview.mdx @@ -3,12 +3,9 @@ title: "Overview" description: "How to use Infisical SDKs to fetch back secrets for your app" --- -Infisical SDKs provide the easiest way for your app to fetch back secrets using an [Infisical Token](/getting-started/dashboard/token) and has a few benefits: +Whether it be for local development or production, Infisical SDKs provide the easiest way for your app to fetch back secrets using an [Infisical Token](/getting-started/dashboard/token). -- Local development: Replace 10s of environment variables in your `.env` file with 1 environment variable (the [Infisical Token](/getting-started/dashboard/token)). -- Production: Fetch secrets back to any cloud regardless of if an integration exists between Infisical and the cloud platform. - -We currently only have the [Node SDK](/sdks/languages/node) available but more language SDKs are coming out soon: +We currently have the [Node SDK](/sdks/languages/node) and [Python SDK](/sdks/languages/python) available with more language SDKs coming out soon: - [Node](/sdks/languages/node) - [Python](/sdks/languages/python)