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

Add zookeeper auth supports #132

Merged
merged 8 commits into from Oct 21, 2019
Merged

Add zookeeper auth supports #132

merged 8 commits into from Oct 21, 2019

Conversation

xusd320
Copy link

@xusd320 xusd320 commented Aug 26, 2019

For Issue:130.
Add zookeeper authInfo supports.
Detail is here:
node-zookeeper-client#addAuthInfo

@hufeng
Copy link
Member

hufeng commented Oct 18, 2019

@xusd320

感谢你的pr ^_^
因为后续我们会支持多注册中心,支持开发者很方便的自定义自己的注册中心,所有我前段时间做了注册中心的代码重构,这是目前的api

const dubbo = new Dubbo<typeof service>({
  application: {name: 'node-dubbo'},
  // 这个作为一个兼容模式存在默认为zk作为注册中心,未来我们可能支持redis,naccos
  register: 'localhost:2181',
  service,
});

所以通过这样设计就比较单薄了不方便扩展,而且会让dubbo的初始化参数爆表。

所以做了重构之后,我们现在是这样的设计:

import {Dubbo, setting, Zk} from 'dubbo2.js';
const dubbo = new Dubbo<typeof service>({
  application: {name: 'dubbo-node-consumer'},
  service,
  dubboSetting,

  register: Zk({
    url: 'localhost:2181,localhost:2182,localhost:2183',
    // others arguments, for example authInfo
  }),
});

这样注册中心的扩展性就不会影响到Dubbo的入口参数,Keep it simple.

所以希望authInfo不要挂在this.props.authInfo, 而是作为Zk的入口参数。

@@ -98,9 +98,12 @@ export default class Dubbo<TService = Object>

//if dubbo register is string, create a zookeeper instance
let register = this._props.register;
const zkAuthInfo = this._props.zkAuthInfo;
Copy link
Member

Choose a reason for hiding this comment

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

这个参数的设置直接放入Zk({url: '', authInfo: {}})这个函数的参数内部,这样不会再在Dubbo的构造方法中添加更多的属性参数,为后续的多注册中心打下基础。

if (isString(register)) {
register = Zk({
url: this._props.register as string,
zkAuthInfo: zkAuthInfo,
zkRoot: this._props.zkRoot as string,
});
}
Copy link
Member

Choose a reason for hiding this comment

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

url为string的注册中心地址,默认是zk的注册中心,这个只作为兼容方案,后续希望收入到Zk函数,保证更好的扩展性
所以这个地方 不需要加入zkRoot和zkAuthInfo属性的设置

@@ -111,7 +113,13 @@ export interface IDubboProvider {
methods: {[methodName: string]: Function};
}

export interface IZKAuthInfo {
Copy link
Member

Choose a reason for hiding this comment

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

Yes!

//debug log
log(`connecting zkserver ${register}`);
//connect
this._client = zookeeper.createClient(register, {
retries: 10,
});

if (zkAuthInfo && zkAuthInfo.scheme && zkAuthInfo.auth) {
Copy link
Member

Choose a reason for hiding this comment

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

Yes!

@@ -145,14 +145,18 @@ export class ZkRegistry extends Registry<IZkClientProps & IDubboRegistryProps> {
* connect zookeeper
*/
private _connect = (callback: (err: Error) => void) => {
const {url: register} = this._props;
const {url: register, zkAuthInfo} = this._props;
Copy link
Member

Choose a reason for hiding this comment

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

Yes

@xusd320
Copy link
Author

xusd320 commented Oct 20, 2019

@hufeng 感谢回复和review。 重构的设计的确具有更好的抽象,我稍后在这个思路下重新提交一次,烦请您再查阅,十分感谢!

@xusd320
Copy link
Author

xusd320 commented Oct 20, 2019

@hufeng 更新了pr, 自测功能正常,辛苦您再查看一下。
更新中限定了zk acl scheme 的值,依据是:
https://zookeeper.apache.org/doc/r3.1.2/zookeeperProgrammers.html
Builtin ACL Schemes

@hufeng
Copy link
Member

hufeng commented Oct 21, 2019

@xusd320 好的,我来review下 辛苦了

@hufeng hufeng merged commit 551d9ad into apache:master Oct 21, 2019
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.

None yet

2 participants