Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] feat: support loadConfig asynchronous #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gxcsoccer
Copy link

@gxcsoccer gxcsoccer commented Jun 24, 2019

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

oss 的 ak/sk 可能配置的是加密的,启动的时候可能需要先调用 api 进行解密

exports.oss = {
  default: {
    async loadConfig(config, app) {
      const accessKeyId = await app.kmiclient.decrypt(config.accessKeyId);
      const accessKeySecret = await app.kmiclient.decrypt(config.accessKeySecret);
      return Object.assign({}, config, {
         accessKeyId,
         accessKeySecret,
      });
    },
  },
  client: {
     accessKeyId: '**********',
     accessKeySecret: '***********',
     endpoint: 'http://oss-cn-hangzhou.aliyuncs.com',
     bucket: 'xxx',
  },
};

@gxcsoccer gxcsoccer force-pushed the feat/support-loadconfig-async branch from 7514364 to a0066ea Compare June 24, 2019 08:01
@codecov
Copy link

codecov bot commented Jun 24, 2019

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@93a05ea). Learn more about missing BASE report.
Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##             master       #11   +/-   ##
==========================================
  Coverage          ?   100.00%           
==========================================
  Files             ?         6           
  Lines             ?        33           
  Branches          ?         0           
==========================================
  Hits              ?        33           
  Misses            ?         0           
  Partials          ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gxcsoccer gxcsoccer force-pushed the feat/support-loadconfig-async branch 2 times, most recently from 31caaba to 42327b4 Compare June 24, 2019 08:27
@gxcsoccer gxcsoccer force-pushed the feat/support-loadconfig-async branch from 42327b4 to b33ff7a Compare June 24, 2019 08:31
@gxcsoccer gxcsoccer changed the title [WIP] feat: support loadConfig asynchronous [BREAKING] feat: support loadConfig asynchronous Jun 24, 2019
config = Object.assign({}, config, { urllib: app.httpclient });
if (is.function(config.loadConfig)) {
const result = config.loadConfig(config, app);
config = is.promise(result) ? (await result) : result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样直接赋值的话 client 的配置会不会覆盖 default 啊(盲猜
测试用例里好像也没体现

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@troyeagle troyeagle Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样的话 default 中的异步函数由于延迟执行,会覆盖 client 里面已经设置好的重复字段;对于 client 和 default 都需要异步函数的情形还支持不了。
https://gist.github.com/troyeagle/b10774eff060cc6c6d1ed51ba8d842ec 可能是一种解决方法。总之用异步函数设定的值会打破原先 default 和 client 的加载顺序。求教在这种情形下应该怎么考虑设计

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants