Skip to content

Commit

Permalink
Merge pull request #132 from xusd320/zkAuthInfo
Browse files Browse the repository at this point in the history
Add zookeeper auth supports
  • Loading branch information
hufeng committed Oct 21, 2019
2 parents 2e22edf + 137b942 commit 551d9ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/dubbo/src/registry/zookeeper.ts
Expand Up @@ -179,14 +179,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;
//debug log
log(`connecting zkserver ${register}`);
//connect
this._client = zookeeper.createClient(register, {
retries: 10,
});

if (zkAuthInfo && zkAuthInfo.scheme && zkAuthInfo.auth) {
this._client.addAuthInfo(zkAuthInfo.scheme, Buffer.from(zkAuthInfo.auth));
}

//超时检测
//node-zookeeper-client,有个bug,当连不上zk时会无限重连
//手动做一个超时检测
Expand Down
11 changes: 10 additions & 1 deletion packages/dubbo/src/types.ts
Expand Up @@ -93,7 +93,7 @@ export interface IDubboProps {

//magic, you should use typescript 2.8+
export type TDubboService<T> = {
[k in keyof T]: T[k] extends ((dubbo: any) => infer R) ? R : any
[k in keyof T]: T[k] extends ((dubbo: any) => infer R) ? R : any;
};

export interface IDubboResult<T> {
Expand All @@ -111,7 +111,16 @@ export interface IDubboProvider {
methods: {[methodName: string]: Function};
}

// zookeeper acl shemes must be one of [ 'world', 'ip', 'host', 'auth', 'digest' ]
export type IZKAuthSchemes = 'world' | 'ip' | 'host' | 'auth' | 'digest';

export interface IZKAuthInfo {
scheme: IZKAuthSchemes;
auth: string;
}

export interface IZkClientProps {
zkAuthInfo?: IZKAuthInfo;
zkRoot?: string;
url: string;
}
Expand Down

0 comments on commit 551d9ad

Please sign in to comment.