From 74ca83e242efc935d89c097210a94c89fe5ac1e3 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sat, 17 Apr 2021 15:10:31 -0500 Subject: [PATCH] Move pin to secret file --- .env.example | 2 +- src/server/services/TvDb.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 4a4e658..a4463c7 100644 --- a/.env.example +++ b/.env.example @@ -11,7 +11,7 @@ TMDB_KEY_FILE = /run/secrets/tmdb_key # TVDB API key TVDB_KEY_FILE = /run/secrets/tvdb_key -TVDB_PIN = +TVDB_PIN_FILE = /run/secrets/tvdb_pin TVDB_REFRESH_PERIOD = 480 # (8 hours) How frequently to refresh the token (in minutes) # Database ----------------------------------------------------------------------------------------- diff --git a/src/server/services/TvDb.ts b/src/server/services/TvDb.ts index b05ee6e..5dd14e8 100644 --- a/src/server/services/TvDb.ts +++ b/src/server/services/TvDb.ts @@ -2,6 +2,7 @@ import { readFile } from "fs/promises"; import Application from "@server/Application"; import TVDB from "tvdb-v4"; import Service from "./Service"; +import { env, secret } from "@server/util"; /** * The token refresh period in milliseconds @@ -32,7 +33,7 @@ export default class TvDb extends Service * Boot the service */ public async boot() { - let apiKey = (await readFile(process.env["TVDB_KEY_FILE"])).toString().trim(); + let apiKey = await secret(env("TVDB_KEY_FILE")); this.tvdb = new TVDB(apiKey); await this.refreshLogin(); } @@ -52,9 +53,10 @@ export default class TvDb extends Service return; } this.log("Refreshing login token..."); + let pin = await secret(env("TVDB_PIN_FILE")); let timestamp = Date.now() + TOKEN_REFRESH_PERIOD; // Save the time before the request - await this.tvdb.login(process.env["TVDB_PIN"]); - this.nextTokenRefreshTimestamp = timestamp // if succeeds, update the timestamp + await this.tvdb.login(pin); + this.nextTokenRefreshTimestamp = timestamp } /**