Code Monkey home page Code Monkey logo

enterprise-client's People

Watchers

 avatar  avatar  avatar  avatar

enterprise-client's Issues

nodejs enterprise-client

I did not find an enterprise nodejs client available; is it possible to have a client created similar to the python and go clients?

I have been trying to use @grpc/grpc-js and @grpc/proto-loader to create it and this is what I have come up with so far (against the update-docs-template branch):

pull.sh:

#!/bin/bash

# Directory to ignore
LIB_DIR="lib"

# Git repositories to clone
REPO1="envoyproxy/data-plane-api"
TAG1="3a71d52b66bc661c25ba6f6b082d900b09ea7fd8"
REPO2="googleapis/googleapis"
TAG2="9a7d19079b5e3c22a5a08eaa94273f5d1eebb317"
REPO3="bufbuild/protoc-gen-validate"
TAG3="59da36e59fef2267fc2b1849a05159e3ecdf24f3"
REPO4="cncf/udpa"
TAG4="6414d713912e988471d192940b62bf552b11793a"

mkdir -p $LIB_DIR/$REPO1
curl -L https://api.github.com/repos/$REPO1/tarball/$TAG1 | tar xz -C $LIB_DIR/$REPO1 --strip-components=1
mkdir -p $LIB_DIR/$REPO2
curl -L https://api.github.com/repos/$REPO2/tarball/$TAG2 | tar xz -C $LIB_DIR/$REPO2 --strip-components=1
mkdir -p $LIB_DIR/$REPO3
curl -L https://api.github.com/repos/$REPO3/tarball/$TAG3 | tar xz -C $LIB_DIR/$REPO3 --strip-components=1
mkdir -p $LIB_DIR/$REPO4
curl -L https://api.github.com/repos/$REPO4/tarball/$TAG4 | tar xz -C $LIB_DIR/$REPO4 --strip-components=1

gulpfile.js

const gulp = require('gulp');
const through2 = require('through2');
const fs = require('fs');
const path = require('path');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

gulp.task('generate-sdk', function () {
    const protoDir = 'proto';
    const includeDirs = [
        path.resolve(__dirname, 'lib/envoyproxy/data-plane-api'),
        path.resolve(__dirname, 'lib/googleapis/googleapis'),
        path.resolve(__dirname, 'lib/bufbuild/protoc-gen-validate'),
        path.resolve(__dirname, 'lib/cncf/udpa'),
        path.resolve(__dirname, 'proto/pomerium'),
    ]
    return gulp.src(`${protoDir}/**/*.proto`)
      .pipe(through2.obj(function (file, _, cb) {
        const packageDefinition = protoLoader.loadSync(file.path, {
          keepCase: true,
          longs: String,
          enums: String,
          defaults: true,
          oneofs: true,
          includeDirs
        });
        const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
        const serviceName = Object.keys(protoDescriptor)[0]; // Assume the service name is the first key
        const relativePath = path.relative(protoDir, path.dirname(file.path));
        const outputFilePath = path.join('build', relativePath, `${serviceName}Client.js`);
        const clientFactory = `
          const grpc = require('@grpc/grpc-js');
          const protoDescriptor = ${JSON.stringify(protoDescriptor)};
          class ${serviceName}Client {
            constructor(endpoint, channelCredentials) {
              this.service = new protoDescriptor.${serviceName}(endpoint, channelCredentials);
            }
          }
          module.exports = ${serviceName}Client;
        `;
        fs.mkdirSync(path.dirname(outputFilePath), { recursive: true });
        fs.writeFileSync(outputFilePath, clientFactory);
        cb(null, file);
      }));
  });
// Define a task that uses the generate file and includes the copy task
gulp.task('copy', () => {
    return gulp.src('src/**/*')
        .pipe(gulp.dest('build'))
});

// Define a task to clean the build directory
gulp.task('clean', async () => {
    const del = await import('del');
    return del(['build']);
});

// Default task

gulp.task('generate', gulp.series('copy','generate-sdk'));

gulp.task('default', gulp.series('clean', 'generate'));

src/package.json

{
  "name": "@pomerium/enterprise-client",
  "version": "1.0.0",
  "description": "javascript sdk to access the pomerium api",
  "main": "",
  "scripts": {},
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@grpc/grpc-js": "^1.9.13"
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.