Skip to content

Commit

Permalink
Merge pull request #6 from KillrVideo/support_for_ssl
Browse files Browse the repository at this point in the history
Support for ssl
  • Loading branch information
SonicDMG authored Aug 23, 2018
2 parents 6675ffe + a934ff5 commit 8fef315
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ config/production.yaml

# Webstorm/IDEA
.idea/
.vscode
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions npm-shrinkwrap.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
54 changes: 37 additions & 17 deletions src/utils/cassandra.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -66,22 +66,45 @@ 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);

} 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);
Expand All @@ -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 = ...).
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -145,4 +165,4 @@ export async function initCassandraAsync() {

// Save client instance
clientInstance = client;
};
}

0 comments on commit 8fef315

Please sign in to comment.