Skip to content

Commit e5011c6

Browse files
committed
chore: update readme
1 parent c6d0942 commit e5011c6

File tree

1 file changed

+39
-85
lines changed

1 file changed

+39
-85
lines changed

README.md

Lines changed: 39 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,38 @@
33

44
## Table of contents
55

6-
- [Adonis Credentials](#adonis-credentials)
6+
- [AdonisJS Credentials](#adonisjs-credentials)
77
- [Installation](#installation)
88
- [Configuration](#configuration)
99
- [Run `ace configure`](#run-ace-configure)
10-
- [Modify `server.ts` file](#modify-serverts-file)
11-
- [Modify `.adonisrs.json`](#modify-adonisrsjson)
12-
- [Modify `ace` file (optional)](#modify-ace-file-optional)
13-
- [Pipe credentials to command (optional)](#pipe-credentials-to-command-optional)
10+
- [Modify `bin/server.ts` file](#modify-binserverts-file)
11+
- [Modify `bin/console.ts` file](#modify-binconsolets-file)
1412
- [Usage](#usage)
1513
- [Creating credentials](#creating-credentials)
1614
- [Editing credentials](#editing-credentials)
17-
- [Piping credentials](#piping-credentials)
1815
- [Using in production](#using-in-production)
1916
- [How it works](#how-it-works)
2017

2118
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2219

23-
# Adonis Credentials
20+
# AdonisJS Credentials
2421

25-
> adonis, credentials
22+
> adonisjs, adonis, credentials
2623
2724
[![workflow-image]][workflow-url] [![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
2825

29-
Adonis Credentials is created to help manage multiple environment secrets, share them securely and even keep them inside your repo.
26+
AdonisJS Credentials is created to help you manage multiple environment secrets, share them securely and even keep them inside your repo.
27+
28+
Inspired by Rails Credentials.
3029

3130
## Installation
3231

3332
To install the provider run:
3433

3534
```bash
36-
npm install @bitkidd/adonis-credentials
35+
npm install @bitkidd/adonisjs-credentials
3736
# or
38-
yarn add @bitkidd/adonis-credentials
37+
yarn add @bitkidd/adonisjs-credentials
3938
```
4039

4140
## Configuration
@@ -45,56 +44,42 @@ To configure credentials provider, we should proceed with 4 steps:
4544
#### Run `ace configure`
4645

4746
```
48-
node ace configure @bitkidd/adonis-credentials
47+
node ace configure @bitkidd/adonisjs-credentials
4948
```
5049

51-
This will add two new commands to your app and will allow to create and edit credentials.
52-
At the same time it will add a new rule to your `.gitignore` file that will exclude all `*.key` files from repository and will not allow to commit them.
53-
54-
#### Modify `server.ts` file
50+
This will:
5551

56-
As a next step you need to modify the `server.ts` file and add a new line inside it, just before the `Ignitor`:
52+
- Add two new commands to your app and will allow to create and edit credentials
53+
- Add a new rule to your `.gitignore` file that will exclude all `*.key` files from repository and will not allow to commit them
54+
- Add a new `credentials.ts` file inside `/start` folder
5755

58-
```ts
59-
// This goes on top, where import declarations are
60-
import { Credentials } from '@bitkidd/adonis-credentials/build/src/Credentials'
56+
#### Modify `bin/server.ts` file
6157

62-
// ...
58+
As a next step you need to modify the `bin/server.ts` file and add a new line inside it:
6359

64-
new Credentials().initialize() // <--- Insert credentials initialization here, before the Ignitor
65-
new Ignitor(__dirname).httpServer().start().catch(console.error)
60+
```ts
61+
...
62+
app.booting(async () => {
63+
await import('#start/env')
64+
await import('#start/credentials') // <--- Import credentials here
65+
})
66+
...
6667
```
6768

68-
This allows the credentials to be parsed and populated inside current `process.env` before the app even starts, so an `Env` provider will be able to validate values.
69-
70-
#### Modify `.adonisrs.json`
71-
72-
As a final step, open `.adonisrc.json` file and add `resources/credentials` to `metaFiles` section, so credentials will copied as you build your Adonis app.
73-
74-
#### Modify `ace` file (optional)
75-
76-
In this step you do basically the same thing as done in a step above, but for `ace` commands that need the app to be loaded, just add two new lines to the file.
69+
#### Modify `bin/console.ts` file
7770

78-
```js
79-
// ...
80-
// This goes on top, where require declarations are
81-
const { Credentials } = require('@bitkidd/adonis-credentials/build/src/Credentials')
71+
Next you need to modify the `bin/console.ts` file and add a new line inside it:
8272

83-
// ...
84-
85-
new Credentials().initialize() // <--- Insert credentials initialization here, before the Ignitor
86-
new Ignitor(__dirname).ace().handle(process.argv.slice(2)).catch(console.error)
73+
```ts
74+
...
75+
app.booting(async () => {
76+
await import('#start/env')
77+
await import('#start/credentials') // <--- Import credentials here
78+
})
79+
...
8780
```
8881

89-
This will populates credentials into the ace process so they will be available in it.
90-
91-
#### Pipe credentials to command (optional)
92-
93-
Another way to make credentials visible to command, is to run that command inside a child process with secret credentials populated, for example:
94-
95-
`node ace credentials:pipe 'ace migrations:run'`
96-
97-
This reads credentials, decrypts them, creates a child process and populates environment with some new values from your vault and then runs the command that you specified.
82+
This will allow commands and app that they will start get access to credentials.
9883

9984
## Usage
10085

@@ -107,7 +92,6 @@ As you configured the provider, you may now create your first credentials by run
10792
# ---
10893
# Flags
10994
# --env string Specify an environment for credentials file (default: development)
110-
# --format string Specify format for the credentials file (default: yaml, available: json,yaml)
11195

11296
node ace credentials:create
11397
```
@@ -116,10 +100,10 @@ This will create a new directory in your `resources` folder, called `credentials
116100

117101
Obviously, the `.key` file keeps your password to the credentials file, **do not commit any .key files to your git repo**, please check your `.gitignore` for `*.key` exclusion rule.
118102

119-
The `.key` should be kept somewhere in a secret place, the best spot I know is a sticky note on your laptop. Just NO, don't do this :see_no_evil:
103+
`.key` should be kept somewhere in a secret place, the best spot I know is a sticky note on your laptop. Just NO, don't do this :see_no_evil:
120104
Keep your secrets in a secure place and use password managers!
121105

122-
The `.credentials` file can be committed and shared as it is impossimple to decrypt it without the password.
106+
`.credentials` file can be committed and shared as it is impossible to decrypt without the key.
123107

124108
These two files should always be kept in one folder while in development.
125109

@@ -139,24 +123,9 @@ node ace credentials:edit --editor="code ---wait" --env=development
139123
node ace credentials:edit --editor=nano --env=development
140124
```
141125

142-
This will decrypt the credentials file, create a temporary one and open it in the editor you specified. As you finish editing, close the file (or tab inside your editor), this will encrypt it back again and remove the temporary file, to keep you safe and sound.
143-
144-
#### Piping credentials
145-
146-
To pipe credentials to a command that needs them run:
147-
148-
```bash
149-
# node ace credentials:pipe <command>
150-
# ---
151-
# Args
152-
# command Specify an ace command to pipe credentials to
153-
# Flags
154-
# --env string Specify an environment for credentials file (default: development)
126+
You can also add `EDITOR='code --wait'` to your `.env` file to omit `--editor` flag.
155127

156-
node ace credentials:pipe 'ace migrations:run'
157-
# or
158-
node ace credentials:pipe 'ace migrations:run' --env=development
159-
```
128+
This will decrypt the credentials file, create a temporary one and open it in the editor you specified. As you finish editing, close the file (or tab inside your editor), this will encrypt it back again and remove the temporary file, to keep you safe and sound.
160129

161130
#### Using in production
162131

@@ -170,20 +139,7 @@ For production you should set additional environment variable `APP_CREDENTIALS_K
170139

171140
The provider uses node.js' native crypto library and encrypts everything using _AES_ cipher with a random vector, which makes your secrets very secure, with a single key that can decrypt data.
172141

173-
Credentials while decrypted present themselves as simple files in JSON or YAML formats, this allows to keep variables in a very predictable and simple manner:
174-
175-
**JSON**
176-
177-
```json
178-
{
179-
"google": {
180-
"key": "your_google_key",
181-
"secret": "your_google_secret"
182-
}
183-
}
184-
```
185-
186-
**YAML**
142+
Credentials while decrypted present themselves as simple files in YAML format, this allows you to keep variables in a very predictable and simple form:
187143

188144
```yaml
189145
google:
@@ -198,8 +154,6 @@ GOOGLE_KEY=your_google_key
198154
GOOGLE_SECRET=your_google_secret
199155
```
200156

201-
And then populated to `process.env`, as this is done before Adonis.js `Env` provider, you may even validate data to be sure that everything is present and has an exact format.
202-
203157
[workflow-image]: https://img.shields.io/github/workflow/status/bitkidd/adonis-credentials/test?style=for-the-badge&logo=github
204158
[workflow-url]: https://github.com/bitkidd/adonis-credentials/actions/workflows/test.yml
205159
[npm-image]: https://img.shields.io/npm/v/@bitkidd/adonis-credentials.svg?style=for-the-badge&logo=npm

0 commit comments

Comments
 (0)