How to use the @creditkarma/thrift-server-core.getTransport function in @creditkarma/thrift-server-core

To help you get started, we’ve selected a few @creditkarma/thrift-server-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github creditkarma / thrift-server / packages / thrift-client / src / main / connections / TcpConnection.ts View on Github external
constructor({
        hostName,
        port,
        timeout = 5000,
        transport = 'buffered',
        protocol = 'binary',
        logger = defaultLogger,
        pool,
    }: IConnectionOptions) {
        super(getTransport(transport), getProtocol(protocol))
        this.hostName = hostName
        this.port = port
        this.filters = []
        this.logger = logger
        this.pool = createPool(
            {
                port,
                hostName,
                timeout,
            },
            this.logger,
            pool || {},
        )
    }
github creditkarma / thrift-server / packages / thrift-client / src / main / connections / HttpConnection.ts View on Github external
constructor({
        hostName,
        port,
        path = '/thrift',
        https = false,
        transport = 'buffered',
        protocol = 'binary',
        requestOptions = {},
        serviceName,
        withEndpointPerMethod = false,
        headerBlacklist = [],
    }: IHttpConnectionOptions) {
        super(Core.getTransport(transport), Core.getProtocol(protocol))
        this.requestOptions = Object.freeze(
            filterHeaders(requestOptions, headerBlacklist),
        )
        this.port = port
        this.hostName = hostName
        this.path = Core.normalizePath(path || DEFAULT_PATH)
        this.protocol = https === true ? 'https' : 'http'
        this.serviceName = serviceName
        this.basePath = `${this.protocol}://${this.hostName}:${this.port}`
        this.withEndpointPerMethod = withEndpointPerMethod
        this.url = `${this.basePath}${this.path}`
        this.filters = []
    }
github creditkarma / thrift-server / packages / thrift-client-context-filter / src / main / appendThriftObject.ts View on Github external
export function appendThriftObject(
    value: LooseType,
    data: Buffer,
    ThriftCodec: IStructCodec,
    transportType: TransportType = 'buffered',
    protocolType: ProtocolType = 'binary',
): Promise {
    const Transport: ITransportConstructor = getTransport(transportType)
    const Protocol: IProtocolConstructor = getProtocol(protocolType)

    return encode(value, ThriftCodec, Transport, Protocol).then(
        (encoded: Buffer) => {
            return Buffer.concat([encoded, data])
        },
    )
}
github creditkarma / thrift-server / packages / thrift-server-hapi / src / main / ThriftServerHapi.ts View on Github external
export function ThriftServerHapi<
    TProcessor extends Core.IThriftProcessor
>(pluginOptions: IHapiPluginOptions): ThriftHapiPlugin {
    const thriftOptions: IHapiServerOptions =
        pluginOptions.thriftOptions
    const logger: Core.LogFunction = thriftOptions.logger || defaultLogger
    const thriftPath: string = Core.normalizePath(
        pluginOptions.path || DEFAULT_PATH,
    )
    const serviceName: string = pluginOptions.thriftOptions.serviceName

    const Transport: Core.ITransportConstructor = Core.getTransport(
        thriftOptions.transport,
    )
    const Protocol: Core.IProtocolConstructor = Core.getProtocol(
        thriftOptions.protocol,
    )
    const processor: Core.IThriftProcessor = thriftOptions.handler
    const rawServiceName: string = processor._serviceName

    return {
        name: require('../../package.json').name,
        version: require('../../package.json').version,
        multiple: true,
        async register(server: Hapi.Server, nothing: void): Promise {
            if (
                server.plugins.thrift !== undefined &&
                (server.plugins.thrift.transport !==
github creditkarma / thrift-server / packages / zipkin-tracing-express / src / main / ZipkinTracingExpress.ts View on Github external
tracer.scoped(() => {
            const requestMethod: string =
                isThrift === true
                    ? readThriftMethod(
                          request.body,
                          getTransport(transport),
                          getProtocol(protocol),
                      )
                    : request.method

            const normalHeaders: IRequestHeaders = normalizeHeaders(
                request.headers,
            )

            function readHeader(header: string): option.IOption {
                const val = normalHeaders[header.toLocaleLowerCase()]
                if (val !== null && val !== undefined) {
                    return new option.Some(val)
                } else {
                    return option.None
                }
            }
github alitelabs / tyx / src / core / thrift.ts View on Github external
constructor(pluginOptions: ICoreThriftHandlerOptions) {
    this.pluginOptions = pluginOptions;
    this.transport = getTransport(pluginOptions.transport);
    this.protocol = getProtocol(pluginOptions.protocol);
  }
github creditkarma / thrift-server / packages / zipkin-tracing-hapi / src / main / ZipkinTracingHapi.ts View on Github external
(request: Hapi.Request, reply: Hapi.ResponseToolkit) => {
                    const requestMethod: string =
                        isThrift === true
                            ? Core.readThriftMethod(
                                  request.payload as Buffer,
                                  Core.getTransport(transport),
                                  Core.getProtocol(protocol),
                              )
                            : request.method

                    const normalHeaders: Core.IRequestHeaders = normalizeHeaders(
                        request.headers,
                    )

                    return tracer.scoped(() => {
                        const traceId: TraceId = instrumentation.recordRequest(
                            requestMethod,
                            Core.formatUrl(url.format(request.url)),
                            (header: string): option.IOption => {
                                const val = normalHeaders[header.toLowerCase()]
                                if (val !== null && val !== undefined) {
                                    return new option.Some(val)
github creditkarma / thrift-server / packages / thrift-client-ttwitter-filter / src / main / ThriftClientTTwitterFilter.ts View on Github external
function upgradeRequest(
    transportType: TransportType = 'buffered',
    protocolType: ProtocolType = 'binary',
): Buffer {
    const Transport: ITransportConstructor = getTransport(transportType)
    const Protocol: IProtocolConstructor = getProtocol(protocolType)
    const options: TTwitter.ConnectionOptions = new TTwitter.ConnectionOptions()
    const writer: TTransport = new Transport()
    const output: TProtocol = new Protocol(writer)

    output.writeMessageBegin(CAN_TRACE_METHOD_NAME, MessageType.CALL, 0)
    options.write(output)
    output.writeMessageEnd()

    return output.flush()
}
github creditkarma / thrift-server / packages / thrift-server-express / src / main / ThriftServerExpress.ts View on Github external
return (
        request: ThriftRequest,
        response: express.Response,
        next: express.NextFunction,
    ): void => {
        const Transport: ITransportConstructor = getTransport(
            pluginOptions.transport,
        )
        const Protocol: IProtocolConstructor = getProtocol(
            pluginOptions.protocol,
        )
        const buffer: Buffer = request.body

        const method: string = readThriftMethod(buffer, Transport, Protocol)

        request.thrift = {
            requestMethod: method,
            processor: pluginOptions.handler,
            transport: pluginOptions.transport || 'buffered',
            protocol: pluginOptions.protocol || 'binary',
        }