Skip to content

Commit

Permalink
fix(core): added missing env var definition in global defs
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Jan 30, 2020
1 parent 178ce31 commit 8e4d24c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/bp/core/services/action/action-service.ts
Expand Up @@ -7,6 +7,7 @@ import _ from 'lodash'
import ms from 'ms'
import path from 'path'
import { NodeVM } from 'vm2'
import yn from 'yn'

import { GhostService } from '..'
import { createForAction } from '../../api'
Expand Down Expand Up @@ -114,9 +115,9 @@ export class ScopedActionService {
await this.ghost.forBot(this.botId).directoryListing('actions', '*.js', exclude)
)

const actions: ActionDefinition[] = (
await Promise.map(globalActionsFiles, async file => this.getActionDefinition(file, 'global', true))
).concat(await Promise.map(localActionsFiles, async file => this.getActionDefinition(file, 'local', true)))
const actions: ActionDefinition[] = (await Promise.map(globalActionsFiles, async file =>
this.getActionDefinition(file, 'global', true)
)).concat(await Promise.map(localActionsFiles, async file => this.getActionDefinition(file, 'local', true)))

this._actionsCache = actions
return actions
Expand Down Expand Up @@ -212,7 +213,7 @@ export class ScopedActionService {
async runAction(actionName: string, incomingEvent: any, actionArgs: any): Promise<any> {
process.ASSERT_LICENSED()

if (process.core_env.BP_EXPERIMENTAL_REQUIRE_BPFS) {
if (yn(process.core_env.BP_EXPERIMENTAL_REQUIRE_BPFS)) {
await this.checkActionRequires(actionName)
}

Expand Down
10 changes: 6 additions & 4 deletions src/bp/core/services/middleware/event-engine.ts
Expand Up @@ -5,6 +5,7 @@ import { inject, injectable, tagged } from 'inversify'
import joi from 'joi'
import _ from 'lodash'
import { VError } from 'verror'
import yn from 'yn'

import { Event } from '../../sdk/impl'
import { TYPES } from '../../types'
Expand Down Expand Up @@ -78,9 +79,9 @@ const debugOutgoing = debug.sub('outgoing')

@injectable()
export class EventEngine {
public onBeforeIncomingMiddleware: ((event) => Promise<void>) | undefined
public onAfterIncomingMiddleware: ((event) => Promise<void>) | undefined
public onBeforeOutgoingMiddleware: ((event) => Promise<void>) | undefined
public onBeforeIncomingMiddleware?: (event) => Promise<void>
public onAfterIncomingMiddleware?: (event) => Promise<void>
public onBeforeOutgoingMiddleware?: (event) => Promise<void>

private readonly _incomingPerf = new TimedPerfCounter('mw_incoming')
private readonly _outgoingPerf = new TimedPerfCounter('mw_outgoing')
Expand Down Expand Up @@ -119,7 +120,7 @@ export class EventEngine {
* Usage: set `BP_DEBUG_IO` to `true`
*/
private setupPerformanceHooks() {
if (!process.env.BP_DEBUG_IO) {
if (!yn(process.env.BP_DEBUG_IO)) {
return
}

Expand Down Expand Up @@ -180,6 +181,7 @@ export class EventEngine {
}

async replyToEvent(eventDestination: sdk.IO.EventDestination, payloads: any[], incomingEventId?: string) {
// prettier-ignore
const keys: (keyof sdk.IO.EventDestination)[] = ['botId', 'channel', 'target', 'threadId']

for (const payload of payloads) {
Expand Down
3 changes: 2 additions & 1 deletion src/bp/core/services/middleware/state-manager.ts
Expand Up @@ -9,6 +9,7 @@ import Knex from 'knex'
import _ from 'lodash'
import { Memoize } from 'lodash-decorators'
import ms from 'ms'
import yn from 'yn'

import { SessionRepository, UserRepository } from '../../repositories'
import { TYPES } from '../../types'
Expand Down Expand Up @@ -41,7 +42,7 @@ export class StateManager {
@inject(TYPES.JobService) private jobService: JobService
) {
// Temporarily opt-in until thoroughly tested
this.useRedis = process.CLUSTER_ENABLED && process.env.USE_REDIS_STATE
this.useRedis = process.CLUSTER_ENABLED && yn(process.env.USE_REDIS_STATE)
}

public initialize() {
Expand Down
5 changes: 3 additions & 2 deletions src/bp/core/services/migration/index.ts
Expand Up @@ -12,6 +12,7 @@ import { Container, inject, injectable, tagged } from 'inversify'
import _ from 'lodash'
import path from 'path'
import semver from 'semver'
import yn from 'yn'

import { container } from '../../app.inversify'
import { GhostService } from '../ghost/service'
Expand Down Expand Up @@ -52,7 +53,7 @@ export class MigrationService {
const configVersion = process.env.TESTMIG_CONFIG_VERSION || (await this.configProvider.getBotpressConfig()).version
debug(`Migration Check: %o`, { configVersion, currentVersion: this.currentVersion })

if (process.env.SKIP_MIGRATIONS) {
if (yn(process.env.SKIP_MIGRATIONS)) {
debug(`Skipping Migrations`)
return
}
Expand Down Expand Up @@ -225,7 +226,7 @@ export class MigrationService {
}

private async _getCompletedMigrations(): Promise<string[]> {
if (process.env.TESTMIG_IGNORE_COMPLETED) {
if (yn(process.env.TESTMIG_IGNORE_COMPLETED)) {
return []
}

Expand Down
37 changes: 32 additions & 5 deletions src/typings/global.d.ts
Expand Up @@ -69,6 +69,15 @@ declare type BotpressEnvironmentVariables = {
/** Change the BPFS storage mechanism ("database" or "disk"). Defaults to "disk" */
readonly BPFS_STORAGE?: 'database' | 'disk'

/** The URL exposed by Botpress to external users (eg: when displaying links) */
readonly EXTERNAL_URL?: string

/** Use this to override the hostname that botpress will listen on (by default it's localhost) - replaces httpServer.host */
readonly BP_HOST?: string

/** Change the port where botpress listens. Replaces the configuration of httpServer.port */
readonly PORT?: number

/**
* The connection string for redis
* @example redis://username:password@localhost:6379
Expand Down Expand Up @@ -96,6 +105,12 @@ declare type BotpressEnvironmentVariables = {
/** Server license key */
readonly BP_LICENSE_KEY?: string

/**
* Change the host of the licensing server
* @default https://license.botpress.io
*/
readonly BP_LICENSE_SERVER_HOST?: string

/**
* Set this to true if you're exposing Botpress through a reverse proxy such as Nginx
* Read more: https://expressjs.com/en/guide/behind-proxies.html
Expand All @@ -114,6 +129,9 @@ declare type BotpressEnvironmentVariables = {
*/
readonly DEBUG?: string

/** Enable performance hooks to track incoming and outgoing events */
readonly BP_DEBUG_IO?: boolean

/**
* Overrides the auto-computed `process.APP_DATA_PATH` path
* @see Process.APP_DATA_PATH
Expand Down Expand Up @@ -156,11 +174,8 @@ declare type BotpressEnvironmentVariables = {
*/
readonly BP_FAILSAFE?: boolean

/**
* When true, it will not store/load the state from redis to speed up event processing
* Adding temporarily until the feature is battle-tested
*/
readonly BP_NO_REDIS_STATE?: boolean
/** When true, Redis will be used to keep active sessions in memory for better performances */
readonly USE_REDIS_STATE?: boolean

/**
* Experimental feature which will try to load actions locally, then from the ghost
Expand All @@ -172,6 +187,18 @@ declare type BotpressEnvironmentVariables = {
* Can give a significant performance improvement but removes some protections.
*/
readonly DISABLE_GLOBAL_SANDBOX?: boolean

/** Migration Testing: Simulate a specific version for the server, ex: 12.5.0 */
readonly TESTMIG_BP_VERSION?: string

/** Migration Testing: Simulate a specific version for the configuration file, ex: 12.4.0 */
readonly TESTMIG_CONFIG_VERSION?: string

/** Migration Testing: Set this to true to run completed migrations everytime the server starts */
readonly TESTMIG_IGNORE_COMPLETED?: boolean

/** Prevent running migrations (to allow manual fix of an issue which prevents server startup) */
readonly SKIP_MIGRATIONS?: boolean
}

interface IDebug {
Expand Down

0 comments on commit 8e4d24c

Please sign in to comment.