diff --git a/.gitignore b/.gitignore index 7d72234..17a0418 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ config/production.yaml # Webstorm/IDEA .idea/ +.vscode \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index aefccfa..92a06cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ WORKDIR /opt/killrvideo-generator # Copy package.json for dependencies COPY package.json /opt/killrvideo-generator/ COPY npm-shrinkwrap.json /opt/killrvideo-generator/ - + # Add dependencies for node-gyp, then run npm install and remove dependencies RUN set -x \ && apt-get update \ diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0f43e65..d1c6e9b 100755 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "killrvideo-generator", - "version": "1.2.6", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2268,8 +2268,8 @@ "dev": true }, "grpc": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.10.1.tgz", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.0.0.tgz", "integrity": "sha512-xmhA11h2XhqpSVzDAmoQAYdNQ+swILXpKOiRpAEQ2kX55ioxVADc6v7SkS4zQBxm4klhQHgGqpGKvoL6LGx4VQ==", "requires": { "lodash": "4.17.5", diff --git a/package.json b/package.json index 742fab1..eb53705 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "killrvideo-generator", - "version": "1.2.6", + "version": "2.1.0", "description": "Sample Data generator for KillrVideo", "main": "dist/index.js", "scripts": { @@ -31,7 +31,7 @@ "dse-driver": "^1.6.0", "faker": "^3.1.0", "googleapis": "^12.4.0", - "grpc": "^1.10.1", + "grpc": "^1.0.0", "js-yaml": "^3.11.0", "later": "^1.2.0", "regenerator-runtime": "^0.9.6", diff --git a/src/utils/cassandra.js b/src/utils/cassandra.js index 8b12b27..e73abbe 100644 --- a/src/utils/cassandra.js +++ b/src/utils/cassandra.js @@ -1,8 +1,8 @@ import Promise from 'bluebird'; import config from 'config'; -import { Client, auth, types as CassandraTypes } from 'dse-driver'; -import { logger } from './logging'; -import { lookupServiceAsync } from './lookup-service'; +import {auth, Client, types as CassandraTypes} from 'dse-driver'; +import {logger} from './logging'; +import {lookupServiceAsync} from './lookup-service'; /** * An array of CQL table strings to use for the schema. @@ -66,14 +66,14 @@ export function getCassandraClientAsync(keyspace, dseUsername, dsePassword) { clientOpts.keyspace = keyspace; } - /** - * Check for both KILLRVIDEO_DSE_USERNAME and KILLRVIDEO_DSE_PASSWORD environment - * variables. If they both exist use the values set within them. If not, - * use default values for authentication. - */ + /** + * Check for both KILLRVIDEO_DSE_USERNAME and KILLRVIDEO_DSE_PASSWORD environment + * variables. If they both exist use the values set within them. If not, + * use default values for authentication. + */ if (dseUsername && dsePassword) { let passwordLength = dsePassword.length; - logger.info('Using supplied DSE username: "' + dseUsername + '" and password: "***' + dsePassword.substring(passwordLength - 4, passwordLength) + '" from environment variables') + logger.info('Using supplied DSE username: "' + dseUsername + '" and password: "***' + dsePassword.substring(passwordLength - 4, passwordLength) + '" from environment variables'); // Use the values passed in from the config clientOpts.authProvider = new auth.DsePlainTextAuthProvider(dseUsername, dsePassword); @@ -81,7 +81,30 @@ export function getCassandraClientAsync(keyspace, dseUsername, dsePassword) { } else { logger.info('No detected username/password combination was passed in. DSE cluster authentication method was NOT executed.'); } - + + let Filesystem = require("fs"); + let sslStat = process.env.KILLRVIDEO_ENABLE_SSL; + logger.info(sslStat); + + if (sslStat === "true") { + logger.info('SSL is configured to be on.'); + if (Filesystem.existsSync('cassandra.cert')) { + clientOpts.sslOptions = { + ca: [Filesystem.readFileSync('cassandra.cert')], + // validate server cert and reject if not trusted + requestCert: true, + rejectUnauthorized: true + }; + logger.info('Found cert, read file sync.') + } else { + logger.info('No cert found, SSL not enabled.') + } + } else if (sslStat === "false") { + logger.info('SSL is configured to be off.') + } else { + logger.info('SSL is not configured, should it be set?') + } + // Create a client and promisify it let client = new Client(clientOpts); client = Promise.promisifyAll(client); @@ -96,8 +119,7 @@ export function getCassandraClientAsync(keyspace, dseUsername, dsePassword) { clientPromises.set(keyspace, promise); return promise; -}; - +} /** * Creates a keyspace in Cassandra if it doesn't already exist. Pass the name of the keyspace and the * string to be used as the REPLICATION setting (i.e. after WITH REPLIACTION = ...). @@ -108,8 +130,7 @@ function createKeyspaceIfNotExistsAsync(keyspace, replication, dseUsername, dseP // Get a client, then create the keyspace return getCassandraClientAsync(null, dseUsername, dsePassword).then(client => client.executeAsync(cql)); -}; - +} /** * Create the tables if they don't already exist. */ @@ -129,8 +150,7 @@ export function getCassandraClient() { throw new Error('No client instance found. Did you forget to call initCassandraAsync?'); } return clientInstance; -}; - +} /** * Initializes the Cassandra keyspace and schema needed. */ @@ -145,4 +165,4 @@ export async function initCassandraAsync() { // Save client instance clientInstance = client; -}; \ No newline at end of file +}