From e318aed447e67cba4c4584e29a5ca916497f9262 Mon Sep 17 00:00:00 2001 From: Adil Ansari Date: Fri, 14 Oct 2022 13:08:40 -0700 Subject: [PATCH 1/2] chore: getting ready for next release (#127) --- .github/workflows/pre-release.yaml | 2 +- .github/workflows/release.yaml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml index c6e2db9..ba34e2e 100644 --- a/.github/workflows/pre-release.yaml +++ b/.github/workflows/pre-release.yaml @@ -23,5 +23,5 @@ jobs: - name: Release dry run env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GH_BOT_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: npx semantic-release --debug --dryRun diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 366c85b..7a8ebc9 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -47,5 +47,5 @@ jobs: - name: Release env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GH_BOT_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: npx semantic-release --debug diff --git a/package-lock.json b/package-lock.json index ffe2d34..945cc15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tigrisdata/core", - "version": "1.0.0-beta.9", + "version": "1.0.0-beta.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tigrisdata/core", - "version": "1.0.0-beta.9", + "version": "1.0.0-beta.10", "license": "Apache-2.0", "dependencies": { "@grpc/grpc-js": "^1.6.10", diff --git a/package.json b/package.json index df9f9fd..e10583e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tigrisdata/core", - "version": "1.0.0-beta.9", + "version": "1.0.0-beta.10", "description": "Tigris client for Typescript", "author": "Tigris Data (https://www.tigrisdata.com/)", "contributors": [ From 5a7424543dccb3c91f0b4b950d1b71beedcdd40f Mon Sep 17 00:00:00 2001 From: Adil Ansari Date: Tue, 18 Oct 2022 16:19:11 -0700 Subject: [PATCH 2/2] feat: Remove insecure from config (#128) --- src/__tests__/consumables/cursor.spec.ts | 2 +- src/__tests__/tigris.rpc.spec.ts | 78 ++++++++++++------------ src/tigris.ts | 28 ++------- 3 files changed, 44 insertions(+), 64 deletions(-) diff --git a/src/__tests__/consumables/cursor.spec.ts b/src/__tests__/consumables/cursor.spec.ts index 1e0c288..e68d767 100644 --- a/src/__tests__/consumables/cursor.spec.ts +++ b/src/__tests__/consumables/cursor.spec.ts @@ -30,7 +30,7 @@ describe("class FindCursor", () => { } } ); - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); db = tigris.getDatabase("db3"); done(); }); diff --git a/src/__tests__/tigris.rpc.spec.ts b/src/__tests__/tigris.rpc.spec.ts index 59314df..6c840a0 100644 --- a/src/__tests__/tigris.rpc.spec.ts +++ b/src/__tests__/tigris.rpc.spec.ts @@ -54,7 +54,7 @@ describe("rpc tests", () => { }); it("listDatabase", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const listDbsPromise = tigris.listDatabases(); listDbsPromise .then((value) => { @@ -71,7 +71,7 @@ describe("rpc tests", () => { }); it("createDatabaseIfNotExists", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const dbCreationPromise = tigris.createDatabaseIfNotExists("db6", new DatabaseOptions()); dbCreationPromise .then((value) => { @@ -83,7 +83,7 @@ describe("rpc tests", () => { }); it("dropDatabase", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const dbDropPromise = tigris.dropDatabase("db6", new DatabaseOptions()); dbDropPromise .then((value) => { @@ -95,13 +95,13 @@ describe("rpc tests", () => { }); it("getDatabase", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db1"); expect(db1.db).toBe("db1"); }); it("listCollections1", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db1"); const listCollectionPromise = db1.listCollections(); @@ -117,7 +117,7 @@ describe("rpc tests", () => { }); it("listCollections2", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const listCollectionPromise = db1.listCollections(); @@ -133,7 +133,7 @@ describe("rpc tests", () => { }); it("describeDatabase", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const databaseDescriptionPromise = db1.describe(); @@ -150,7 +150,7 @@ describe("rpc tests", () => { }); it("dropCollection", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const dropCollectionPromise = db1.dropCollection("db3_coll_2"); @@ -162,14 +162,14 @@ describe("rpc tests", () => { }); it("getCollection", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const books = db1.getCollection("books"); expect(books.collectionName).toBe("books"); }); it("insert", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const insertionPromise = db1.getCollection("books").insertOne({ author: "author name", @@ -184,7 +184,7 @@ describe("rpc tests", () => { }); it("insert2", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const insertionPromise = db1.getCollection("books").insertOne({ id: 0, @@ -201,7 +201,7 @@ describe("rpc tests", () => { }); it("insertWithOptionalField", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const randomNumber: number = Math.floor(Math.random() * 100); // pass the random number in author field. mock server reads author and sets as the @@ -218,7 +218,7 @@ describe("rpc tests", () => { }); it("insertOrReplace", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const insertOrReplacePromise = db1.getCollection("books").insertOrReplaceOne({ author: "author name", @@ -233,7 +233,7 @@ describe("rpc tests", () => { }); it("insertOrReplaceWithOptionalField", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const randomNumber: number = Math.floor(Math.random() * 100); // pass the random number in author field. mock server reads author and sets as the @@ -250,7 +250,7 @@ describe("rpc tests", () => { }); it("delete", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const deletionPromise = db1.getCollection("books").deleteMany({ op: SelectorFilterOperator.EQ, @@ -265,7 +265,7 @@ describe("rpc tests", () => { }); it("deleteOne", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const collection = tigris.getDatabase("db3").getCollection("books"); const spyCollection = spy(collection); @@ -289,7 +289,7 @@ describe("rpc tests", () => { }); it("update", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const updatePromise = db1.getCollection("books").updateMany( { @@ -312,7 +312,7 @@ describe("rpc tests", () => { }); it("updateOne", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const collection = tigris.getDatabase("db3").getCollection("books"); const spyCollection = spy(collection); @@ -339,7 +339,7 @@ describe("rpc tests", () => { }); it("readOne", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const readOnePromise = db1.getCollection("books").findOne( { op: SelectorFilterOperator.EQ, @@ -358,7 +358,7 @@ describe("rpc tests", () => { }); it("readOneRecordNotFound", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const readOnePromise = db1.getCollection("books").findOne({ op: SelectorFilterOperator.EQ, @@ -373,7 +373,7 @@ describe("rpc tests", () => { }); it("readOneWithLogicalFilter", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db1 = tigris.getDatabase("db3"); const readOnePromise: Promise = db1.getCollection("books").findOne({ op: LogicalOperator.AND, @@ -403,7 +403,7 @@ describe("rpc tests", () => { }); describe("findMany", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("db3"); it("with filter using for await on cursor", async () => { @@ -462,7 +462,7 @@ describe("rpc tests", () => { }); it("search", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const options: SearchRequestOptions = { page: 2, @@ -488,7 +488,7 @@ describe("rpc tests", () => { }); it("searchStream using iteration", async () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const request: SearchRequest = { q: "philosophy", @@ -509,7 +509,7 @@ describe("rpc tests", () => { }); it("searchStream using next", async () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const request: SearchRequest = { q: "philosophy", @@ -532,7 +532,7 @@ describe("rpc tests", () => { }); it("beginTx", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const beginTxPromise = db3.beginTransaction(); beginTxPromise.then(value => { @@ -543,7 +543,7 @@ describe("rpc tests", () => { }); it("commitTx", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const beginTxPromise = db3.beginTransaction(); beginTxPromise.then(session => { @@ -556,7 +556,7 @@ describe("rpc tests", () => { }); it("rollbackTx", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const beginTxPromise = db3.beginTransaction(); beginTxPromise.then(session => { @@ -569,7 +569,7 @@ describe("rpc tests", () => { }); it("transact", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const txDB = tigris.getDatabase("test-tx"); const books = txDB.getCollection("books"); txDB.transact(tx => { @@ -615,7 +615,7 @@ describe("rpc tests", () => { }); it("createOrUpdateCollections", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db3 = tigris.getDatabase("db3"); const bookSchema: TigrisSchema = { id: { @@ -644,7 +644,7 @@ describe("rpc tests", () => { }); it("createOrUpdateTopic", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const alertSchema: TigrisTopicSchema = { id: { @@ -669,7 +669,7 @@ describe("rpc tests", () => { }); it("serverMetadata", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const serverMetadataPromise = tigris.getServerMetadata(); serverMetadataPromise.then(value => { expect(value.serverVersion).toBe("1.0.0-test-service"); @@ -678,7 +678,7 @@ describe("rpc tests", () => { }); it("events", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const collection = db.getCollection("books"); let success = true; @@ -705,7 +705,7 @@ describe("rpc tests", () => { }); it("publish", () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const topic = db.getTopic("test_topic"); expect(topic.topicName).toBe("test_topic"); @@ -724,7 +724,7 @@ describe("rpc tests", () => { }); it("subscribe using callback", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const topic = db.getTopic("test_topic"); let success = true; @@ -747,7 +747,7 @@ describe("rpc tests", () => { }); it("subscribe using stream", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const topic = db.getTopic("test_topic"); const subscription: Readable = topic.subscribe() as Readable; @@ -768,7 +768,7 @@ describe("rpc tests", () => { }); it("subscribeWithFilter", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const topic = db.getTopic("test_topic"); let success = true; @@ -797,7 +797,7 @@ describe("rpc tests", () => { }); it("subscribeToPartitions", (done) => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const topic = db.getTopic("test_topic"); let success = true; @@ -823,7 +823,7 @@ describe("rpc tests", () => { }); it("findMany in topic", async () => { - const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true}); + const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT}); const db = tigris.getDatabase("test_db"); const topic = db.getTopic("test_topic"); const expectedIds = new Set(TestTigrisService.ALERTS_B64_BY_ID.keys()); diff --git a/src/tigris.ts b/src/tigris.ts index 4ec56b3..8d60ea1 100644 --- a/src/tigris.ts +++ b/src/tigris.ts @@ -33,7 +33,6 @@ const AuthorizationBearer = "Bearer "; export interface TigrisClientConfig { serverUrl: string; - insecureChannel?: boolean; clientId?: string; clientSecret?: string; /** @@ -129,34 +128,15 @@ export class Tigris { defaultMetadata.set(USER_AGENT_KEY, USER_AGENT_VAL); defaultMetadata.set(DEST_NAME_KEY, config.serverUrl); - if (config.insecureChannel === true && config.clientSecret === undefined) { - // no auth & insecure channel - cannot compose insecure channels + if (config.clientId === undefined && config.clientSecret === undefined) { + // no auth - generate insecure channel this.grpcClient = new TigrisClient(config.serverUrl, grpc.credentials.createInsecure()); this.observabilityClient = new ObservabilityClient( config.serverUrl, grpc.credentials.createInsecure() ); - } else if ( - (config.insecureChannel === undefined || config.insecureChannel == false) && - config.clientSecret === undefined - ) { - const channelCreds: ChannelCredentials = grpc.credentials.combineChannelCredentials( - grpc.credentials.createSsl(), - grpc.credentials.createFromMetadataGenerator((params, callback) => - callback(undefined, defaultMetadata) - ) - ); - - // no auth & secure channel - this.grpcClient = new TigrisClient(config.serverUrl, channelCreds); - this.observabilityClient = new ObservabilityClient(config.serverUrl, channelCreds); - } else if ( - (config.insecureChannel !== undefined || config.insecureChannel) && - config.clientSecret !== undefined - ) { - // auth & insecure channel - console.error("Passing token on insecure channel is not allowed"); - process.exitCode = 1; + } else if (config.clientId === undefined || config.clientSecret === undefined) { + throw new Error("Both `clientId` and `clientSecret` are required"); } else { // auth & secure channel const tokenSupplier = new TokenSupplier(config);