Skip to content

Commit

Permalink
fix: env for samplebot
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Nov 19, 2017
1 parent f405633 commit d16c120
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 14 deletions.
3 changes: 3 additions & 0 deletions lib/s3-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions lib/samplebot/bot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/samplebot/default-conf.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"org": {
"logo": "https://s3.amazonaws.com/tradle-public-images/safe-re.png",
"domain": "safere.io",
"name": "SafeRe",
"LOGO": "https://s3.amazonaws.com/tradle-public-images/safe-re.png",
"DOMAIN": "safere.io",
"NAME": "SafeRe"
},
"products": {
"products": "nl.tradle.DigitalPassport,tradle.CorporateBankAccount,tradle.LifeInsurance,tradle.MortgageProduct,tradle.CurrentAccount,tradle.OnfidoVerification",
"autoApprove": false,
"autoVerify": false
Expand Down
2 changes: 1 addition & 1 deletion lib/samplebot/strategy/products.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/s3-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ module.exports = function createUtils ({ resources, env, aws }) {
}

function getBucket (bucket) {
if (typeof bucket !== 'string') {
throw new Error('expected string bucket name')
}

debug(`wrapping ${bucket} bucket`)
let api = {
get: key => get({ key, bucket }),
Expand Down
17 changes: 14 additions & 3 deletions src/samplebot/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ export default function createBotFromEnv (env) {
IS_LOCAL
} = env

tradle.env.set(env)
// important: don't set all props from env
// as in testing mode it overrides resources like R_BUCKET_...
tradle.env.set({
PRODUCTS,
ORG_DOMAIN,
AUTO_VERIFY_FORMS,
AUTO_APPROVE_APPS,
AUTO_APPROVE_EMPLOYEES,
GRAPHQL_AUTH,
IS_LOCAL
})

const NAMESPACE = ORG_DOMAIN.split('.').reverse().join('.')
const deploymentModels = createDeploymentModels(NAMESPACE)
Expand All @@ -44,9 +54,10 @@ export default function createBotFromEnv (env) {
graphqlRequiresAuth: yn(GRAPHQL_AUTH)
})

const confBucket = bot.resources.buckets.PublicConf
const CONF_FILE = 'bot-conf.json'
const putConf = (conf) => bot.resources.buckets.PublicConf.put(CONF_FILE, conf)
const cacheableConf = bot.resources.buckets.PublicConf.getCacheable({
const putConf = (conf) => confBucket.put(CONF_FILE, conf)
const cacheableConf = confBucket.getCacheable({
key: CONF_FILE,
ttl: 60000,
parse: JSON.parse.bind(JSON)
Expand Down
17 changes: 17 additions & 0 deletions src/samplebot/default-conf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
{
"org": {
"LOGO": "https://s3.amazonaws.com/tradle-public-images/safe-re.png",
"DOMAIN": "safere.io",
"NAME": "SafeRe"
},
"products": {
"products": "nl.tradle.DigitalPassport,tradle.CorporateBankAccount,tradle.LifeInsurance,tradle.MortgageProduct,tradle.CurrentAccount,tradle.OnfidoVerification",
"autoApprove": false,
"autoVerify": false
},
"style": {
"_t": "tradle.StylesPack",
"backgroundImage": {
"url": "https://s3.amazonaws.com/tradle-public-images/blue-underwater-gradient-opacity-15.png"
},
"logoNeedsText": true
},
"plugins": {
"customize-message": {
"tradle.FormRequest": {
Expand Down
2 changes: 1 addition & 1 deletion src/samplebot/strategy/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const DONT_FORWARD_FROM_EMPLOYEE = [

export default function createProductsBot (opts={}) {
const {
tradle=defaultTradleInstance,
tradle,
models=baseModels,
products=DEFAULT_PRODUCTS,
namespace='test.bot',
Expand Down
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Resources = require('./resources')
import { ExecutionTimeout } from './errors'

const debug = require('debug')('tradle:sls:utils')
const notNull = obj => obj != null
const isPromise = obj => obj && typeof obj.then === 'function'
const { omitVirtual, setVirtual, pickVirtual } = buildResource
const LAUNCH_STACK_BASE_URL = 'https://console.aws.amazon.com/cloudformation/home'
Expand Down Expand Up @@ -689,5 +690,3 @@ export const getRequestIps = (req) => {
req.get('x-real-ip')
].filter(notNull)
}

const notNull = obj => obj != null

0 comments on commit d16c120

Please sign in to comment.