diff --git a/packages/dubbo/src/registry/zookeeper.ts b/packages/dubbo/src/registry/zookeeper.ts index d27d7fbb..fe60f1bd 100644 --- a/packages/dubbo/src/registry/zookeeper.ts +++ b/packages/dubbo/src/registry/zookeeper.ts @@ -179,7 +179,7 @@ export class ZkRegistry extends Registry { * 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 @@ -187,6 +187,10 @@ export class ZkRegistry extends Registry { retries: 10, }); + if (zkAuthInfo && zkAuthInfo.scheme && zkAuthInfo.auth) { + this._client.addAuthInfo(zkAuthInfo.scheme, Buffer.from(zkAuthInfo.auth)); + } + //超时检测 //node-zookeeper-client,有个bug,当连不上zk时会无限重连 //手动做一个超时检测 diff --git a/packages/dubbo/src/types.ts b/packages/dubbo/src/types.ts index 45f9ceb1..1c91fc90 100644 --- a/packages/dubbo/src/types.ts +++ b/packages/dubbo/src/types.ts @@ -93,7 +93,7 @@ export interface IDubboProps { //magic, you should use typescript 2.8+ export type TDubboService = { - [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 { @@ -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; }