Skip to content

Commit

Permalink
Adding client auditing session properties (vertica#132)
Browse files Browse the repository at this point in the history
* Adding client auditing session properties

* Updates for 1.1.1 release
  • Loading branch information
DMickens authored Feb 7, 2024
1 parent 321e33f commit df92e11
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
"arrowParens": "always",
"trailingComma": "es5",
"singleQuote": true
},
"dependencies": {
"vertica-nodejs": "^1.1.1"
}
}
4 changes: 2 additions & 2 deletions packages/v-pool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-pool",
"version": "1.1.0",
"version": "1.1.1",
"description": "Connection pool for Vertica",
"main": "index.js",
"directories": {
Expand Down Expand Up @@ -35,6 +35,6 @@
"mocha": "^7.1.2"
},
"peerDependencies": {
"vertica-nodejs": "1.1.0"
"vertica-nodejs": "1.1.1"
}
}
8 changes: 6 additions & 2 deletions packages/vertica-nodejs/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,12 @@ class Client extends EventEmitter {
user: params.user,
database: params.database,
protocol_version: params.protocol_version.toString(),
client_os_hostname: params.client_os_hostname
client_type: params.client_type,
client_version: params.client_version,
client_os: params.client_os,
client_os_user_name: params.client_os_user_name,
client_os_hostname: params.client_os_hostname,
client_pid: params.client_pid
}

if (params.replication) {
Expand All @@ -533,7 +538,6 @@ class Client extends EventEmitter {
data.workload = params.workload
}


return data
}

Expand Down
8 changes: 8 additions & 0 deletions packages/vertica-nodejs/lib/connection-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ class ConnectionParameters {
this.backup_server_node = parseBackupServerNodes(val('backup_server_node', config))
this.client_label = val('client_label', config, false)
this.workload = val('workload', config, false)

// client auditing information
this.client_os_hostname = os.hostname()
this.client_type = "Node.js Driver"
this.client_version = "1.1.1"
this.client_pid = process.pid.toString()
this.client_os = os.platform()
this.client_os_user_name = os.userInfo().username

//NOTE: The client has only been tested to support 3.5, which was chosen in order to include SHA512 support
this.protocol_version = (3 << 16 | 5) // 3.5 -> (major << 16 | minor) -> (3 << 16 | 5) -> 196613

Expand Down
6 changes: 4 additions & 2 deletions packages/vertica-nodejs/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var defaults = require('./defaults')
var Connection = require('./connection')
var Pool = require('v-pool')
const { DatabaseError } = require('v-protocol')
const packageJson = require('../package.json')

const poolFactory = (Client) => {
return class BoundPool extends Pool {
Expand All @@ -28,7 +29,7 @@ const poolFactory = (Client) => {
}
}

var PG = function (clientConstructor) {
var Vertica = function (clientConstructor) {
this.defaults = defaults
this.Client = clientConstructor
this.Query = this.Client.Query
Expand All @@ -37,7 +38,8 @@ var PG = function (clientConstructor) {
this.Connection = Connection
this.types = require('pg-types')
this.DatabaseError = DatabaseError
this.version = packageJson.version
}

module.exports = new PG(Client)
module.exports = new Vertica(Client)

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

'use strict'
const vertica = require('../../../lib')
const vertica = require('../../../../vertica-nodejs')
const assert = require('assert')

var os = require('os')
Expand Down Expand Up @@ -105,12 +105,17 @@ describe('vertica backup_server_node connection parameter', function() {
})
})

describe('vertica client_os_hostname connection parameter', function() {
it('is automatically determined and sent in the startup packet', function() {
describe('vertica-nodejs handling auditing connection properties', function() {
it('are provided automatically when establishing a connection', function() {
const client = new vertica.Client()
client.connect()
client.query("SELECT client_os_hostname FROM current_session", (err, res) => {
client.query("SELECT client_pid, client_type, client_version, client_os, client_os_user_name, client_os_hostname FROM CURRENT_SESSION", (err, res) => {
if (err) assert(false)
assert.equal(res.rows[0].client_pid, process.pid)
assert.equal(res.rows[0].client_type, "Node.js Driver")
assert.equal(res.rows[0].client_version, vertica.version)
assert.equal(res.rows[0].client_os, os.platform())
assert.equal(res.rows[0].client_os_user_name, os.userInfo().username)
assert.equal(res.rows[0].client_os_hostname, os.hostname())
client.end()
})
Expand All @@ -131,3 +136,4 @@ describe('vertica workload connection parameter', function() {
})
})
})

4 changes: 2 additions & 2 deletions packages/vertica-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vertica-nodejs",
"version": "1.1.0",
"version": "1.1.1",
"description": "Vertica client - pure javascript & libpq with the same API",
"keywords": [
"database",
Expand Down Expand Up @@ -31,7 +31,7 @@
"pg-types": "^2.1.0",
"pgpass": "1.x",
"v-connection-string": "1.1.0",
"v-pool": "1.1.0",
"v-pool": "1.1.1",
"v-protocol": "1.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit df92e11

Please sign in to comment.