diff --git a/.github/workflows/src/app/education-web.js b/.github/workflows/src/app/education-web.js new file mode 100644 index 00000000..932f700e --- /dev/null +++ b/.github/workflows/src/app/education-web.js @@ -0,0 +1,47 @@ +const axios = require('axios'); + +class EducationWeb { + constructor() { + + } + + async hasPack(github_identifier) { + await this.authenticate() + + const result = await axios({ + method: "get", + url: process.env.EDUCATION_WEB_API + "/api/user", + headers: { + "Authorization": "token " + this.authToken, + "Accept": "application/vnd.education.github.v2" + }, + params: { github_identifier: github_identifier } + }) + + const user_type = result?.data?.user?.type + + return (user_type === "faculty" || user_type === "student") + } + + async authenticate() { + if(this.authToken) { + return + } + + const result = await axios({ + method: "post", + url: process.env.EDUCATION_WEB_API + "/api/auth", + headers: { + "Accept": "application/vnd.education.github.v2" + }, + data: { + key: process.env.EDUCATION_WEB_KEY, + secret: process.env.EDUCATION_WEB_SECRET + } + }) + + this.authToken = result.data.jwt + } +} + +module.exports = new EducationWeb() diff --git a/.github/workflows/src/package-lock.json b/.github/workflows/src/package-lock.json index 6e9574d4..9238d7b0 100644 --- a/.github/workflows/src/package-lock.json +++ b/.github/workflows/src/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "airtable": "^0.11.0", + "axios": "^0.21.1", "dotenv": "^8.2.0", "octokit": "^1.0.3" } @@ -333,6 +334,14 @@ "node": ">=8.0.0" } }, + "node_modules/axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "dependencies": { + "follow-redirects": "^1.10.0" + } + }, "node_modules/before-after-hook": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.1.tgz", @@ -390,6 +399,25 @@ "node": ">=6" } }, + "node_modules/follow-redirects": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz", + "integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", @@ -906,6 +934,14 @@ "node-fetch": "^2.6.1" } }, + "axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, "before-after-hook": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.1.tgz", @@ -954,6 +990,11 @@ "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==" }, + "follow-redirects": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz", + "integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg==" + }, "fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", diff --git a/.github/workflows/src/package.json b/.github/workflows/src/package.json index 52895825..831eaa55 100644 --- a/.github/workflows/src/package.json +++ b/.github/workflows/src/package.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "airtable": "^0.11.0", + "axios": "^0.21.1", "dotenv": "^8.2.0", "octokit": "^1.0.3" }