Skip to content

Commit

Permalink
feat(env): add and document env-var ADMIN_API_KEY_FILE
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli authored and djwhitt committed Jan 2, 2025
1 parent 3cdac7e commit 8b14d4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@
# Arweave wallet address used for staking and rewards
# AR_IO_WALLET=""

# Admin key used for accessing the admin API
# Admin key value used for accessing the admin API
# ADMIN_API_KEY="secret"

# Alternatively use filepath to admin key used for accessing the admin API
# it takes precedence over ADMIN_API_KEY
# ADMIN_API_KEY_FILE="/path/to/admin-key.txt"

# If true, ar.io node will start indexing missing bundles
# BACKFILL_BUNDLE_RECORDS=false

Expand Down
1 change: 1 addition & 0 deletions docs/envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This document describes the environment variables that can be used to configure
| SIMULATED_REQUEST_FAILURE_RATE | Number | 0 | Number from 0 to 1, representing the probability of a request failing |
| AR_IO_WALLET | String | "" | Arweave wallet address used for staking and rewards |
| ADMIN_API_KEY | String | Generated | API key used for admin API requests (if not set, it's generated and logged into the console) |
| ADMIN_API_KEY_FILE | String | Generated | Alternative way to set the API key used for admin API requests via filepath, it takes precedene over ADMIN_API_KEY if defined |
| BACKFILL_BUNDLE_RECORDS | Boolean | false | If true, ar.io node will start indexing missing bundles |
| FILTER_CHANGE_REPROCESS | Boolean | false | If true, all indexed bundles will be reprocessed with the new filters (you can use this when you change the filters) |
| ON_DEMAND_RETRIEVAL_ORDER | String | s3,trusted-gateways,chunks,tx-data | Data source retrieval order for on-demand data requests |
Expand Down
14 changes: 13 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
import { canonicalize } from 'json-canonicalize';
import { isMainThread } from 'node:worker_threads';
import { existsSync, readFileSync } from 'node:fs';

import { createFilter } from './filters.js';
import * as env from './lib/env.js';
Expand All @@ -31,10 +32,21 @@ export const PORT = +env.varOrDefault('PORT', '4000');

// API key for accessing admin HTTP endpoints
// It's set once in the main thread
export const ADMIN_API_KEY = isMainThread
export let ADMIN_API_KEY = isMainThread
? env.varOrRandom('ADMIN_API_KEY')
: undefined;

const ADMIN_API_KEY_FILE = isMainThread
? env.varOrUndefined('ADMIN_API_KEY_FILE')
: undefined;

if (ADMIN_API_KEY_FILE !== undefined) {
if (!existsSync(ADMIN_API_KEY_FILE)) {
throw new Error(`ADMIN_API_KEY_FILE not found: ${ADMIN_API_KEY_FILE}`);
}
ADMIN_API_KEY = readFileSync(ADMIN_API_KEY_FILE).toString().trim();
}

//
// Nodes
//
Expand Down

0 comments on commit 8b14d4d

Please sign in to comment.