Skip to content

Retrieving Remote ENVs

Matt Carlotta edited this page Feb 1, 2024 · 20 revisions

Prerequisite

To retrieve remote ENVs from the nvi API, you must first register and verify your email using the front-facing application.

  • Once registered and verified, create a project, an environment and at least 1 ENV secret within that project's environment
  • Navigate to your account settings page, locate your unique API key and click the copy to clipboard button

See prerequisite.

Retrieving remote ENVs via specific project and environment using the nvi CLI tool, input the following:

  • "--api" flag followed by a space
  • "--project" flag followed by a space and then the name of the project you've created
  • "--environment" flag followed by a space and then the name of the environment you've created
  • a "--print" flag or "--" flag followed by a space and then a system command to run
nvi --api --project my_project --environment development -- cargo run

Then, you'll be asked for your API key‡. Input your API key and press the "Enter" key:

[nvi] Please enter your unique API key: 

If no error is displayed in the terminal, then a child process should be spawned with the command OR ENVs will be printed to standard out as stringified JSON.

How do I retrieve remote ENVs dynamically?

See prerequisite.

Retrieving remote ENVs via dynamic selection using the nvi CLI tool, input the following:

  • "--api" flag followed by a space
  • a "--print" flag or "--" flag followed by a space and then a system command to run
nvi --api -- cargo run

Then, you'll be asked for your API key‡. Input your API key and press the "Enter" key:

[nvi] Please enter your unique API key: 

Then, you'll be asked to select a project. Input a corresponding number and press the "Enter" key:

[nvi] Retrieved the following projects from the nvi API...
[1]: my_project
[2]: my_project_2
[3]: my_project_3
[4]: my_project_4
[5]: my_project_5

Please select one of the projects by providing its corresponding [number]:

Then, you'll be asked to select an environment. Input a corresponding number and press the "Enter" key:

[nvi] Retrieved the following environments from the nvi API...
[1]: my_environment_1
[2]: my_environment_2

Please select one of the environments by providing its corresponding [number]:

If no error is displayed in the terminal, then a child process should be spawned with the command OR ENVs will be printed to standard out as stringified JSON.

How do I save remote ENVs?

See prerequisite.

Retrieving and saving remote ENVs using the nvi CLI tool, input the following:

  • "--api" flag followed by a space
  • optional "--project" flag followed by a space and then the name of the project you've created
  • optional "--environment" flag followed by a space and then the name of the environment you've created
  • a "--save" flag
nvi --api --project my_project --environment development --save

Then, you'll be asked for your API key‡. Input your API key and press the "Enter" key:

[nvi] Please enter your unique API key: 

If an .env file already exists with that environment name, then you'll be greeted with a prompt:

[nvi] WARNING: A file named "development.env" already exists at the current path ("/home/[user]/[current_directory]").
[nvi] Are you sure you want to save and overwrite it? (y|N): 

If you insert y, Y, yes or Yes and press the "Enter" key OR the file doesn't exist, then it'll save (and overwrite) the file:

[nvi] (Logger::Api::SAVED_ENV_FILE) Successfully saved the "development.env" file to disk (/home/[user]/[current_directory]/development.env).

‡ You can bypass this step by creating a .nvi-key file at the project root directory that includes your unique API key. Be mindful, that this file MUST be added to your .gitignore!