Skip to content

Commit

Permalink
ddn run jwt-gen (#111)
Browse files Browse the repository at this point in the history
* Created a new ddn run script that invokes the jwt gen tool from the command line. Docs are in the readme of the jwt scripts folder.

* Rectifies automatic provisioning of AWS servers by opening port 8788 and
sending the right gql url to each server for the restified plugin to talk back

* refines .gitignore

---------

Co-authored-by: Jesse Martin <[email protected]>
Co-authored-by: Adam Malone <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2025
1 parent 67c7de8 commit d888a06
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Node.js
node_modules/
npm-debug.log
yarn-error.log
package-lock.json
yarn.lock
.npm
.eslintcache
.node_repl_history
.yarn-integrity

# 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/

# Environment
.env
.env.*
5 changes: 2 additions & 3 deletions hasura/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
engine/build
/engine/build
/.env*
/.data/.env*
node_modules
./compose.yaml
/compose.yaml
5 changes: 4 additions & 1 deletion hasura/.hasura/context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ definition:
powershell: ./scripts/ddn-run/docker-start.ps1 -Context $CONTEXT
docker-stop:
bash: ../scripts/ddn-run/docker-stop.sh
powershell: ./scripts/ddn-run/docker-stop.ps1
powershell: ./scripts/ddn-run/docker-stop.ps1
jwt-gen:
bash: node ../scripts/jwt/jwt.mjs
powershell: node ../scripts/jwt/jwt.mjs
4 changes: 4 additions & 0 deletions infra/ansible/playbooks/axiom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
file: ../.env
name: env_vars

- name: Override RESTIFIED_GRAPHQL_SERVER_URL based on server
ansible.builtin.set_fact:
restified_graphql_server_url: "{{ hostvars[inventory_hostname]['graphql_url'] | default(' http://local.hasura.dev:3280/graphql') }}"

- name: Setup environment variables from Ansible -> Docker
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/env_vars.j2"
Expand Down
11 changes: 8 additions & 3 deletions infra/ansible/playbooks/templates/env_vars.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{% for key, value in env_vars.items() %}
{{ key }}={{ value | quote if value | regex_search('[:#= ]') else value }}
{% endfor %}
CONTAINER_PREFIX={{ env_vars.CONTAINER_PREFIX }}
MONGO_PASSWORD={{ env_vars.MONGO_PASSWORD }}
POSTGRES_PASSWORD={{ env_vars.POSTGRES_PASSWORD }}
CLICKHOUSE_PASSWORD={{ env_vars.CLICKHOUSE_PASSWORD }}
CACHING_PLUGIN_SECRET={{ env_vars.CACHING_PLUGIN_SECRET }}
CACHING_PLUGIN_REDIS_URL={{ env_vars.CACHING_PLUGIN_REDIS_URL }}
RESTIFIED_PLUGIN_SECRET={{ env_vars.RESTIFIED_PLUGIN_SECRET }}
RESTIFIED_GRAPHQL_SERVER_URL={{ restified_graphql_server_url }}
2 changes: 1 addition & 1 deletion infra/aws/create-axiom-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ INSTANCE_TYPE="t2.medium"
VOLUME_SIZE=25
SG_NAME="presales-sg"
SG_DESCRIPTION="presales sg with required ports"
PORTS=(22 80 443 5432 5433 8123 8787 9000 27017)
PORTS=(22 80 443 5432 5433 8123 8787 8788 9000 27017)

# Generate the key name based on region and date
DATETIME=$(date +%Y%m%d-%H%M%S)
Expand Down
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
2 changes: 1 addition & 1 deletion scripts/jwt/jwt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ program
const options = program.opts();
const roles = options.roles ? options.roles.split(',') : ['customer'];
const userId = options.userId ? options.userId : 7;
const context = options.context || 'axiom-dev';
const context = options.context || 'telco-dev';

const contextDir = path.resolve(__dirname, '../../hasura/.hasura');
const contextData = yaml.load(fs.readFileSync(`${contextDir}/context.yaml`, 'utf8'));
Expand Down

0 comments on commit d888a06

Please sign in to comment.