diff --git a/.env.example b/.env.example index f4050f4..c010d1e 100644 --- a/.env.example +++ b/.env.example @@ -17,4 +17,5 @@ CRED_STATUS_REPO_NAME=credential-status-test-jc CRED_STATUS_REPO_ID=12345678 # only required when CRED_STATUS_SERVICE = 'gitlab' CRED_STATUS_META_REPO_NAME=credential-status-metadata-test-jc CRED_STATUS_META_REPO_ID=87654321 # only required when CRED_STATUS_SERVICE = 'gitlab' -CRED_STATUS_ACCESS_TOKEN=REPLACE_THIS_WITH_A_GITHUB_ACCESS_TOKEN +CRED_STATUS_REPO_ACCESS_TOKEN=REPLACE_THIS_WITH_A_GITHUB_ACCESS_TOKEN +CRED_STATUS_META_REPO_ACCESS_TOKEN=REPLACE_THIS_WITH_A_GITHUB_ACCESS_TOKEN diff --git a/README.md b/README.md index 0c61290..1c347f9 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,8 @@ This service provides support for managing credential status in a variety of Git | \* `CRED_STATUS_REPO_ID` | ID of the status credential repository | string | yes if `CRED_STATUS_SERVICE` = `gitlab` | | \* `CRED_STATUS_META_REPO_NAME` | name of the credential status metadata repository | string | yes | | \* `CRED_STATUS_META_REPO_ID` | ID of the credential status metadata repository | string | yes if `CRED_STATUS_SERVICE` = `gitlab` | -| `CRED_STATUS_ACCESS_TOKEN` | access token for the credential status repositories | string | yes | +| `CRED_STATUS_REPO_ACCESS_TOKEN` | access token for the status credential repository | string | yes | +| `CRED_STATUS_META_REPO_ACCESS_TOKEN` | access token for the credential status metadata repository | string | yes | | `CRED_STATUS_DID_SEED` | seed used to deterministically generate DID | string | yes | | `PORT` | HTTP port on which to run the express app | number | no (default: `4008`) | | `ENABLE_ACCESS_LOGGING` | whether to enable access logging (see [Logging](#logging)) | boolean | no (default: `true`) | diff --git a/server.js b/server.js index dc2a5d7..32cd356 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ import { build } from './src/app.js'; import { getConfig } from './src/config.js'; +import fs from 'fs'; import http from 'http'; import https from 'https'; import logger from './src/utils/logger.js'; diff --git a/src/config.js b/src/config.js index 7c98b48..5ae4a4e 100644 --- a/src/config.js +++ b/src/config.js @@ -8,24 +8,26 @@ export function setConfig() { CONFIG = parseConfig(); } -function getBooleanValue(value) { +function getBooleanValue(value, defaultValue=true) { value = value?.toLocaleLowerCase(); if ( value === 'true' || - value === '1' || + value === 't' || value === 'yes' || - value === 'y' + value === 'y' || + value === '1' ) { return true; } else if ( value === 'false' || - value === '0' || + value === 'f' || value === 'no' || - value === 'n' + value === 'n' || + value === '0' ) { return false; } - return true; + return defaultValue; } function getGeneralEnvs(env) { @@ -44,7 +46,8 @@ function getGeneralEnvs(env) { function getGitHubEnvs(env) { return { - credStatusAccessToken: env.CRED_STATUS_ACCESS_TOKEN, + credStatusRepoAccessToken: env.CRED_STATUS_REPO_ACCESS_TOKEN, + credStatusMetaRepoAccessToken: env.CRED_STATUS_META_REPO_ACCESS_TOKEN, credStatusRepoName: env.CRED_STATUS_REPO_NAME, credStatusMetaRepoName: env.CRED_STATUS_META_REPO_NAME, credStatusOwnerAccountName: env.CRED_STATUS_REPO_OWNER diff --git a/src/status.js b/src/status.js index 0d030e5..a85632b 100644 --- a/src/status.js +++ b/src/status.js @@ -8,7 +8,8 @@ const { credStatusMetaRepoName, credStatusMetaRepoId, credStatusOwnerAccountName, - credStatusAccessToken, + credStatusRepoAccessToken, + credStatusMetaRepoAccessToken, credStatusDidSeed } = getConfig(); @@ -20,8 +21,8 @@ async function createGitHubStatusManager() { repoName: credStatusRepoName, metaRepoName: credStatusMetaRepoName, ownerAccountName: credStatusOwnerAccountName, - repoAccessToken: credStatusAccessToken, - metaRepoAccessToken: credStatusAccessToken, + repoAccessToken: credStatusRepoAccessToken, + metaRepoAccessToken: credStatusMetaRepoAccessToken, didMethod: 'key', didSeed: credStatusDidSeed, // This is the already the default value, @@ -41,8 +42,8 @@ async function createGitLabStatusManager() { metaRepoName: credStatusMetaRepoName, metaRepoId: credStatusMetaRepoId, ownerAccountName: credStatusOwnerAccountName, - repoAccessToken: credStatusAccessToken, - metaRepoAccessToken: credStatusAccessToken, + repoAccessToken: credStatusRepoAccessToken, + metaRepoAccessToken: credStatusMetaRepoAccessToken, didMethod: 'key', didSeed: credStatusDidSeed, // This is the already the default value, diff --git a/src/test-fixtures/.env.testing b/src/test-fixtures/.env.testing index 198fca7..f2408e3 100644 --- a/src/test-fixtures/.env.testing +++ b/src/test-fixtures/.env.testing @@ -5,7 +5,8 @@ CRED_STATUS_SERVICE=github CRED_STATUS_REPO_OWNER=jchartrand CRED_STATUS_REPO_NAME=status-test-three CRED_STATUS_META_REPO_NAME=status-test-meta-three -CRED_STATUS_ACCESS_TOKEN= +CRED_STATUS_REPO_ACCESS_TOKEN= +CRED_STATUS_META_REPO_ACCESS_TOKEN= CRED_STATUS_DID_SEED=z1AackbUm8U69ohKnihoRRFkXcXJd4Ra1PkAboQ2ZRy1ngB ERROR_LOG_FILE=logs/error.log