apollo icon indicating copy to clipboard operation
apollo copied to clipboard

feat: support RepositoryChangeListener for SPI

Open qxo opened this issue 3 years ago • 6 comments

提供SPI扩展,以便具体项目通过此SPI中来实现敏感信息(如密码)的解密处理

SPI实现类配置文件位置:META-INF\services\com.ctrip.framework.apollo.internals.RepositoryChangeListener

What's the purpose of this PR

XXXXX

Which issue(s) this PR fixes:

Fixes #

Brief changelog

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • [x] Read the Contributing Guide before making this pull request.
  • [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [ ] Write necessary unit tests to verify the code.
  • [ ] Run mvn clean test to make sure this pull request doesn't break anything.
  • [ ] Update the CHANGES log.

qxo avatar Aug 10 '21 16:08 qxo

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

github-actions[bot] avatar Aug 10 '21 16:08 github-actions[bot]

RepositoryChangeListener 应该没法实现这个需求吧,可行的方式可以参考 com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory,通过 ApolloInjectorCustomizer 来自定义一个 Config 类实现出来

nobodyiam avatar Aug 11 '21 00:08 nobodyiam

RepositoryChangeListener 应该没法实现这个需求吧,可行的方式可以参考 com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory,通过 ApolloInjectorCustomizer 来自定义一个 Config 类实现出来

经过此PR, 是可能实现对apollo中获取配置项进行解码处理再交由程序来处理。

API应提供扩展点以便具体项目进行个性化改造(而不用修改源码)

以下是切入点调用链供参考 //启动时的SPI切入点:

       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.fireRepositoryChange(AbstractConfigRepository.java:53) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository.sync(RemoteConfigRepository.java:148) ~[classes/:1.8.0]
       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.trySync(AbstractConfigRepository.java:25) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository.<init>(RemoteConfigRepository.java:97) ~[classes/:1.8.0]
       at com.ctrip.framework.apollo.spi.DefaultConfigFactory.createRemoteConfigRepository(DefaultConfigFactory.java:77) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spi.DefaultConfigFactory.createLocalConfigRepository(DefaultConfigFactory.java:73) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spi.DefaultConfigFactory.create(DefaultConfigFactory.java:42) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.DefaultConfigManager.getConfig(DefaultConfigManager.java:37) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.ConfigService.getConfig(ConfigService.java:61) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer.initialize(ApolloApplicationContextInitializer.java:104) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer.initialize(ApolloApplicationContextInitializer.java:82) ~[apollo-client-1.8.0.jar:1.8.0]
       at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:623) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:367) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]

//更变时的切入点:

       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.fireRepositoryChange(AbstractConfigRepository.java:53) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository.sync(RemoteConfigRepository.java:148) ~[classes/:1.8.0]
       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.trySync(AbstractConfigRepository.java:25) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository$2.run(RemoteConfigRepository.java:329) ~[classes/:1.8.0]
       at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
       at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
       at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
       at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

qxo avatar Aug 11 '21 14:08 qxo

@qxo 通过 onRepositoryChange 应该无法实现诸如敏感信息(如密码)的解密处理,这里传入的 properties 对象虽然目前是可写的,但是从语义上而言只能当作是 readonly 的,所以如果要解密的话,还是需要通过自定义 Config 类来实现的,或者在 fireRepositoryChange 中增加一个新的 spi,专门用于对 properties 进行加工处理

nobodyiam avatar Aug 14 '21 06:08 nobodyiam

@qxo 通过 onRepositoryChange 应该无法实现诸如敏感信息(如密码)的解密处理,这里传入的 properties 对象虽然目前是可写的,但是从语义上而言只能当作是 readonly 的,所以如果要解密的话,还是需要通过自定义 Config 类来实现的,或者在 fireRepositoryChange 中增加一个新的 spi,专门用于对 properties 进行加工处理

这样啊,新增一个spi也行, 请项目主管理方决策:)

qxo avatar Aug 14 '21 15:08 qxo

我加了 discussion 标签,开放一段时间看看大家的想法吧~

nobodyiam avatar Aug 15 '21 07:08 nobodyiam