From d7054404007b88a417837d288a72a52a59545b1f Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Wed, 15 Mar 2023 18:21:52 +0700 Subject: [PATCH] Revamp Node SDK docs --- docs/mint.json | 13 ++-- docs/sdk/overview/usage.mdx | 103 ------------------------------- docs/sdks/overview/go.mdx | 8 +++ docs/sdks/overview/java.mdx | 8 +++ docs/sdks/overview/node.mdx | 111 ++++++++++++++++++++++++++++++++++ docs/sdks/overview/python.mdx | 8 +++ docs/sdks/overview/ruby.mdx | 8 +++ docs/sdks/overview/rust.mdx | 8 +++ 8 files changed, 160 insertions(+), 107 deletions(-) delete mode 100644 docs/sdk/overview/usage.mdx create mode 100644 docs/sdks/overview/go.mdx create mode 100644 docs/sdks/overview/java.mdx create mode 100644 docs/sdks/overview/node.mdx create mode 100644 docs/sdks/overview/python.mdx create mode 100644 docs/sdks/overview/ruby.mdx create mode 100644 docs/sdks/overview/rust.mdx diff --git a/docs/mint.json b/docs/mint.json index 697a7bfeb..efd669781 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -50,9 +50,9 @@ "url": "self-hosting" }, { - "name": "SDK", + "name": "SDKs", "icon": "puzzle-piece", - "url": "sdk" + "url": "sdks" }, { "name": "API Reference", @@ -192,9 +192,14 @@ ] }, { - "group": "SDK", + "group": "SDKs", "pages": [ - "sdk/overview/usage" + "sdks/overview/node", + "sdks/overview/python", + "sdks/overview/java", + "sdks/overview/ruby", + "sdks/overview/go", + "sdks/overview/rust" ] }, { diff --git a/docs/sdk/overview/usage.mdx b/docs/sdk/overview/usage.mdx deleted file mode 100644 index 84d963fff..000000000 --- a/docs/sdk/overview/usage.mdx +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: "Usage" ---- - - - We're currently expanding the functionality of the Javascript SDK and working - on mirror SDKs for other languages like Python as well. Follow this GitHub - [issue](https://github.com/Infisical/infisical/issues/320) to stay updated. - - -Infisical provides a [Node SDK](https://github.com/Infisical/infisical-node) that users can easily install into their applications and use to fetch their secrets. - -With the SDK, users can currently fetch back secrets and define default values. - - - - -## Installation - -```bash -$ npm install infisical-node -``` - -## Import - -```js -// ES6 syntax -import infisical from "infisical-node"; - -// ES5 syntax -const infisical = require("infisical-node"); -``` - -## Initialization - -If your app only needs to connect to one Infisical project, you should use `infisical.connect`. If you need to connect to multiple Infisical projects, use `infisical.createConnection`. - -Both `connect` and `createConnection` take a parameter `token` and pull in the secrets accessible by that Infisical token. - -```js -// using async-await (recommended) -await infisical.connect({ - token: "your_infisical_token", -}); -``` - -```js -// using promise chaining -infisical.connect({ - token: "your_infisical_token" -}) -.then(() => { - console.log('Success!) -}) -.catch(err => { - console.error('Error: ', err); -}) -``` - -Options: - -| Option | Description | Default Value | -| -------------------- | --------------------------------------------------------- | --------------------------- | -| `token` | ❗️ An Infisical Token to be used to fetch secrets | `None` | -| `siteURL` | Site URL of Infisical to connect to | `https://app.infisical.com` | -| `attachToProcessEnv` | Whether or not to attach fetched secrets to `process.env` | `false` | - -## Access a Secret Value - -```js -const dbURL = infisical.get("DB_URL"); -``` - -## Example with Express - -```js -const express = require("express"); -const port = 3000; -const infisical = require("infisical-node"); - -app.get("/", (req, res) => { - // access value - const name = infisical.get("NAME"); - - res.send(`Hello! My name is: ${name}`); -}); - -app.listen(port, async () => { - // initialize client - await infisical.connect({ - token: "YOUR_INFISICAL_TOKEN", - }); - - console.log(`App listening on port ${port}`); -}); -``` - - - - Coming soon. - - - diff --git a/docs/sdks/overview/go.mdx b/docs/sdks/overview/go.mdx new file mode 100644 index 000000000..0ff2a2dde --- /dev/null +++ b/docs/sdks/overview/go.mdx @@ -0,0 +1,8 @@ +--- +title: "Go" +--- + +Coming soon. + +Follow this GitHub +[issue](https://github.com/Infisical/infisical/issues/436) to stay updated. diff --git a/docs/sdks/overview/java.mdx b/docs/sdks/overview/java.mdx new file mode 100644 index 000000000..2dd2c3c1d --- /dev/null +++ b/docs/sdks/overview/java.mdx @@ -0,0 +1,8 @@ +--- +title: "Java" +--- + +Coming soon. + +Follow this GitHub +[issue](https://github.com/Infisical/infisical/issues/434) to stay updated. diff --git a/docs/sdks/overview/node.mdx b/docs/sdks/overview/node.mdx new file mode 100644 index 000000000..37928933f --- /dev/null +++ b/docs/sdks/overview/node.mdx @@ -0,0 +1,111 @@ +--- +title: "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 secrets for your application. + +## Installation + +Run `npm` to add `infisical` to your project. + +```bash +npm install infisical-node --save +``` + +## Initialization + +Set up `infisical` asynchronously as early as possible in your application by importing and initializing the global instance with `infisical.connect([options])`. + +This methods fetches back all the secrets in the project and environment accessible by the token passed in `options`. + + + + ```js + import infisical from "infisical-node"; + + const main = async () => { + await infisical.connect({ + token: "your_infisical_token", + }); + + // your app logic + } + + main(); + ``` + + + + ```js + const infisical = require("infisical-node"); + + infisical.connect({ + token: "your_infisical_token" + }) + .then(() => { + // your application logic + }) + .catch(err => { + console.error('Error: ', err); + }) + ```` + + + + +`infisical.connect([options])` + +| Option | Description | Default Value | +| --------- | -------------------------------------------------------------------------------------------- | --------------------------- | +| `token` | An [Infisical Token](/getting-started/dashboard/token) scoped to a project and environment | `None` | +| `siteURL` | Your self-hosted absolute site URL including the protocol (e.g. `https://app.infisical.com`) | `https://app.infisical.com` | +| `debug` | Whether or not debug mode is on | `false` | + + + If you need to connect to multiple Infisical projects, you can use + `infisical.createConnection([options])` to return a local instance of + `infisical`. + + +## Usage + +To get the value of secret, pass the name of its key into `infisical.get()`. + +```js +const value = infisical.get("SOME_KEY"); +``` + + + `infisical` falls back to `process.env` if `token` is `undefined` during + initialization or if a value is not found in the secrets fetched. + + +## Example with Express + +```js +const express = require("express"); +const port = 3000; +const infisical = require("infisical-node"); + +const main = async () => { + await infisical.connect({ + token: "st.xxx.xxx", + }); + + // your application logic + + app.get("/", (req, res) => { + res.send(`Howdy, ${infisical.get("NAME")}!`); + }); + + app.listen(port, async () => { + console.log(`App listening on port ${port}`); + }); +}; +``` + + + We do not recommend hardcoding your [Infisical + Token](/getting-started/dashboard/token). Setting it as an environment + variable would be best. + diff --git a/docs/sdks/overview/python.mdx b/docs/sdks/overview/python.mdx new file mode 100644 index 000000000..3a9b82152 --- /dev/null +++ b/docs/sdks/overview/python.mdx @@ -0,0 +1,8 @@ +--- +title: "Python" +--- + +Coming soon. + +Follow this GitHub +[issue](https://github.com/Infisical/infisical/issues/433) to stay updated. diff --git a/docs/sdks/overview/ruby.mdx b/docs/sdks/overview/ruby.mdx new file mode 100644 index 000000000..80dab508a --- /dev/null +++ b/docs/sdks/overview/ruby.mdx @@ -0,0 +1,8 @@ +--- +title: "Ruby" +--- + +Coming soon. + +Follow this GitHub +[issue](https://github.com/Infisical/infisical/issues/435) to stay updated. diff --git a/docs/sdks/overview/rust.mdx b/docs/sdks/overview/rust.mdx new file mode 100644 index 000000000..8fa9b3b5b --- /dev/null +++ b/docs/sdks/overview/rust.mdx @@ -0,0 +1,8 @@ +--- +title: "Rust" +--- + +Coming soon. + +Follow this GitHub +[issue](https://github.com/Infisical/infisical/issues/437) to stay updated.