forked from ydb-platform/ydb-nodejs-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First app version: create stub from proto, connect to db
- Loading branch information
Showing
5 changed files
with
793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#npm | ||
npm-debug.log* | ||
node_modules | ||
|
||
#temporary | ||
tmp/ | ||
temp/ | ||
|
||
#personal | ||
.idea/ | ||
.DS_Store | ||
|
||
# git merge leftovers | ||
*.orig | ||
|
||
# secrets | ||
secrets/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
|
||
const SERVICE_PROTO_PATH = path.resolve(__dirname, './kikimr/public/api/grpc/ydb_discovery_v1.proto'); | ||
|
||
const packageDefinition = protoLoader.loadSync( | ||
SERVICE_PROTO_PATH, | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true, | ||
includeDirs: [ | ||
__dirname | ||
] | ||
} | ||
); | ||
|
||
function readToken(pathname) { | ||
if (fs.existsSync(pathname)) { | ||
const token = fs.readFileSync(pathname); | ||
return String(token).trim(); | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
const OAUTH_TOKEN = readToken(path.resolve(__dirname, 'secrets/oauth.token')); | ||
|
||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
|
||
const {DiscoveryService} = protoDescriptor.Ydb.Discovery.V1; | ||
|
||
const client = new DiscoveryService('ydb-ru-prestable.yandex.net:2135', grpc.credentials.createInsecure()); | ||
|
||
const metadata = new grpc.Metadata(); | ||
metadata.add('x-ydb-auth-ticket', OAUTH_TOKEN); | ||
|
||
client.ListEndpoints({database: '/ru-prestable/home/tsufiev/mydb'}, metadata, (err, response) => { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log('Response', response) | ||
} | ||
}); |
Oops, something went wrong.