@gravity-ui/gateway 3.2.2-alpha.0 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -9
- package/build/components/grpc.d.ts +1 -1
- package/build/components/grpc.js +4 -36
- package/build/index.js +1 -1
- package/build/models/common.d.ts +0 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @gravity-ui/gateway · [](https://www.npmjs.com/package/@gravity-ui/gateway) [](https://github.com/gravity-ui/gateway/actions/workflows/ci.yml?query=branch:main)
|
|
2
2
|
|
|
3
|
-
Express controller for working with REST
|
|
3
|
+
Express controller for working with REST and GRPC APIs.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -102,13 +102,9 @@ interface GatewayConfig {
|
|
|
102
102
|
onRequestFailed?: (req: Request, res: Response, error: any) => any;
|
|
103
103
|
// List of paths to the necessary proto files for the gateway.
|
|
104
104
|
includeProtoRoots?: string[];
|
|
105
|
-
// Configuration of the path to the
|
|
105
|
+
// Configuration of the path to the certificate in gRPC.
|
|
106
106
|
// Set to null to use system certificates by default.
|
|
107
107
|
caCertificatePath?: string | null;
|
|
108
|
-
// Configuration of the path to the client certificate for mTLS in gRPC.
|
|
109
|
-
clientCertificatePath?: string | null;
|
|
110
|
-
// Configuration of the path to the client private key for mTLS in gRPC.
|
|
111
|
-
clientKeyPath?: string | null;
|
|
112
108
|
// Telemetry sending configuration.
|
|
113
109
|
sendStats?: SendStats;
|
|
114
110
|
// Configuration of headers sent to the API.
|
|
@@ -147,9 +143,6 @@ const config = {
|
|
|
147
143
|
includeProtoRoots: ['...'],
|
|
148
144
|
timeout: 25000, // default 25 seconds
|
|
149
145
|
caCertificatePath: '...',
|
|
150
|
-
// Optional: paths for mTLS client certificate and key
|
|
151
|
-
clientCertificatePath: '...',
|
|
152
|
-
clientKeyPath: '...',
|
|
153
146
|
};
|
|
154
147
|
|
|
155
148
|
const {api: gatewayApi} = getGatewayControllers({root: Schema}, config);
|
|
@@ -19,6 +19,6 @@ export interface GrpcContext {
|
|
|
19
19
|
credentials: CredentialsMap;
|
|
20
20
|
}
|
|
21
21
|
export declare function createRoot(includeGrpcPaths?: string[]): protobufjs.Root;
|
|
22
|
-
export declare function getCredentialsMap(caCertificatePath?: string | null
|
|
22
|
+
export declare function getCredentialsMap(caCertificatePath?: string | null): CredentialsMap;
|
|
23
23
|
export default function createGrpcAction<Context extends GatewayContext>({ root, credentials }: GrpcContext, endpoints: EndpointsConfig | undefined, config: ApiServiceGrpcActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any, any>) => Promise<import("../models/common").GatewayActionClientStreamResponse<any> | import("../models/common").GatewayActionServerStreamResponse<any> | import("../models/common").GatewayActionDuplexStreamResponse<any> | import("../models/common").GatewayActionUnaryResponse<any>>;
|
|
24
24
|
export {};
|
package/build/components/grpc.js
CHANGED
|
@@ -59,21 +59,13 @@ function createRoot(includeGrpcPaths) {
|
|
|
59
59
|
return root;
|
|
60
60
|
}
|
|
61
61
|
exports.createRoot = createRoot;
|
|
62
|
-
function getCredentialsMap(caCertificatePath
|
|
62
|
+
function getCredentialsMap(caCertificatePath) {
|
|
63
63
|
let certificate;
|
|
64
|
-
let clientCertificate;
|
|
65
|
-
let clientKey;
|
|
66
64
|
if (caCertificatePath && fs_1.default.existsSync(caCertificatePath)) {
|
|
67
65
|
certificate = fs_1.default.readFileSync(caCertificatePath);
|
|
68
66
|
}
|
|
69
|
-
if (clientCertificatePath && fs_1.default.existsSync(clientCertificatePath)) {
|
|
70
|
-
clientCertificate = fs_1.default.readFileSync(clientCertificatePath);
|
|
71
|
-
}
|
|
72
|
-
if (clientKeyPath && fs_1.default.existsSync(clientKeyPath)) {
|
|
73
|
-
clientKey = fs_1.default.readFileSync(clientKeyPath);
|
|
74
|
-
}
|
|
75
67
|
return {
|
|
76
|
-
secure: grpc.ChannelCredentials.createSsl(certificate
|
|
68
|
+
secure: grpc.ChannelCredentials.createSsl(certificate),
|
|
77
69
|
secureWithoutRootCert: grpc.ChannelCredentials.createSsl(),
|
|
78
70
|
insecure: grpc.ChannelCredentials.createInsecure(),
|
|
79
71
|
};
|
|
@@ -154,6 +146,7 @@ const reflectionServiceInstancesMap = {};
|
|
|
154
146
|
function clearInstancesCache(service, instancesMap, cachePath, closeTimeout, ctx) {
|
|
155
147
|
const cachedService = lodash_1.default.get(instancesMap, cachePath);
|
|
156
148
|
if (cachedService !== service) {
|
|
149
|
+
ctx.log(`Service client not matched cached service for cachePath '${cachePath}'`);
|
|
157
150
|
return;
|
|
158
151
|
}
|
|
159
152
|
// Remove cached service instance
|
|
@@ -178,37 +171,12 @@ function clearInstancesCache(service, instancesMap, cachePath, closeTimeout, ctx
|
|
|
178
171
|
function getChannelCredential(config, endpointData, credentials) {
|
|
179
172
|
let endpointInsecure;
|
|
180
173
|
let endpointSecureWithoutRootCert;
|
|
181
|
-
let endpointCaCertificatePath;
|
|
182
|
-
let endpointClientCertificatePath;
|
|
183
|
-
let endpointClientKeyPath;
|
|
184
174
|
if ((0, common_2.isExtendedGrpcActionEndpoint)(endpointData)) {
|
|
185
175
|
endpointInsecure = endpointData === null || endpointData === void 0 ? void 0 : endpointData.insecure;
|
|
186
176
|
endpointSecureWithoutRootCert = endpointData === null || endpointData === void 0 ? void 0 : endpointData.secureWithoutRootCert;
|
|
187
|
-
endpointCaCertificatePath = endpointData === null || endpointData === void 0 ? void 0 : endpointData.caCertificatePath;
|
|
188
|
-
endpointClientCertificatePath = endpointData === null || endpointData === void 0 ? void 0 : endpointData.clientCertificatePath;
|
|
189
|
-
endpointClientKeyPath = endpointData === null || endpointData === void 0 ? void 0 : endpointData.clientKeyPath;
|
|
190
177
|
}
|
|
191
178
|
const isInsecure = config.insecure || endpointInsecure;
|
|
192
179
|
const isSecureWithoutRootCert = config.secureWithoutRootCert || endpointSecureWithoutRootCert;
|
|
193
|
-
// If endpoint-specific certificates are provided, create new credentials
|
|
194
|
-
if (endpointCaCertificatePath || endpointClientCertificatePath || endpointClientKeyPath) {
|
|
195
|
-
let certificate;
|
|
196
|
-
let clientCertificate;
|
|
197
|
-
let clientKey;
|
|
198
|
-
const caCertPath = endpointCaCertificatePath || config.caCertificatePath;
|
|
199
|
-
const clientCertPath = endpointClientCertificatePath || config.clientCertificatePath;
|
|
200
|
-
const clientKeyPath = endpointClientKeyPath || config.clientKeyPath;
|
|
201
|
-
if (caCertPath && fs_1.default.existsSync(caCertPath)) {
|
|
202
|
-
certificate = fs_1.default.readFileSync(caCertPath);
|
|
203
|
-
}
|
|
204
|
-
if (clientCertPath && fs_1.default.existsSync(clientCertPath)) {
|
|
205
|
-
clientCertificate = fs_1.default.readFileSync(clientCertPath);
|
|
206
|
-
}
|
|
207
|
-
if (clientKeyPath && fs_1.default.existsSync(clientKeyPath)) {
|
|
208
|
-
clientKey = fs_1.default.readFileSync(clientKeyPath);
|
|
209
|
-
}
|
|
210
|
-
return grpc.ChannelCredentials.createSsl(certificate, clientKey, clientCertificate);
|
|
211
|
-
}
|
|
212
180
|
let creds = credentials.secure;
|
|
213
181
|
if (isInsecure) {
|
|
214
182
|
creds = credentials.insecure;
|
|
@@ -633,7 +601,7 @@ function createGrpcAction({ root, credentials }, endpoints, config, serviceKey,
|
|
|
633
601
|
const shouldRetry = error && retries && (0, grpc_1.isRetryableError)(error);
|
|
634
602
|
if (shouldRecreateService) {
|
|
635
603
|
ctx.log(`Service client for ${config.protoKey} is going to be re-created`);
|
|
636
|
-
recreateService(service,
|
|
604
|
+
recreateService(service, 5000, ctx, args);
|
|
637
605
|
}
|
|
638
606
|
if (shouldRetry) {
|
|
639
607
|
ctx.logError(`Request failed, retrying ${retries--} more times`);
|
package/build/index.js
CHANGED
|
@@ -244,7 +244,7 @@ function getGatewayControllers(schemasByScope, config) {
|
|
|
244
244
|
console.warn('Error when parse GATEWAY_ENDPOINTS_OVERRIDES', err);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
const credentials = (0, grpc_1.getCredentialsMap)(config.caCertificatePath
|
|
247
|
+
const credentials = (0, grpc_1.getCredentialsMap)(config.caCertificatePath);
|
|
248
248
|
for (const scope of (0, common_1.getKeys)(schemasByScope)) {
|
|
249
249
|
apiByScope[scope] = generateGatewayApi(schemasByScope[scope], config, { root: (0, grpc_1.createRoot)(config.includeProtoRoots), credentials }, apiByScope);
|
|
250
250
|
}
|
package/build/models/common.d.ts
CHANGED
|
@@ -106,9 +106,6 @@ export interface ExtendedBaseActionEndpoint {
|
|
|
106
106
|
export interface ExtendedGrpcActionEndpoint extends ExtendedBaseActionEndpoint {
|
|
107
107
|
insecure?: boolean;
|
|
108
108
|
secureWithoutRootCert?: boolean;
|
|
109
|
-
caCertificatePath?: string;
|
|
110
|
-
clientCertificatePath?: string;
|
|
111
|
-
clientKeyPath?: string;
|
|
112
109
|
grpcOptions?: object;
|
|
113
110
|
}
|
|
114
111
|
export interface ExtendedRestActionEndpoint extends ExtendedBaseActionEndpoint {
|
|
@@ -143,9 +140,6 @@ export interface ApiServiceBaseGrpcActionConfig<Context extends GatewayContext,
|
|
|
143
140
|
protoKey: string;
|
|
144
141
|
insecure?: boolean;
|
|
145
142
|
secureWithoutRootCert?: boolean;
|
|
146
|
-
caCertificatePath?: string;
|
|
147
|
-
clientCertificatePath?: string;
|
|
148
|
-
clientKeyPath?: string;
|
|
149
143
|
encodedFields?: string[];
|
|
150
144
|
type?: HandlerType;
|
|
151
145
|
decodeAnyMessageProtoLoaderOptions?: protobufjs.IConversionOptions;
|
|
@@ -261,8 +255,6 @@ export interface GatewayConfig<Context extends GatewayContext, Req extends Gatew
|
|
|
261
255
|
sendStats?: SendStats<Context>;
|
|
262
256
|
includeProtoRoots?: string[];
|
|
263
257
|
caCertificatePath: string | null;
|
|
264
|
-
clientCertificatePath?: string | null;
|
|
265
|
-
clientKeyPath?: string | null;
|
|
266
258
|
proxyHeaders: ProxyHeaders;
|
|
267
259
|
proxyDebugHeaders?: ProxyHeaders;
|
|
268
260
|
withDebugHeaders?: boolean | ((req: Req, res: Res) => boolean);
|