Add authhooks to proxy constructor (#153)

This commit is contained in:
KonradStaniec 2022-09-22 10:58:19 +02:00 committed by GitHub
parent 5fa7071d5b
commit 64dbf122d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions

View File

@ -48,7 +48,7 @@ proc proxyCall(client: RpcClient, name: string): RpcProc =
let res = await client.call(name, params)
return StringOfJson($res)
proc getClient(proxy: RpcProxy): RpcClient =
proc getClient*(proxy: RpcProxy): RpcClient =
case proxy.kind
of Http:
proxy.httpClient
@ -71,11 +71,20 @@ proc new*(T: type RpcProxy, server: RpcHttpServer, cfg: ClientConfig): T =
flags: cfg.flags
)
proc new*(T: type RpcProxy, listenAddresses: openArray[TransportAddress], cfg: ClientConfig): T {.raises: [Defect, CatchableError].} =
RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init()), cfg)
proc new*(
T: type RpcProxy,
listenAddresses: openArray[TransportAddress],
cfg: ClientConfig,
authHooks: seq[HttpAuthHook] = @[]
): T {.raises: [Defect, CatchableError].} =
RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init(), authHooks), cfg)
proc new*(T: type RpcProxy, listenAddresses: openArray[string], cfg: ClientConfig): T {.raises: [Defect, CatchableError].} =
RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init()), cfg)
proc new*(
T: type RpcProxy,
listenAddresses: openArray[string],
cfg: ClientConfig,
authHooks: seq[HttpAuthHook] = @[]): T {.raises: [Defect, CatchableError].} =
RpcProxy.new(newRpcHttpServer(listenAddresses, RpcRouter.init(), authHooks), cfg)
proc connectToProxy(proxy: RpcProxy): Future[void] =
case proxy.kind