Skip to content

Commit

Permalink
adds env var for meta repo; modifies getBooleanValue implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kezike committed May 1, 2024
1 parent e01f702 commit 1cd50d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`) |
Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
17 changes: 10 additions & 7 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
credStatusMetaRepoName,
credStatusMetaRepoId,
credStatusOwnerAccountName,
credStatusAccessToken,
credStatusRepoAccessToken,
credStatusMetaRepoAccessToken,
credStatusDidSeed
} = getConfig();

Expand All @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/test-fixtures/.env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1cd50d1

Please sign in to comment.