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

feat: support RepositoryChangeListener for SPI #3883

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

Conversation

qxo
Copy link

@qxo qxo commented Aug 10, 2021

提供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:

  • 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.

@github-actions
Copy link

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

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

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

I have read the CLA Document and I hereby sign the CLA
@nobodyiam
Copy link
Member

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

@qxo
Copy link
Author

qxo commented Aug 11, 2021

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]

@nobodyiam
Copy link
Member

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

@qxo
Copy link
Author

qxo commented Aug 14, 2021

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

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

@nobodyiam nobodyiam added the discussion Categorizes issue as related to discussion label Aug 15, 2021
@nobodyiam
Copy link
Member

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

@nobodyiam nobodyiam added this to the 1.10.0 milestone Aug 21, 2021
@nobodyiam nobodyiam removed this from the 2.0.0 milestone Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Categorizes issue as related to discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants