Skip to content

Commit

Permalink
JSCBC-1137: Create and use CppClusterCredentials and CppDnsConfig
Browse files Browse the repository at this point in the history
interfaces for connection

Motivation
----------
Instead of redefining a credentials object to connect we should use what
is already available from the autogen tooling.

Changes
-------
Create CppClusterCredentials and CppDnsConfig interfaces that are used
when connecting.

Change-Id: Ic77cfaecd163539158093caa4d2b119d282a89d9
Reviewed-on: https://review.couchbase.org/c/couchnode/+/187863
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Jared Casey <jared.casey@couchbase.com>
  • Loading branch information
thejcfactor committed Mar 9, 2023
1 parent 5884066 commit e855b09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
28 changes: 16 additions & 12 deletions lib/binding.ts
Expand Up @@ -14,6 +14,20 @@ export type CppExpiry = number

export type CppJsonString = string | Buffer

export interface CppClusterCredentials {
username?: string
password?: string
certificate_path?: string
key_path?: string
allowed_sasl_mechanisms?: string[]
}

export interface CppDnsConfig {
nameserver?: string
port?: number
dnsSrvTimeout?: number
}

export interface CppDocumentId {
bucket: string
scope: string
Expand Down Expand Up @@ -3160,18 +3174,8 @@ export type CppError =
export interface CppConnection extends CppConnectionAutogen {
connect(
connStr: string,
credentials: {
username?: string
password?: string
certificate_path?: string
key_path?: string
allowed_sasl_mechanisms?: string[]
},
dnsOptions: {
nameserver?: string
port?: number
dnsSrvTimeout?: number
} | null,
credentials: CppClusterCredentials,
dnsOptions: CppDnsConfig | null,
callback: (err: CppError | null) => void
): void
shutdown(callback: (err: CppError | null) => void): void
Expand Down
11 changes: 2 additions & 9 deletions lib/cluster.ts
Expand Up @@ -10,7 +10,7 @@ import {
PasswordAuthenticator,
CertificateAuthenticator,
} from './authenticators'
import binding, { CppConnection } from './binding'
import binding, { CppClusterCredentials, CppConnection } from './binding'
import { errorFromCpp } from './bindingutilities'
import { Bucket } from './bucket'
import { BucketManager } from './bucketmanager'
Expand Down Expand Up @@ -614,13 +614,7 @@ export class Cluster {

const connStr = dsnObj.toString()

const authOpts = {
username: undefined as string | undefined,
password: undefined as string | undefined,
certificate_path: undefined as string | undefined,
key_path: undefined as string | undefined,
allowed_sasl_mechanisms: undefined as string[] | undefined,
}
const authOpts: CppClusterCredentials = {}

// lets allow `allowed_sasl_mechanisms` to override legacy connstr option
for (const saslKey of ['sasl_mech_force', 'allowed_sasl_mechanisms']) {
Expand Down Expand Up @@ -658,7 +652,6 @@ export class Cluster {
const err = errorFromCpp(cppErr)
return reject(err)
}

resolve(null)
})
})
Expand Down

0 comments on commit e855b09

Please sign in to comment.