infisical icon indicating copy to clipboard operation
infisical copied to clipboard

[CLI] export secrets based on project name

Open Andarius opened this issue 2 years ago • 3 comments

Feature description

For now, when trying to export secrets locally, we must first run infisical init and then manually select the project.

It would be nice if we could just pass the project name to the export command so that we could run

infisical export --project-name="example-project" --env=prod --format=json > secrets.json

Why would it be useful?

It would allow to run the following when setting up multiple projects at once:

#!/usr/bin/env bash

readonly PROJECTS=(
  proj-1
  proj-2
)

declare -A ENVFILES=(
  ["proj-1"]=".env.proj1"
  ["proj-2"]=".env.proj2"
)


for project in "${PROJECTS[@]}"; do
  _env_file=${ENVFILES[$project]}
  echo "Exporting '$project' to $_env_file"
  infisical export --project-name="$project" --env="stg" --format=dotenv > "$_env_file"
done

Andarius avatar Feb 15 '23 17:02 Andarius

Great suggestion, I will let you know when we are able to pick this up in our sprint!

maidul98 avatar Feb 20 '23 20:02 maidul98

It looks like one or more projects can have the same name currently. Since this is already the standard, I think the easiest option is to do it by projectId. What do you think about a flag to specify the project ID?

maidul98 avatar Feb 23 '23 05:02 maidul98

Yes that would work too :)

Andarius avatar Feb 23 '23 07:02 Andarius

You can add --projectId to the export command in the latest version of the CLI! Let us know if things are working on your end.

maidul98 avatar Mar 02 '23 21:03 maidul98

Hey @maidul98, sorry for the late answer. I tried the following command but it's asking to connect to a project.

infisical export --env=stg --format=dotenv --projectId=***********

It looks you have not yet connected this project to Infisical
To do so, run [infisical init] then run your command again

I'm not sure why it's asking since I'm passing the ID in the command.

Andarius avatar Mar 08 '23 09:03 Andarius

I'll take another look at this and get back to you

maidul98 avatar Mar 08 '23 19:03 maidul98

Hey @maidul98, do you have any news on this issue ?

Andarius avatar Mar 23 '23 12:03 Andarius

Hey @Andarius the issue is occurring because for none service token fetch, the code still requires a workspace file. As a temporary work around, you can run infisical init and then use the --projectID which will override the project id in the .infisical.json.

I will need some time to see how we can re format the current workflow so that it doesn't require the file for none service token use cases. Let me know if the work around is working for you.

maidul98 avatar Mar 23 '23 15:03 maidul98