Skip to content

Commit

Permalink
chore: add note to new Camunda REST client
Browse files Browse the repository at this point in the history
  • Loading branch information
jwulf committed Oct 23, 2024
1 parent e3d9206 commit 44d041d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 80 deletions.
23 changes: 16 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.0.1",
"express": "^4.19.2",
"get-port-please": "^3.1.2",
"grpc-tools": "^1.12.4",
"husky": "^8.0.3",
"jest": "^29.7.0",
Expand Down
154 changes: 82 additions & 72 deletions src/__tests__/lib/GetCustomCertificateBuffer.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path'
import { loadPackageDefinition, Server, ServerCredentials } from '@grpc/grpc-js'
import { loadSync } from '@grpc/proto-loader'
import express from 'express'
import { getPort } from 'get-port-please'

import {
BrokerInfo,
Expand Down Expand Up @@ -82,86 +83,95 @@ test('Can use a custom root certificate to connect to a REST API', async () => {
server.close()
})

test('gRPC server with self-signed certificate', (done) => {
// Load the protobuf definition
const packageDefinition = loadSync(
path.join(__dirname, '..', '..', 'proto', 'zeebe.proto'),
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
}
)
test('gRPC server with self-signed certificate', async () => {
// eslint-disable-next-line no-async-promise-executor
return new Promise<void>(async (resolve) => {
// Load the protobuf definition
const packageDefinition = loadSync(
path.join(__dirname, '..', '..', 'proto', 'zeebe.proto'),
{
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
}
)

const zeebeProto = loadPackageDefinition(
packageDefinition
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) as unknown as { gateway_protocol: { Gateway: any } }
const zeebeProto = loadPackageDefinition(
packageDefinition
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) as unknown as { gateway_protocol: { Gateway: any } }

// Create the server
server = new Server()
// Create the server
server = new Server()

// Add a service to the server
server.addService(zeebeProto.gateway_protocol.Gateway.service, {
Topology: (_, callback) => {
const t = new TopologyResponse()
const b = new BrokerInfo()
b.setHost('localhost')
const partition = new Partition()
partition.setHealth(0)
partition.setPartitionid(0)
partition.setRole(0)
b.setPartitionsList([partition])
t.setBrokersList([b])
callback(null, t)
},
// Implement your service methods here
})
// Add a service to the server
server.addService(zeebeProto.gateway_protocol.Gateway.service, {
Topology: (_, callback) => {
const t = new TopologyResponse()
const b = new BrokerInfo()
b.setHost('localhost')
const partition = new Partition()
partition.setHealth(0)
partition.setPartitionid(0)
partition.setRole(0)
b.setPartitionsList([partition])
t.setBrokersList([b])
callback(null, t)
},
// Implement your service methods here
})

// Read the key and certificate
const key = fs.readFileSync(path.join(__dirname, 'localhost.key'))
const cert = fs.readFileSync(path.join(__dirname, 'localhost.crt'))
// Read the key and certificate
const key = fs.readFileSync(path.join(__dirname, 'localhost.key'))
const cert = fs.readFileSync(path.join(__dirname, 'localhost.crt'))

// Start the server
server.bindAsync(
'localhost:50051',
ServerCredentials.createSsl(null, [
{
private_key: key,
cert_chain: cert,
},
]),
(err) => {
if (err) {
console.error(err)
done()
return
}
const port = await getPort()

const zbc = new ZeebeGrpcClient({
config: {
CAMUNDA_OAUTH_DISABLED: true,
ZEEBE_ADDRESS: 'localhost:50051',
CAMUNDA_CUSTOM_ROOT_CERT_PATH: path.join(__dirname, 'localhost.crt'),
CAMUNDA_SECURE_CONNECTION: true,
zeebeGrpcSettings: {
ZEEBE_CLIENT_LOG_LEVEL: 'NONE',
},
// Start the server
server.bindAsync(
`localhost:${port}`,
ServerCredentials.createSsl(null, [
{
private_key: key,
cert_chain: cert,
},
})
zbc.topology().then(() => {
expect(true).toBe(true)
zbc.close()
// Stop the server after the test
server.tryShutdown((err) => {
if (err) console.error(err)
done()
]),
(err) => {
if (err) {
console.error(err)
resolve()
return
}

const zbc = new ZeebeGrpcClient({
config: {
CAMUNDA_OAUTH_DISABLED: true,
ZEEBE_ADDRESS: `localhost:${port}`,
CAMUNDA_CUSTOM_ROOT_CERT_PATH: path.join(
__dirname,
'localhost.crt'
),
CAMUNDA_SECURE_CONNECTION: true,
zeebeGrpcSettings: {
ZEEBE_CLIENT_LOG_LEVEL: 'NONE',
},
},
})
})
}
)
zbc.topology().then(() => {
expect(true).toBe(true)
zbc.close()
// Stop the server after the test
server.tryShutdown((err) => {
if (err) console.error(err)
resolve()
return
})
})
}
)
})
})

test('gRPC server with self-signed certificate provided via string', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion src/c8/lib/CamundaRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DefaultLosslessDto extends LosslessDto {}
* `CAMUNDA_LOG_LEVEL` in the environment or the constructor options can be used to set the log level to one of 'error', 'warn', 'info', 'http', 'verbose', 'debug', or 'silly'.
*
* @since 8.6.0
* @experimental this API may be removed from this package in a future version, and moved to an ESM package. Can you use ESM in your project? Comment [on this issue](https://github.com/camunda/camunda-8-js-sdk/issues/267).
* @experimental this API may be moved to an ESM package in a future release. Can you use ESM in your project? Comment [on this issue](https://github.com/camunda/camunda-8-js-sdk/issues/267).
*/
export class CamundaRestClient {
private userAgentString: string
Expand Down

0 comments on commit 44d041d

Please sign in to comment.