remove getSecret, always use env variables

This commit is contained in:
Vyacheslav Matyukhin 2022-03-24 01:07:55 +03:00
parent fad762ab3a
commit f3592cde40
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
12 changed files with 30 additions and 64 deletions

View File

@ -1,5 +1,4 @@
import pkg from "mongodb"; import pkg from "mongodb";
import { getSecret } from "../utils/getSecrets.js";
import { roughSizeOfObject } from "../utils/roughSize.js"; import { roughSizeOfObject } from "../utils/roughSize.js";
const { MongoClient } = pkg; const { MongoClient } = pkg;
@ -9,7 +8,7 @@ export async function mongoUpsert(
collectionName = "metaforecastCollection", collectionName = "metaforecastCollection",
databaseName = "metaforecastDatabase" databaseName = "metaforecastDatabase"
) { ) {
const url = process.env.MONGODB_URL || getSecret("mongodb"); const url = process.env.MONGODB_URL;
const client = new MongoClient(url); const client = new MongoClient(url);
try { try {
await client.connect(); await client.connect();
@ -60,7 +59,7 @@ export async function mongoRead(
collectionName = "metaforecastCollection", collectionName = "metaforecastCollection",
databaseName = "metaforecastDatabase" databaseName = "metaforecastDatabase"
) { ) {
const url = process.env.MONGODB_URL || getSecret("mongodb"); const url = process.env.MONGODB_URL;
const client = new MongoClient(url, { const client = new MongoClient(url, {
useNewUrlParser: true, useNewUrlParser: true,
@ -142,7 +141,7 @@ export async function mongoGetAllElements(
databaseName = "metaforecastDatabase", databaseName = "metaforecastDatabase",
collectionName = "metaforecastCollection" collectionName = "metaforecastCollection"
) { ) {
const url = process.env.MONGODB_URL || getSecret("mongodb"); const url = process.env.MONGODB_URL;
const client = new MongoClient(url, { const client = new MongoClient(url, {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,

View File

@ -1,6 +1,5 @@
import pkg from "pg"; import pkg from "pg";
import { platformNames } from "../platforms/all/platformNames.js"; import { platformNames } from "../platforms/all/platformNames.js";
import { getSecret } from "../utils/getSecrets.js";
import { hash } from "../utils/hash.js"; import { hash } from "../utils/hash.js";
import { roughSizeOfObject } from "../utils/roughSize.js"; import { roughSizeOfObject } from "../utils/roughSize.js";
const { Pool } = pkg; const { Pool } = pkg;
@ -35,9 +34,7 @@ const tableWhiteList = [
]; ];
/* Postgres database connection code */ /* Postgres database connection code */
const databaseURL = const databaseURL = process.env.DIGITALOCEAN_POSTGRES;
process.env.DIGITALOCEAN_POSTGRES || getSecret("digitalocean-postgres");
// process.env.DATABASE_URL || getSecret("heroku-postgres")
export const readWritePool = new Pool({ export const readWritePool = new Pool({
connectionString: databaseURL, connectionString: databaseURL,
ssl: process.env.POSTGRES_NO_SSL ssl: process.env.POSTGRES_NO_SSL
@ -49,7 +46,7 @@ export const readWritePool = new Pool({
const readOnlyDatabaseURL = const readOnlyDatabaseURL =
"postgresql://public_read_only_user:gOcihnLhqRIQUQYt@postgres-red-do-user-10290909-0.b.db.ondigitalocean.com:25060/metaforecastpg?sslmode=require" || "postgresql://public_read_only_user:gOcihnLhqRIQUQYt@postgres-red-do-user-10290909-0.b.db.ondigitalocean.com:25060/metaforecastpg?sslmode=require" ||
getSecret("digitalocean-postgres-public"); process.env.DIGITALOCEAN_POSTGRES_PUBLIC;
const readOnlyPool = new Pool({ const readOnlyPool = new Pool({
// never used // never used
connectionString: readOnlyDatabaseURL, connectionString: readOnlyDatabaseURL,

View File

@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
import { getSecret, applyIfSecretExists } from "../utils/getSecrets.js"; import { applyIfSecretExists } from "../utils/getSecrets.js";
export async function rebuildNetlifySiteWithNewData_inner(cookie) { async function rebuildNetlifySiteWithNewData_inner(cookie) {
let payload = {}; let payload = {};
let response = await axios.post(cookie, payload); let response = await axios.post(cookie, payload);
let data = response.data; let data = response.data;
@ -9,6 +9,6 @@ export async function rebuildNetlifySiteWithNewData_inner(cookie) {
} }
export async function rebuildNetlifySiteWithNewData() { export async function rebuildNetlifySiteWithNewData() {
let cookie = process.env.REBUIDNETLIFYHOOKURL || getSecret("netlify"); let cookie = process.env.REBUIDNETLIFYHOOKURL;
await applyIfSecretExists(cookie, rebuildNetlifySiteWithNewData_inner); await applyIfSecretExists(cookie, rebuildNetlifySiteWithNewData_inner);
} }

View File

@ -1,9 +1,8 @@
/* Imports */ /* Imports */
import fs from "fs";
import axios from "axios"; import axios from "axios";
import https from "https"; import https from "https";
import { calculateStars } from "../utils/stars.js";
import { databaseUpsert } from "../database/database-wrapper.js"; import { databaseUpsert } from "../database/database-wrapper.js";
import { calculateStars } from "../utils/stars.js";
/* Definitions */ /* Definitions */
let endpoint = process.env.SECRET_BETFAIR_ENDPOINT; let endpoint = process.env.SECRET_BETFAIR_ENDPOINT;
@ -142,7 +141,6 @@ export async function betfair() {
let results = await processPredictions(data); // somehow needed let results = await processPredictions(data); // somehow needed
// console.log(results.map(result => ({title: result.title, description: result.description}))) // console.log(results.map(result => ({title: result.title, description: result.description})))
// let string = JSON.stringify(results, null, 2) // let string = JSON.stringify(results, null, 2)
// fs.writeFileSync('polyprediction-questions.json', string);
await databaseUpsert({ contents: results, group: "betfair" }); await databaseUpsert({ contents: results, group: "betfair" });
console.log("Done"); console.log("Done");
} }

View File

@ -1,10 +1,10 @@
/* Imports */ /* Imports */
import axios from "axios"; import axios from "axios";
import { getSecret, applyIfSecretExists } from "../utils/getSecrets.js";
import { Tabletojson } from "tabletojson"; import { Tabletojson } from "tabletojson";
import toMarkdown from "../utils/toMarkdown.js";
import { calculateStars } from "../utils/stars.js";
import { databaseUpsert } from "../utils/database-wrapper.js"; import { databaseUpsert } from "../utils/database-wrapper.js";
import { applyIfSecretExists } from "../utils/getSecrets.js";
import { calculateStars } from "../utils/stars.js";
import toMarkdown from "../utils/toMarkdown.js";
/* Definitions */ /* Definitions */
let htmlEndPoint = "https://www.cset-foretell.com/questions?page="; let htmlEndPoint = "https://www.cset-foretell.com/questions?page=";
@ -278,6 +278,6 @@ async function csetforetell_inner(cookie) {
} }
export async function csetforetell() { export async function csetforetell() {
let cookie = process.env.CSETFORETELL_COOKIE || getSecret("csetforetell"); let cookie = process.env.CSETFORETELL_COOKIE;
await applyIfSecretExists(cookie, csetforetell_inner); await applyIfSecretExists(cookie, csetforetell_inner);
} }

View File

@ -1,12 +1,10 @@
/* Imports */ /* Imports */
import fs from "fs";
import axios from "axios"; import axios from "axios";
import https from "https"; import https from "https";
import fetch from "isomorphic-fetch";
import { getSecret, applyIfSecretExists } from "../utils/getSecrets.js";
import toMarkdown from "../utils/toMarkdown.js";
import { calculateStars } from "../utils/stars.js";
import { databaseUpsert } from "../utils/database-wrapper.js"; import { databaseUpsert } from "../utils/database-wrapper.js";
import { applyIfSecretExists } from "../utils/getSecrets.js";
import { calculateStars } from "../utils/stars.js";
import toMarkdown from "../utils/toMarkdown.js";
/* Definitions */ /* Definitions */
let hypermindEnpoint1 = "https://predict.hypermind.com/dash/jsx.json"; let hypermindEnpoint1 = "https://predict.hypermind.com/dash/jsx.json";
@ -200,6 +198,6 @@ async function hypermind_inner(cookie) {
//hypermind() //hypermind()
export async function hypermind() { export async function hypermind() {
let cookie = process.env.HYPERMINDCOOKIE || getSecret("hypermind"); let cookie = process.env.HYPERMINDCOOKIE;
await applyIfSecretExists(cookie, hypermind_inner); await applyIfSecretExists(cookie, hypermind_inner);
} }

View File

@ -1,9 +1,7 @@
/* Imports */ /* Imports */
import fs from "fs";
import axios from "axios"; import axios from "axios";
import toMarkdown from "../utils/toMarkdown.js";
import { calculateStars } from "../utils/stars.js";
import { databaseUpsert } from "../database/database-wrapper.js"; import { databaseUpsert } from "../database/database-wrapper.js";
import { calculateStars } from "../utils/stars.js";
/* Definitions */ /* Definitions */
let endpoint = "https://example.com/"; let endpoint = "https://example.com/";
@ -63,7 +61,6 @@ export async function example() {
let results = await processPredictions(data); // somehow needed let results = await processPredictions(data); // somehow needed
// console.log(results) // console.log(results)
// let string = JSON.stringify(results, null, 2) // let string = JSON.stringify(results, null, 2)
// fs.writeFileSync('polyprediction-questions.json', string);
await databaseUpsert({ contents: results, group: "example" }); await databaseUpsert({ contents: results, group: "example" });
console.log("Done"); console.log("Done");
} }

View File

@ -1,11 +1,10 @@
/* Imports */ /* Imports */
import fs from "fs";
import axios from "axios"; import axios from "axios";
import { getSecret, applyIfSecretExists } from "../utils/getSecrets.js";
import { Tabletojson } from "tabletojson"; import { Tabletojson } from "tabletojson";
import { databaseUpsert } from "../database/database-wrapper.js";
import { applyIfSecretExists } from "../utils/getSecrets.js";
import { calculateStars } from "../utils/stars.js"; import { calculateStars } from "../utils/stars.js";
import toMarkdown from "../utils/toMarkdown.js"; import toMarkdown from "../utils/toMarkdown.js";
import { databaseUpsert } from "../database/database-wrapper.js";
/* Definitions */ /* Definitions */
let htmlEndPoint = "https://www.gjopen.com/questions?page="; let htmlEndPoint = "https://www.gjopen.com/questions?page=";
@ -236,7 +235,6 @@ async function goodjudgmentopen_inner(cookie) {
} }
export async function goodjudgmentopen() { export async function goodjudgmentopen() {
let cookie = let cookie = process.env.GOODJUDGMENTOPENCOOKIE;
process.env.GOODJUDGMENTOPENCOOKIE || getSecret("goodjudmentopen");
await applyIfSecretExists(cookie, goodjudgmentopen_inner); await applyIfSecretExists(cookie, goodjudgmentopen_inner);
} }

View File

@ -1,10 +1,10 @@
/* Imports */ /* Imports */
import axios from "axios"; import axios from "axios";
import { getSecret, applyIfSecretExists } from "../utils/getSecrets.js";
import { Tabletojson } from "tabletojson"; import { Tabletojson } from "tabletojson";
import toMarkdown from "../utils/toMarkdown.js";
import { calculateStars } from "../utils/stars.js";
import { databaseUpsert } from "../database/database-wrapper.js"; import { databaseUpsert } from "../database/database-wrapper.js";
import { applyIfSecretExists } from "../utils/getSecrets.js";
import { calculateStars } from "../utils/stars.js";
import toMarkdown from "../utils/toMarkdown.js";
/* Definitions */ /* Definitions */
let htmlEndPoint = "https://www.infer-pub.com/questions"; let htmlEndPoint = "https://www.infer-pub.com/questions";
@ -282,6 +282,6 @@ async function infer_inner(cookie) {
} }
export async function infer() { export async function infer() {
let cookie = process.env.INFER_COOKIE || getSecret("infer"); let cookie = process.env.INFER_COOKIE;
await applyIfSecretExists(cookie, infer_inner); await applyIfSecretExists(cookie, infer_inner);
} }

View File

@ -1,12 +1,10 @@
/* Imports */ /* Imports */
import fs from "fs";
// import axios from "axios" // import axios from "axios"
import { GoogleSpreadsheet } from "google-spreadsheet"; import { GoogleSpreadsheet } from "google-spreadsheet";
import { getSecret, applyIfSecretExists } from "../utils/getSecrets.js";
import toMarkdown from "../utils/toMarkdown.js";
import { calculateStars } from "../utils/stars.js";
import { hash } from "../utils/hash.js";
import { databaseUpsert } from "../database/database-wrapper.js"; import { databaseUpsert } from "../database/database-wrapper.js";
import { applyIfSecretExists } from "../utils/getSecrets.js";
import { hash } from "../utils/hash.js";
import { calculateStars } from "../utils/stars.js";
/* Definitions */ /* Definitions */
const SHEET_ID = "1xcgYF7Q0D95TPHLLSgwhWBHFrWZUGJn7yTyAhDR4vi0"; // spreadsheet key is the long id in the sheets URL const SHEET_ID = "1xcgYF7Q0D95TPHLLSgwhWBHFrWZUGJn7yTyAhDR4vi0"; // spreadsheet key is the long id in the sheets URL
@ -132,6 +130,6 @@ export async function wildeford_inner(google_api_key) {
//example() //example()
export async function wildeford() { export async function wildeford() {
const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY || getSecret("google-api"); // See: https://developers.google.com/sheets/api/guides/authorizing#APIKey const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY; // See: https://developers.google.com/sheets/api/guides/authorizing#APIKey
await applyIfSecretExists(GOOGLE_API_KEY, wildeford_inner); await applyIfSecretExists(GOOGLE_API_KEY, wildeford_inner);
} }

View File

@ -1,10 +1,8 @@
import algoliasearch from "algoliasearch"; import algoliasearch from "algoliasearch";
import fs from "fs";
import { getSecret } from "./getSecrets.js";
import { databaseReadWithReadCredentials } from "../database/database-wrapper.js"; import { databaseReadWithReadCredentials } from "../database/database-wrapper.js";
import { mergeEverythingInner } from "../flow/mergeEverything.js"; import { mergeEverythingInner } from "../flow/mergeEverything.js";
let cookie = process.env.ALGOLIA_MASTER_API_KEY || getSecret("algolia"); let cookie = process.env.ALGOLIA_MASTER_API_KEY;
const client = algoliasearch("96UD3NTQ7L", cookie); const client = algoliasearch("96UD3NTQ7L", cookie);
const index = client.initIndex("metaforecast"); const index = client.initIndex("metaforecast");

View File

@ -1,20 +1,3 @@
import fs from "fs";
export function getSecret(property) {
let answer = 0;
try {
let rawcookie = fs.readFileSync("./input/secrets.json");
let cookie = JSON.parse(rawcookie);
if (cookie[property]) {
answer = cookie[property];
console.log(`Got cookie: ${answer.slice(0, 5)}...`);
}
} catch (error) {
console.log(error);
}
return answer;
}
export async function applyIfSecretExists(cookie, fun) { export async function applyIfSecretExists(cookie, fun) {
if (cookie) { if (cookie) {
await fun(cookie); await fun(cookie);