Skip to content

Commit

Permalink
Added Authorize Step in Main Script
Browse files Browse the repository at this point in the history
  • Loading branch information
YashTotale committed Mar 10, 2021
1 parent 37ff995 commit 33e7eed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/clean-up-dry-runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import moment from "moment";
import yargs from "yargs/yargs";

// Internals
import googleAuth from "./Helpers/google-auth";
import googleAuth from "../src/Helpers/General/google-auth";
import Logger from "../src/Helpers/Logger";

const args = yargs(process.argv.slice(2)).option("all", {
Expand Down
2 changes: 1 addition & 1 deletion scripts/upload-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { format } from "prettier";
import moment from "moment";

// Internals
import googleAuth from "./Helpers/google-auth";
import googleAuth from "../src/Helpers/General/google-auth";
import Logger from "../src/Helpers/Logger";

const uploadLogs = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import readline, { createInterface } from "readline";
import { google, Auth } from "googleapis";

// Internals
import Logger from "../../src/Helpers/Logger";
import keyfile from "../../credentials.json";
import Logger from "../Logger";

readline.Interface.prototype.question[promisify.custom] = function (
prompt: string
Expand All @@ -24,13 +23,17 @@ readline.Interface.prototype.questionAsync = promisify(
readline.Interface.prototype.question
);

const TOKEN_PATH = join(__dirname, "..", "..", "oauth-token.json");
const CRED_PATH = join(__dirname, "..", "..", "..", "credentials.json");
const TOKEN_PATH = join(__dirname, "..", "..", "..", "oauth-token.json");

const googleAuth = async (): Promise<Auth.OAuth2Client> => {
const keyfile = await readFile(CRED_PATH, "utf-8");
const creds = JSON.parse(keyfile);

const oAuth2Client = new google.auth.OAuth2(
keyfile.installed.client_id,
keyfile.installed.client_secret,
keyfile.installed.redirect_uris[0]
creds.installed.client_id,
creds.installed.client_secret,
creds.installed.redirect_uris[0]
);

Logger.log("Authorizing...");
Expand All @@ -47,7 +50,9 @@ const googleAuth = async (): Promise<Auth.OAuth2Client> => {
});

Logger.line();
Logger.log(`Authorize this app by visiting this url: ${authUrl}`);
Logger.log(
`${Logger.COLORS.FgBlue}Authorize by signing in with [email protected]${Logger.COLORS.Reset}: ${authUrl}`
);

const rl = createInterface({
input: process.stdin,
Expand Down
1 change: 1 addition & 0 deletions src/Helpers/General/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as escapeRegex } from "./escape-regex";
export { default as flattenFields } from "./flatten-fields";
export { default as getTemplate } from "./get-template";
export { default as normalizeDate } from "./normalize-date";
export { default as googleAuth } from "./google-auth";
4 changes: 3 additions & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "./Helpers/Checks";
import { sendReminderEmail } from "./Helpers/Email";
import { createGoogleForm } from "./Helpers/Forms";
import { parseProject, flattenFields } from "./Helpers/General";
import { parseProject, flattenFields, googleAuth } from "./Helpers/General";
import Logger from "./Helpers/Logger";
import { FIELDS } from "./Utils/constants";

Expand All @@ -42,6 +42,8 @@ const script = async () => {

const logger = new Logger(dryRun);
try {
await googleAuth();

const table = Airtable.base(process.env.AIRTABLE_BASE_ID ?? "");

const standardQuestions = await getStandardQuestions(table);
Expand Down

0 comments on commit 33e7eed

Please sign in to comment.