Skip to content

Commit

Permalink
fix: add needed env variables for local testing (#227)
Browse files Browse the repository at this point in the history
My local env was not working and after digging through the dev
deployment to find out what was going on, noticed that there were no
docs for the Delegations Bucket, so added it now.

Also ended up adding a validation for the environment
  • Loading branch information
vasco-santos authored Sep 15, 2023
1 parent 3756f02 commit cbfa157
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
EIPFS_INDEXER_SQS_ARN = 'arn:aws:sqs:us-west-2:505595374361:staging-ep-indexer-topic'
EIPFS_INDEXER_SQS_URL = 'https://sqs.us-west-2.amazonaws.com/505595374361/staging-ep-indexer-topic'

ACCESS_SERVICE_DID = ''
PROVIDERS = ''
UPLOAD_API_DID = ''
ACCESS_SERVICE_URL = ''
POSTMARK_TOKEN = ''
Expand All @@ -26,6 +26,7 @@ R2_REGION = ''
R2_SATNAV_BUCKET_NAME = ''
R2_SECRET_ACCESS_KEY = ''
R2_UCAN_BUCKET_NAME = ''
R2_DELEGATION_BUCKET_NAME = ''
SATNAV_BUCKET_NAME = ''

# Following variables are only required to run integration tests
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ The root domain to deploy the w3up API to. e.g `up.web3.storage`. The value shou

The domain to deploy the roundabout API to. e.g `roundabout.web3.storage`. The value should match a hosted zone configured in route53 that your aws account has access to.

#### `ACCESS_SERVICE_DID`

DID of the w3access service.

#### `ACCESS_SERVICE_URL`

URL of the w3access service.
Expand Down Expand Up @@ -140,6 +136,14 @@ Bucket name to replicate written .idx files.

Bucket name to replicate root CID to car CIDs mapping.

#### `R2_DELEGATION_BUCKET_NAME`

Bucket name where delegations are stored.

#### `PROVIDERS`

A comma-separated string of ServiceDIDs in use.

#### `SENTRY_DSN`

Data source name for Sentry application monitoring service.
Expand Down
1 change: 0 additions & 1 deletion stacks/upload-api-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function UploadApiStack({ stack, app }) {
VERSION: pkg.version,
COMMIT: git.commmit,
STAGE: stack.stage,
ACCESS_SERVICE_DID: process.env.ACCESS_SERVICE_DID ?? '',
ACCESS_SERVICE_URL: process.env.ACCESS_SERVICE_URL ?? '',
POSTMARK_TOKEN: process.env.POSTMARK_TOKEN ?? '',
PROVIDERS: process.env.PROVIDERS ?? '',
Expand Down
69 changes: 48 additions & 21 deletions upload-api/functions/ucan-invocation-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { createSubscriptionTable } from '../tables/subscription.js'
import { createConsumerTable } from '../tables/consumer.js'
import { createRateLimitTable } from '../tables/rate-limit.js'
import { createSpaceMetricsTable } from '../tables/space-metrics.js'
import { mustGetEnv } from './utils.js'

Sentry.AWSLambda.init({
environment: process.env.SST_STAGE,
Expand Down Expand Up @@ -80,28 +81,28 @@ const codec = Codec.inbound({
*/
export async function ucanInvocationRouter(request) {
const {
STORE_TABLE_NAME: storeTableName = '',
STORE_BUCKET_NAME: storeBucketName = '',
UPLOAD_TABLE_NAME: uploadTableName = '',
CONSUMER_TABLE_NAME: consumerTableName = '',
SUBSCRIPTION_TABLE_NAME: subscriptionTableName = '',
DELEGATION_TABLE_NAME: delegationTableName = '',
SPACE_METRICS_TABLE_NAME: spaceMetricsTableName = '',
RATE_LIMIT_TABLE_NAME: rateLimitTableName = '',
R2_ENDPOINT: r2DelegationBucketEndpoint = '',
R2_ACCESS_KEY_ID: r2DelegationBucketAccessKeyId = '',
R2_SECRET_ACCESS_KEY: r2DelegationBucketSecretAccessKey = '',
R2_DELEGATION_BUCKET_NAME: r2DelegationBucketName = '',
INVOCATION_BUCKET_NAME: invocationBucketName = '',
TASK_BUCKET_NAME: taskBucketName = '',
WORKFLOW_BUCKET_NAME: workflowBucketName = '',
UCAN_LOG_STREAM_NAME: streamName = '',
POSTMARK_TOKEN: postmarkToken = '',
PROVIDERS: providers = '',
storeTableName,
storeBucketName,
uploadTableName,
consumerTableName,
subscriptionTableName,
delegationTableName,
spaceMetricsTableName,
rateLimitTableName,
r2DelegationBucketEndpoint,
r2DelegationBucketAccessKeyId,
r2DelegationBucketSecretAccessKey,
r2DelegationBucketName,
invocationBucketName,
taskBucketName,
workflowBucketName,
streamName,
postmarkToken,
providers,
// set for testing
DYNAMO_DB_ENDPOINT: dbEndpoint,
ACCESS_SERVICE_URL: accessServiceURL = '',
} = process.env
dbEndpoint,
accessServiceURL,
} = getLambdaEnv()

if (request.body === undefined) {
return {
Expand Down Expand Up @@ -232,3 +233,29 @@ export const fromLambdaRequest = (request) => ({
headers: /** @type {Record<string, string>} */ (request.headers),
body: Buffer.from(request.body || '', 'base64'),
})

function getLambdaEnv () {
return {
storeTableName: mustGetEnv('STORE_TABLE_NAME'),
storeBucketName: mustGetEnv('STORE_BUCKET_NAME'),
uploadTableName: mustGetEnv('UPLOAD_TABLE_NAME'),
consumerTableName: mustGetEnv('CONSUMER_TABLE_NAME'),
subscriptionTableName: mustGetEnv('SUBSCRIPTION_TABLE_NAME'),
delegationTableName: mustGetEnv('DELEGATION_TABLE_NAME'),
spaceMetricsTableName: mustGetEnv('SPACE_METRICS_TABLE_NAME'),
rateLimitTableName: mustGetEnv('RATE_LIMIT_TABLE_NAME'),
r2DelegationBucketEndpoint: mustGetEnv('R2_ENDPOINT'),
r2DelegationBucketAccessKeyId: mustGetEnv('R2_ACCESS_KEY_ID'),
r2DelegationBucketSecretAccessKey: mustGetEnv('R2_SECRET_ACCESS_KEY'),
r2DelegationBucketName: mustGetEnv('R2_DELEGATION_BUCKET_NAME'),
invocationBucketName: mustGetEnv('INVOCATION_BUCKET_NAME'),
taskBucketName: mustGetEnv('TASK_BUCKET_NAME'),
workflowBucketName: mustGetEnv('WORKFLOW_BUCKET_NAME'),
streamName: mustGetEnv('UCAN_LOG_STREAM_NAME'),
postmarkToken: mustGetEnv('POSTMARK_TOKEN'),
providers: mustGetEnv('PROVIDERS'),
accessServiceURL: mustGetEnv('ACCESS_SERVICE_URL'),
// set for testing
dbEndpoint: process.env.DYNAMO_DB_ENDPOINT,
}
}
9 changes: 9 additions & 0 deletions upload-api/functions/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @param {string} name
* @returns {string}
*/
export function mustGetEnv (name) {
const value = process.env[name]
if (!value) throw new Error(`Missing env var: ${name}`)
return value
}

0 comments on commit cbfa157

Please sign in to comment.