-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.js
More file actions
24 lines (20 loc) · 939 Bytes
/
index.js
File metadata and controls
24 lines (20 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import Promise from 'bluebird'
import { EnvironmentVariableConflict } from '../util/errors'
import { environmentCheck, values } from '../util/environment-check'
import getFunctionEnvs from '../util/get-function-envs'
import uploadEnvironment from '../util/upload-environment'
import { funcs, lambdaConfig } from '../util/load'
export default async function ({ env }) {
const configs = await Promise.map(funcs(), (func) => lambdaConfig(func, env))
const environments = await getFunctionEnvs(env, configs)
const { common, differences, conflicts } = environmentCheck(environments)
if (Object.keys(conflicts).length !== 0) {
const conflictVars = values(conflicts)
throw new EnvironmentVariableConflict({ conflictVars, env })
}
const combinedEnvironment = values(differences).reduce((acc, { key, value }) => {
acc[key] = value.value
return acc
}, common)
return uploadEnvironment(env, combinedEnvironment)
}