Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/client-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ const errors = require("./errors.js");
*
* @property {String} [credentials.username] The username to use for plain-text authentication.
* @property {String} [credentials.password] The password to use for plain-text authentication.
* @property {Uuid} [id] A unique identifier assigned to a {@link Client} object, that will be communicated to the
* server (DSE 6.0+) to identify the client instance created with this options. When not defined, the driver will
* @property {Uuid | string} [id] A unique identifier assigned to a {@link Client} object, that will be communicated to the
* server to identify the client instance created with this options. When not defined, the driver will
* generate a random identifier.
* [TODO: Add support for this field]
* @property {String} [applicationName] An optional setting identifying the name of the application using
* the {@link Client} instance.
*
Expand Down Expand Up @@ -663,16 +662,22 @@ function setRustOptions(options) {
rustOptions.connectPoints = options.contactPoints;
rustOptions.applicationName = options.applicationName;
rustOptions.applicationVersion = options.applicationVersion;
if (options.id instanceof types.Uuid) {
options.id = options.id.toString();
}
rustOptions.clientId = options.id;
rustOptions.keyspace = options.keyspace;
rustOptions.cacheSize = options.maxPrepared;
if (rustOptions.cacheSize) {
rustOptions.cacheSize = options.maxPrepared;
}
Comment on lines +670 to +672
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this condition be if (options.maxPrepared)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If yes, then we again lack testing - in this case unit testing.

if (options.credentials) {
rustOptions.credentialsUsername = options.credentials.username;
rustOptions.credentialsPassword = options.credentials.password;
} else if (options.authProvider) {
if (options.authProvider instanceof auth.PlainTextAuthProvider) {
rustOptions.credentialsUsername = options.authProvider.username;
rustOptions.credentialsPassword = options.authProvider.password;
} else {
} else if (!(options.authProvider instanceof auth.NoAuthProvider)) {
throw new errors.ArgumentError(
// TODO: Add support for other auth providers
"Unsupported auth provider: " + options.authProvider,
Expand Down
5 changes: 3 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ class Client extends events.EventEmitter {
*/
constructor(options) {
super();
this.rustOptions = clientOptions.setRustOptions(options);

/** @type {clientOptions.ClientOptions} */
this.options = clientOptions.extend(
{ logEmitter: this.emit.bind(this), id: types.Uuid.random() },
options,
);

this.rustOptions = clientOptions.setRustOptions(this.options);

Object.defineProperty(this, "profileManager", {
value: new ProfileManager(this.options),
});
Expand Down
4 changes: 4 additions & 0 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define_js_to_rust_convertible_object!(SessionOptions {
keyspace, keyspace: String,
application_name, applicationName: String,
application_version, applicationVersion: String,
client_id, clientId: String,
credentials_username, credentialsUsername: String,
credentials_password, credentialsPassword: String,
cache_size, cacheSize: u32,
Expand Down Expand Up @@ -359,5 +360,8 @@ fn self_identity(options: &SessionOptions) -> SelfIdentity<'static> {
if let Some(app_version) = &options.application_name {
self_identity.set_application_version(app_version.clone());
}
if let Some(client_id) = &options.client_id {
self_identity.set_client_id(client_id.to_owned());
}
self_identity
}