Skip to content

Commit

Permalink
Changing to use environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
amyfromandi committed Sep 23, 2024
1 parent 422d578 commit 132e0e2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
credentials.ts
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ v1/utilities/scripts/credentials.py
venv
.env

!v2/credentials.ts
credentials.ts
!v1/credentials.ts
v2/utilities/scripts/credentials.py

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ NOTE: Postgres connections are completely broken in node v14 and v15 (as of
This will also run the script `postinstall.sh` which copies credentials files
into place.



**Old config below. We now use env variables specifying which db and environment to connect to.**
For `credentials.ts` fill in your MariaDB and PostgreSQL user information,
update the port for Redis if necessary, and follow the inline instructions for
generating a cache refresh key. The cache refresh key is used as a secret
Expand Down
3 changes: 1 addition & 2 deletions v2/column-cache-refresh.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const larkin = require("./larkin");
const credentials = require("./credentials");

module.exports = (req, res, next) => {
if (
req.query &&
req.query.cacheRefreshKey &&
req.query.cacheRefreshKey === credentials.cacheRefreshKey
req.query.cacheRefreshKey === process.env.CACHE_REFRESH_KEY
) {
larkin.setupCache();
res.json({ success: "cache refreshed" });
Expand Down
3 changes: 1 addition & 2 deletions v2/definitions/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var api = require("../api"),
dbgeo = require("dbgeo"),
gp = require("geojson-precision");

const credentials = require("../credentials");

module.exports = function (req, res, next, cb) {
if (Object.keys(req.query).length < 1) {
Expand Down Expand Up @@ -80,7 +79,7 @@ module.exports = function (req, res, next, cb) {
${"sample" in req.query ? "LIMIT 5" : ""}
`;
larkin.queryPg(
credentials.pg_macrostrat_database,
"burwell",
sql,
params,
function (error, result) {
Expand Down
19 changes: 13 additions & 6 deletions v2/larkin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var //mysql = require("mysql"),
async = require("async"),
_ = require("underscore"),
credentials = require("./credentials"),
csv = require("csv-express"),
api = require("./api"),
defs = require("./defs"),
Expand All @@ -11,6 +10,13 @@ var //mysql = require("mysql"),
const named = require("yesql").pg;
const { Client, Pool } = require("pg");

require('dotenv').config();

const postgresDatabases = {
burwell: "macrostrat",
geomacro: "geomacro",
elevation: "elevation",
};
(function () {
var larkin = {};

Expand Down Expand Up @@ -72,23 +78,24 @@ const { Client, Pool } = require("pg");
//added new method to query from Maria data in the new PG database after migration
larkin.queryPg = function (db, sql, params, callback) {
//add console.logs for debug mode in the future
const nameMapping = credentials.postgresDatabases ?? {};
const nameMapping = postgresDatabases ?? {};
const dbName = nameMapping[db] ?? db;

if (dbName == "geomacro") {
console.warn(
"In Macrostrat v2, 'geomacro' is merged with 'burwell' into the 'macrostrat' database.",
);
}
let connectionDetails = {...process.env.MACROSTRAT_DEV_URL};
let connectionDetails = process.env.MACROSTRAT_DEV_URL;

if (dbName == "elevation") {
/* Special case for elevation database (temporary) */
connectionDetails.database = 'elevation'
connectionDetails = process.env.ELEVATION_DEV_URL;
}

const pool = new Pool(connectionDetails);
console.log(connectionDetails)
const pool = new Pool({
connectionString: connectionDetails
});

pool.connect(function (err, client, done) {
if (err) {
Expand Down

0 comments on commit 132e0e2

Please sign in to comment.