UNPKG

1.22 kBJavaScriptView Raw
1'use strict';
2
3
4const fs = require('fs-extra');
5const path = require('path');
6
7const yaml = require('js-yaml');
8const debug = require('debug')('fun:conf');
9const getProfile = require('./profile').getProfile;
10
11async function getConf(rootDir) {
12 const profile = await getProfile();
13
14 var confPath = path.join(rootDir, 'faas.yml');
15 var isexists = await fs.pathExists(confPath);
16
17 if (!isexists) {
18 // try faas.yaml
19 confPath = path.join(rootDir, 'faas.yaml');
20 isexists = await fs.pathExists(confPath);
21 }
22
23 if (!isexists) {
24 throw new Error('Current folder not a Faas project\nThe folder must contains faas.yml or faas.yaml');
25 }
26
27 const confContent = await fs.readFile(confPath, 'utf8');
28 const conf = yaml.safeLoad(confContent);
29
30 if (!conf.accountid) {
31 debug('try to get accountId from profile');
32 conf.accountid = profile.accountId;
33 }
34
35 if (!conf.accessKeyId) {
36 debug('try to get accessKeyId from profile');
37 conf.accessKeyId = profile.accessKeyId;
38 }
39
40 if (!conf.accessKeySecret) {
41 debug('try to get accessKeySecret from profile');
42 conf.accessKeySecret = profile.accessKeySecret;
43 }
44
45 debug('exitst config: %j', conf);
46 return conf;
47}
48
49module.exports = getConf;