Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to Slack #11

Merged
merged 4 commits into from Jul 8, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

feat: eliminate network call from tweeter

improve vault#fetch with default arguments
  • Loading branch information...
maxbeatty committed Jul 8, 2019
commit 286c8ddc929417505f6aa856ec9115e80d411e48
@@ -35,10 +35,10 @@ export class Vault {
}

async fetch(
maxTries /*: number */,
howLong /*: number */,
sep /*: string */,
scoreThreshold /*: number */
howLong /*: number */ = 4,
sep /*: string */ = "-",
maxTries /*: number */ = 10,
scoreThreshold /*: number */ = 4 // Zxcvbn maximum
) /*: Promise<string> */ {
if (maxTries === 0) {
throw new Error("Unable to generate strong passphrase");
@@ -67,7 +67,7 @@ export class Vault {
return phrase;
} catch (error) {
console.error(error);
return this.fetch(--maxTries, howLong, sep, scoreThreshold);
return this.fetch(howLong, sep, --maxTries, scoreThreshold);
}
}
}
@@ -3,7 +3,6 @@
const { captureError } = require("../lib/errors");
const { Vault } = require("../lib/vault");

const MAX_TRIES = 10;
const MAX_LEN = 7;

const v = new Vault();
@@ -26,15 +25,8 @@ module.exports = async (req /*: $FlowFixMe */, res /*: $FlowFixMe */) => {
}
}

const SCORE_THRESHOLD = 4; // Zxcvbn maximum

await v.load();
const passphrase = await v.fetch(
MAX_TRIES,
LENGTH,
SEPARATOR,
SCORE_THRESHOLD
);
const passphrase = await v.fetch(LENGTH, SEPARATOR);
const permutations = v.getPermutations(LENGTH);

res.send(`
@@ -4,6 +4,7 @@ const assert = require("assert");
const { get, post } = require("request-promise-native");

const { captureError } = require("../lib/errors");
const { Vault } = require("../lib/vault");

assert(
process.env.PASSPLUM_TWEETER_SECRET,
@@ -19,7 +20,7 @@ const oauth = {
token_secret: process.env.TWITTER_ACCESS_SECRET
};

const RE = /<code\s.+?>(.+?)<\/code>/g;
const v = new Vault();

module.exports = async (req /*: $FlowFixMe */, res /*: $FlowFixMe */) => {
if (req.headers.authorization !== secret) {
@@ -29,21 +30,14 @@ module.exports = async (req /*: $FlowFixMe */, res /*: $FlowFixMe */) => {
}

try {
const body = await get("https://passplum.com");
const matches = RE.exec(body);

if (!matches || matches.length < 2) {
const err = new Error("could not find passphrase");
// $FlowFixMe - I do what I want
err.body = body;
throw err;
}
await v.load();
const passphrase = await v.fetch();

await post({
url: "https://api.twitter.com/1.1/statuses/update.json",
oauth,
qs: {
status: "Here is a great password: " + matches[1]
status: "Here is a great password: " + passphrase
}
});

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.