Skip to content

Commit

Permalink
Created a new ddn run script that invokes the jwt gen tool from the c…
Browse files Browse the repository at this point in the history
…ommand line. Docs are in the readme of the jwt scripts folder.
  • Loading branch information
Jesse Martin authored and Jesse Martin committed Feb 12, 2025
1 parent b2e1c81 commit b350ce2
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Node.js
node_modules/
npm-debug.log
yarn-error.log
package-lock.json
yarn.lock

# Python
__pycache__/
*.py[cod]
*.so
.Python
env/
venv/
ENV/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Go
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
/vendor/
/Godeps/

# IDEs and editors
.idea/
.vscode/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Logs and databases
*.log
*.sql
*.sqlite

# Build output
/dist/
/tmp/
/out/

# Dependency directories
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Python Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# pipenv
Pipfile.lock

# Poetry
poetry.lock

# Go workspace file
go.work

# Demo Specific

*.env.cloud.*
3 changes: 3 additions & 0 deletions hasura/.hasura/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ definition:
docker-stop:
bash: for file in compose*.yaml $(find ../.data -type f -name "compose.yaml"); do docker compose -f $file down -v; done
powershell: docker compose -f compose.yaml down -v; docker compose -f .data/compose.yaml down -v
jwt-gen:
bash: cd ../scripts/jwt && npm i && node ./jwt.mjs --env $(find ../../ -name '.env.cloud.*' -print -quit) -r customer -u 7
powershell: cd ../scripts/jwt && npm i && node ./jwt.mjs --env $(find ../../ -name '.env.cloud.*' -print -quit) -r customer -u 7
11 changes: 9 additions & 2 deletions scripts/jwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Generate a JWT token by running:
node jwt.mjs
```

### Usage as `ddn run` command

From the base hasura folder, call `ddn run jwt-gen` for a default token for user `7` as role `customer`. Pass `-u` to change user and `-r` to change role. Example:

```
ddn run jwt-gen -- -u 8 -r editor
```

### Options

- `-u, --userId <userId>`: User ID (default: `7`).
Expand All @@ -26,10 +34,10 @@ node jwt.mjs
- `-e, --env <path>`: Path to `.env` file containing `JWT_SECRET`.
- `-c, --context <context>`: Context to auto-find `.env` file defined in `.hasura/context.yaml`.


## Example

Using an alternate context from `.hasura/context.yaml`

```
node jwt.mjs -u 8 -r admin,editor -c axiom-test
```
Expand All @@ -49,7 +57,6 @@ node jwt.mjs -u 123 -r admin,editor -k "qG7zP4cZK9B5vN5fjYcLr1Jq3RZqP+R/B5fXzP3a
JWT_SECRET=qG7zP4cZK9B5vN5fjYcLr1Jq3RZqP+R/B5fXzP3aLqY= node jwt.mjs -u 123 -r admin,editor
```


## Output

The generated JWT token is printed to the console along with its decoded content.
Expand Down

0 comments on commit b350ce2

Please sign in to comment.