1 | 'use strict';
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | const fs = require('fs-extra');
|
11 | const path = require('path');
|
12 | const yaml = require('js-yaml');
|
13 | const debug = require('debug')('fun:conf');
|
14 | const getProfile = require('./profile').getProfile;
|
15 | function getConf(rootDir) {
|
16 | return __awaiter(this, void 0, void 0, function* () {
|
17 | const profile = yield getProfile();
|
18 | var confPath = path.join(rootDir, 'faas.yml');
|
19 | var isexists = yield fs.pathExists(confPath);
|
20 | if (!isexists) {
|
21 |
|
22 | confPath = path.join(rootDir, 'faas.yaml');
|
23 | isexists = yield fs.pathExists(confPath);
|
24 | }
|
25 | if (!isexists) {
|
26 | throw new Error('Current folder not a Faas project\nThe folder must contains faas.yml or faas.yaml');
|
27 | }
|
28 | const confContent = yield fs.readFile(confPath, 'utf8');
|
29 | const conf = yaml.safeLoad(confContent);
|
30 | if (!conf.accountid) {
|
31 | debug('try to get accountId from profile');
|
32 | conf.accountid = profile.accountId;
|
33 | }
|
34 | if (!conf.accessKeyId) {
|
35 | debug('try to get accessKeyId from profile');
|
36 | conf.accessKeyId = profile.accessKeyId;
|
37 | }
|
38 | if (!conf.accessKeySecret) {
|
39 | debug('try to get accessKeySecret from profile');
|
40 | conf.accessKeySecret = profile.accessKeySecret;
|
41 | }
|
42 | debug('exitst config: %j', conf);
|
43 | return conf;
|
44 | });
|
45 | }
|
46 | module.exports = getConf;
|