-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
57 lines (53 loc) · 1.66 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as grpc from 'grpc';
import * as fs from 'fs';
import { ExecuteServiceClient } from './src/protos/execute/execute_grpc_pb';
import * as executeDefinitions from './src/protos/execute/execute_pb';
import { ExtensionServiceClient } from './src/protos/extension/extension_grpc_pb';
export interface StyxOps {
executeClient: ExecuteServiceClient;
extensionClient: ExtensionServiceClient;
}
export interface StyxClientArgs {
address: string,
tls: boolean,
tlsCAFile: string,
tlsKeyFile: string,
tlsCertFile: string
}
export function NewStyxClientArgs() {
return {
address: 'localhost:28888',
tls: false,
tlsCAFile: '',
tlsKeyFile: '',
tlsCertFile: '',
}
}
export class StyxClient implements StyxOps {
//ftclient: grpc.Client;
executeClient: ExecuteServiceClient;
extensionClient: ExtensionServiceClient;
args: StyxClientArgs;
constructor(args: StyxClientArgs) {
//this.ftclient = this.initFTClient();
this.executeClient = this.initExecuteClient();
this.extensionClient = this.initExtensionClient();
this.args = args
}
private initCreateSSL() {
return grpc.credentials.createSsl(
fs.readFileSync(this.args.tlsCAFile),
fs.readFileSync(this.args.tlsKeyFile),
fs.readFileSync(this.args.tlsCertFile));
}
private initExecuteClient() {
return new ExecuteServiceClient(
this.args.address,
this.initCreateSSL());
}
private initExtensionClient() {
return new ExtensionServiceClient(
this.args.address,
this.initCreateSSL());
}
}