Skip to content

Commit

Permalink
moved Mailgun API key (private) to env; owner is still initialized at…
Browse files Browse the repository at this point in the history
… multiple places (should be shared as part of app) and DB create does not seem to work on Circle CI
  • Loading branch information
suculent committed Jan 15, 2023
1 parent 33fa1ea commit 8e591a3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ WORKER_SECRET=twilight_zone
# GITHUB_CLIENT_SECRET=

# Slack Bot Notifications
# SLACK_BOT_TOKEN=
# SLACK_BOT_TOKEN=

# Mailgun API Key
# MAILGUN_API_KEY=
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ ENV ENTERPRISE=${ENTERPRISE}
ARG WORKER_SECRET
ENV WORKER_SECRET=${WORKER_SECRET}

ARG MAILGUN_API_KEY
ENV MAILGUN_API_KEY=${MAILGUN_API_KEY}

# Create app directory
WORKDIR /opt/thinx/thinx-device-api

Expand Down
1 change: 0 additions & 1 deletion conf/config-localhost.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"public_url": "http://localhost",
"api_url": "http://localhost:7443",
"mailgun": {
"api_key": "",
"base_url": "",
"domain": ""
},
Expand Down
1 change: 0 additions & 1 deletion conf/config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"public_url": "<enter-your-console-fqdn>",
"api_url": "<enter-your-api-fqdn>",
"mailgun": {
"api_key": "<mailgun-api-key>",
"base_url": "<mailgun-base-url>",
"domain": "<mailgun-domain>"
},
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ services:
- 'THINX_HOSTNAME=${THINX_HOSTNAME}'
- 'THINX_OWNER_EMAIL=${THINX_OWNER_EMAIL}'
- 'WORKER_SECRET=${WORKER_SECRET}'
- 'MAILGUN_API_KEY=${MAILGUN_API_KEY}'
environment:
- 'AQUA_SEC_TOKEN=${AQUA_SEC_TOKEN}'
- 'COUCHDB_PASS=${COUCHDB_PASS}'
Expand All @@ -137,6 +138,7 @@ services:
- 'THINX_OWNER_EMAIL=${THINX_OWNER_EMAIL}'
- 'WORKER_SECRET=${WORKER_SECRET}'
- 'GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN}'
- 'MAILGUN_API_KEY=${MAILGUN_API_KEY}'
ports:
- '7442:7442'
- '7443:7443'
Expand Down
1 change: 1 addition & 0 deletions docker-swarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ services:
- "GOOGLE_OAUTH_SECRET=${GOOGLE_OAUTH_SECRET}"
- "GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}"
- "GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}"
- 'MAILGUN_API_KEY=${MAILGUN_API_KEY}'
ports:
- '7442:7442'
- '7443:7443'
Expand Down
2 changes: 0 additions & 2 deletions lib/thinx/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ var Globals = (function () {
config.password = process.env.REDIS_PASSWORD;
}

console.log("Redis options:", config); // REMOVE ME!

return config;
},

Expand Down
13 changes: 7 additions & 6 deletions lib/thinx/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Mailgun = require('mailgun.js');
const mailgun = new Mailgun(formData);
const mg = mailgun.client({
username: 'api',
key: app_config.mailgun.api_key
key: process.env.MAILGUN_API_KEY
});

const Database = require("./database.js");
Expand Down Expand Up @@ -84,9 +84,10 @@ module.exports = class Owner {
}

sendMail(contents, type, callback) {
console.log("[debug] sendmail", app_config.mailgun.domain, contents);
//console.log("[debug] sendmail", app_config.mailgun.domain, contents);
mg.messages.create(app_config.mailgun.domain, contents)
.then((/* msg */) => {
.then((msg) => {
console.log("[debug] mg.messages.create", msg);
callback(true, type + "_sent");
}) // logs response data
.catch(err => {
Expand Down Expand Up @@ -313,7 +314,7 @@ module.exports = class Owner {
owner: body.owner,
avatar: this.avatar(body.owner),
info: body.info,
admin: body.admin
admin: (typeof(body.admin) === "undefined") ? false : body.admin
});
});
}
Expand Down Expand Up @@ -750,9 +751,9 @@ module.exports = class Owner {
username = new_owner_hash;
}

this.userlib.get(new_owner_hash, (user_get_error/* , user_get_body */) => {
this.userlib.get(new_owner_hash, (user_get_error, user_get_body ) => {

console.log("[DEBUG] expected error on this.userlib.get when creating", user_get_error);
console.log("[DEBUG] expected error on this.userlib.get when creating", {user_get_error}, {user_get_body} );

// test username, must mirror ../../spec/_envi.json:test_info.username; should not exist in production
if (process.env.ENVIRONMENT === "test") {
Expand Down
2 changes: 1 addition & 1 deletion lib/thinx/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Mailgun = require('mailgun.js');
const mailgun = new Mailgun(formData);
const mg = mailgun.client({
username: 'api',
key: app_config.mailgun.api_key
key: process.env.MAILGUN_API_KEY
});

var fs = require("fs-extra");
Expand Down

0 comments on commit 8e591a3

Please sign in to comment.