Skip to content

Add "security" commands to api CLI#9400

Merged
rijkvanzanten merged 16 commits intodirectus:mainfrom
danilopolani:feat/cli-security-commands
Jul 20, 2022
Merged

Add "security" commands to api CLI#9400
rijkvanzanten merged 16 commits intodirectus:mainfrom
danilopolani:feat/cli-security-commands

Conversation

@danilopolani
Copy link
Copy Markdown
Contributor

@danilopolani danilopolani commented Nov 3, 2021

This PR implements two new CLI commands. I thought they could be useful especially when cloning a project and, of course, you have to setup your own .env file or when deploying on production and need to setup the environment variables.

Key generation

It generates the KEY variable. You can additionally use the --show flag to avoid the .env overwrite and just display it in the terminal.

$ npx directus security key:generate
# App key set correctly.

$ npx directus security key:generate --show
# Your new app key: 9a30bf49-946c-430c-83fc-eaefce5673c3

Secret generation

It generates the SECRET variable. You can additionally use the --show flag to avoid the .env overwrite and just display it in the terminal.

$ npx directus security secret:generate
# App secret set correctly.

$ npx directus security secret:generate --show
# Your new app secret: Ypzy1c2O3tcvpP_1c7uT4Dhl-liOub8S

Both commands will fail if no .env file is found in the cwd and the flag --show is omitted:

image


Notes: I named them like this because I'm used to Laravel key:generate --show command, but let me know if you'd prefer another name or if we should group them under a security group, like commands under the users group etc.

@benhaynes
Copy link
Copy Markdown
Member

We can wait until this change is approved, but we'll need to make sure docs are also added as part of this PR.

@danilopolani
Copy link
Copy Markdown
Contributor Author

We can wait until this change is approved, but we'll need to make sure docs are also added as part of this PR.

Right! I totally forgot the docs, sorry, I'm going to work on it later today

@danilopolani
Copy link
Copy Markdown
Contributor Author

danilopolani commented Nov 3, 2021

A few updates:

  1. The two commands are now grouped under the security group, like databases commands and so on;
  2. I've updated the documentation, feel free to edit any paragraph since english it's not my native language 😄
  3. I've added an alert in the installation page about the generation of a fresh token when deploying, let me know if you'd prefer to remove it:

image


Oh, and the HubSpot js code was - for some reason - embedded two times in some page and I had to remove the duplicates because Vue was complaining about multiple root elements

@rijkvanzanten rijkvanzanten changed the title [Feat] Add "security" commands to api CLI Add "security" commands to api CLI Nov 3, 2021
@danilopolani
Copy link
Copy Markdown
Contributor Author

Ok, at the end I removed the feature to automatically update the .env with generated values because it would be a pain to develop and maintain support for YAML, JSON and every variation of them

@rijkvanzanten rijkvanzanten added this to the Next Release milestone Jul 20, 2022
@rijkvanzanten rijkvanzanten self-assigned this Jul 20, 2022
@rijkvanzanten rijkvanzanten merged commit 8b116f6 into directus:main Jul 20, 2022
qborisb pushed a commit to qdentity/directus that referenced this pull request Jul 22, 2022
* add command to generate app key

* add command to generate secret

* group security commands under the security group

* add new security commands to cli docs

* add disclaimer on deploy secret generation

* remove duplicate hubspot embed code

* remove .env overwrite feature to security commands

* update the cli docs for security commands

* return key generation directly in output

* restore package-lock.json

* Write secret directly

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants