-
Notifications
You must be signed in to change notification settings - Fork 51
/
updateWhoopKey.js
70 lines (51 loc) · 1.97 KB
/
updateWhoopKey.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// This script grabs a temp auth token from whoop and sets it as a secret in this repo
const puppeteer = require('puppeteer');
const { Octokit } = require("@octokit/rest");
function delay(timeout) {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
}
const getToken = async () => {
let token = null;
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', request => {
if (request.url().includes("cycles")) {
let headers = request.headers()
if(headers.authorization) {
token = headers.authorization;
}
}
request.continue();
});
await page.goto('https://app.whoop.com');
await page.type('input[name="username"]', process.env.WHOOP_USERNAME);
await page.type('input[name="password"]', process.env.WHOOP_PASSWORD);
await page.click('button');
await page.waitForNavigation();
await delay(2000);
await browser.close();
return token.split(' ')[1];
}
(async () => {
let token = await getToken()
// Get secrets key and key_id so we can encrypt and set a secret
const octokit = new Octokit({auth: process.env.GH_PAT});
const publicKeyData = await octokit.actions.getRepoPublicKey({ owner: "mscoutermarsh", repo: "mscoutermarsh" });
const key_id = publicKeyData.data.key_id
const key = publicKeyData.data.key
const sodium = require('tweetsodium');
const value = token;
// Convert the message and key to Uint8Array's (Buffer implements that interface)
const messageBytes = Buffer.from(value);
const keyBytes = Buffer.from(key, 'base64');
// Encrypt using LibSodium.
const encryptedBytes = sodium.seal(messageBytes, keyBytes);
// Base64 the encrypted secret
const encrypted = Buffer.from(encryptedBytes).toString('base64');
await octokit.actions.createOrUpdateRepoSecret({
owner: "mscoutermarsh", repo: "mscoutermarsh", secret_name: "WHOOP_KEY", encrypted_value: encrypted, key_id: key_id
});
})();