Skip to content

Commit

Permalink
configures database and table names for db status manager; enables st…
Browse files Browse the repository at this point in the history
…atus credential retrieval for all status managers
  • Loading branch information
kezike committed Mar 1, 2024
1 parent 5c58314 commit 39e527d
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 40 deletions.
9 changes: 7 additions & 2 deletions .env.db.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ STATUS_CRED_SITE_ORIGIN=https://credentials.example.edu
CRED_STATUS_DB_URL=mongodb+srv://user:[email protected]?retryWrites=false
CRED_STATUS_DB_HOST=domain.mongodb.net # ignored if CRED_STATUS_DB_URL is configured
CRED_STATUS_DB_PORT=27017 # ignored if CRED_STATUS_DB_URL is configured
CRED_STATUS_DB_USER=user # ignored if CRED_STATUS_DB_URL is configured
CRED_STATUS_DB_PASS=pass # ignored if CRED_STATUS_DB_URL is configured
CRED_STATUS_DB_USER=testuser # ignored if CRED_STATUS_DB_URL is configured
CRED_STATUS_DB_PASS=testpass # ignored if CRED_STATUS_DB_URL is configured
CRED_STATUS_DB_NAME=
STATUS_CRED_TABLE_NAME=
CONFIG_TABLE_NAME=
EVENT_TABLE_NAME=
CRED_EVENT_TABLE_NAME=
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ There is a sample `.env` file provided called `.env.db.example` to help you get

| Key | Description | Default | Required |
| --- | --- | --- | --- |
| \* `STATUS_CRED_SITE_ORIGIN` | Base URL of status credentials managed by this service | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true |
| `CRED_STATUS_DB_URL` | URL of the database instance used to manage the credential status repository | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if the other set of `CRED_STATUS_DB_*` fields are not set |
| `CRED_STATUS_DB_HOST` | host of the database instance used to manage the credential status repository | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| `CRED_STATUS_DB_PORT` | port of the database instance used to manage the credential status repository | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| `CRED_STATUS_DB_USER` | username of user with read/write privileges on the database instance used to manage the credential status repository | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| \* `STATUS_CRED_SITE_ORIGIN` | base URL of status credentials managed by a given deployment | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true |
| `CRED_STATUS_DB_URL` | URL of the database instance used to manage credential status data | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if the other set of `CRED_STATUS_DB_*` fields are not set |
| `CRED_STATUS_DB_HOST` | host of the database instance used to manage credential status data | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| `CRED_STATUS_DB_PORT` | port of the database instance used to manage credential status data | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| `CRED_STATUS_DB_USER` | username of user with read/write privileges on the database instance used to manage credential status data | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| `CRED_STATUS_DB_PASS` | password associated with `CRED_STATUS_DB_USER` | N/A | yes if `ENABLE_STATUS_ALLOCATION` is true and if `CRED_STATUS_DB_URL` is not set |
| `CRED_STATUS_DB_NAME` | name of the database instance used to manage credential status data | `credentialStatus` | no |
| `STATUS_CRED_TABLE_NAME` | name of the database table used to manage status credentials | `StatusCredential` | no |
| `CONFIG_TABLE_NAME` | name of the database table used to manage application configuration | `Config` | no |
| `EVENT_TABLE_NAME` | name of the database table used to manage credential status events | `Event` | no |
| `CRED_EVENT_TABLE_NAME` | name of the database table used to manage the latest status event for a given credential | `CredentialEvent` | no |

\* In order for credential status verification to work, you will need to use a publicly accessible URL for `STATUS_CRED_SITE_ORIGIN`, so that the verifier can access the status data. If you would like to spin up this service at a public URL, consider using a traffic forwarding tool like [localtunnel](https://www.npmjs.com/package/localtunnel). Once you have installed it, follow these simple steps to run the service:
1. Run `lt --port $PORT`
Expand Down Expand Up @@ -225,7 +230,7 @@ NOTE: CURL can get a bit clunky if you want to experiment more (like say by chan

### Revoke

Revocation is fully explained in the StatusList2021 specifivation and the git status repo implemenation but amounts to POSTing an object to the revocation endpoint, like so:
Revocation is fully explained in the Status List 2021 specification and the git status repo implemenation but amounts to POSTing an object to the revocation endpoint, like so:

```
{credentialId: '23kdr', credentialStatus: [{type: 'StatusList2021Credential', status: 'revoked'}]}
Expand Down
10 changes: 5 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { build } from './src/app.js'
import { getConfig, setConfig } from "./src/config.js";
import http from "http"
import { getConfig, setConfig } from './src/config.js';
import http from 'http';

const run = async () => {
await setConfig()
const { port, enableHttpsForDev } = getConfig();
const { port } = getConfig();
const app = await build();
http.createServer(app).listen(port, () => console.log(`Server running on port ${port}`))
http.createServer(app).listen(port, () => console.log(`Server running on port ${port}`));
};

run();
run();
15 changes: 4 additions & 11 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import express from 'express';
import logger from 'morgan';
import cors from 'cors';
import { getConfig } from './config.js';
import status from './status.js';
import revoke from './revoke.js'
import allocateStatus from './allocateStatus.js'
Expand All @@ -11,8 +9,6 @@ import errorLogger from './middleware/errorLogger.js';
import invalidPathHandler from './middleware/invalidPathHandler.js';

export async function build(opts = {}) {
const { credStatusService } = getConfig();

await status.initializeStatusManager();

const app = express();
Expand All @@ -29,9 +25,6 @@ export async function build(opts = {}) {

// get status credential
app.get('/:statusCredentialId', async (req, res, next) => {
if (credStatusService !== 'mongodb') {
return null;
}
const statusCredentialId = req.params.statusCredentialId;
try {
const statusCredential = await status.getStatusCredential(statusCredentialId);
Expand Down Expand Up @@ -104,10 +97,10 @@ export async function build(opts = {}) {
}
});

// Attach the error handling middleware calls, in the order that they should run
app.use(errorLogger);
app.use(errorHandler);
app.use(invalidPathHandler);
// Attach the error handling middleware calls, in the order that they should run
app.use(errorLogger);
app.use(errorHandler);
app.use(invalidPathHandler);

return app;
}
9 changes: 7 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ function getGeneralEnvs() {
function getMongoDbEnvs() {
const env = process.env;
return {
statusCredentialSiteOrigin: env.STATUS_CRED_SITE_ORIGIN,
statusCredSiteOrigin: env.STATUS_CRED_SITE_ORIGIN,
credStatusDatabaseUrl: env.CRED_STATUS_DB_URL,
credStatusDatabaseHost: env.CRED_STATUS_DB_HOST,
credStatusDatabasePort: env.CRED_STATUS_DB_PORT,
credStatusDatabaseUsername: env.CRED_STATUS_DB_USER,
credStatusDatabasePassword: env.CRED_STATUS_DB_PASS
credStatusDatabasePassword: env.CRED_STATUS_DB_PASS,
credStatusDatabaseName: env.CRED_STATUS_DB_NAME,
statusCredTableName: env.STATUS_CRED_TABLE_NAME,
configTableName: env.CONFIG_TABLE_NAME,
eventTableName: env.EVENT_TABLE_NAME,
credEventTableName: env.CRED_EVENT_TABLE_NAME
};
}

Expand Down
50 changes: 36 additions & 14 deletions src/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import { getConfig } from './config.js';

const {
// Database env vars
statusCredentialSiteOrigin,
statusCredSiteOrigin,
credStatusDatabaseUrl,
credStatusDatabaseHost,
credStatusDatabasePort,
credStatusDatabaseUsername,
credStatusDatabasePassword,
credStatusDatabaseName,
statusCredTableName,
configTableName,
eventTableName,
credEventTableName,

// Git env vars
credStatusService,
Expand All @@ -30,38 +35,54 @@ let STATUS_LIST_MANAGER;

async function createDatabaseStatusManager() {
return createStatusManagerDb({
statusCredentialSiteOrigin,
statusCredentialSiteOrigin: statusCredSiteOrigin,
databaseService: credStatusService,
databaseUrl: credStatusDatabaseUrl,
databaseHost: credStatusDatabaseHost,
databasePort: credStatusDatabasePort,
databaseUsername: credStatusDatabaseUsername,
databasePassword: credStatusDatabasePassword,
databaseName: credStatusDatabaseName,
statusCredentialTableName: statusCredTableName,
configTableName,
eventTableName,
credentialEventTableName: credEventTableName,
didMethod: 'key',
didSeed: credStatusDidSeed,
signUserCredential: false,
signStatusCredential: true
// This is the already the default value,
// but setting here to be explicit
autoDeployDatabase: true,
// This is the already the default value,
// but setting here to be explicit
signStatusCredential: true,
// This is the already the default value,
// but setting here to be explicit
signUserCredential: false
});
}

async function createGitHubStatusManager() {
return createStatusManagerGit({
service: credStatusService,
gitService: credStatusService,
repoName: credStatusRepoName,
metaRepoName: credStatusMetaRepoName,
ownerAccountName: credStatusOwnerAccountName,
repoAccessToken: credStatusAccessToken,
metaRepoAccessToken: credStatusAccessToken,
didMethod: 'key',
didSeed: credStatusDidSeed,
signUserCredential: false,
signStatusCredential: true
// This is the already the default value,
// but setting here to be explicit
signStatusCredential: true,
// This is the already the default value,
// but setting here to be explicit
signUserCredential: false
});
}

async function createGitLabStatusManager() {
return createStatusManagerGit({
service: credStatusService,
gitService: credStatusService,
repoName: credStatusRepoName,
repoId: credStatusRepoId,
metaRepoName: credStatusMetaRepoName,
Expand All @@ -71,8 +92,12 @@ async function createGitLabStatusManager() {
metaRepoAccessToken: credStatusAccessToken,
didMethod: 'key',
didSeed: credStatusDidSeed,
signUserCredential: false,
signStatusCredential: true
// This is the already the default value,
// but setting here to be explicit
signStatusCredential: true,
// This is the already the default value,
// but setting here to be explicit
signUserCredential: false
});
}

Expand Down Expand Up @@ -106,11 +131,8 @@ async function getStatusManager() {
}

async function getStatusCredential(statusCredentialId) {
if (credStatusService !== 'mongodb') {
return null;
}
const statusManager = await getStatusManager();
return statusManager.getStatusCredential(statusCredentialId);
}

export default { initializeStatusManager, getStatusManager, getStatusCredential };
export default { initializeStatusManager, getStatusManager, getStatusCredential };

0 comments on commit 39e527d

Please sign in to comment.