Skip to content

Commit

Permalink
secrets: read youtube api key from secrets (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
taraspos authored Nov 1, 2024
1 parent 9e542a4 commit 307ba21
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
12 changes: 5 additions & 7 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "dotenv/config";
import type { Config } from "@docusaurus/types";
import type { VFile } from "vfile";

import { getFromSecretOrEnv } from "./utils/general";
import { loadConfig } from "./server/config-docs";
import {
getDocusaurusConfigVersionOptions,
Expand All @@ -26,14 +27,11 @@ const latestVersion = getLatestVersion();

const config: Config = {
customFields: {
inkeepConfig: (() => {
const configVars = process.env.secrets ? JSON.parse(process.env.secrets) : process.env;
return {
apiKey: configVars.INKEEP_API_KEY,
integrationId: configVars.INKEEP_INTEGRATION_ID,
organizationId: configVars.INKEEP_ORGANIZATION_ID,
inkeepConfig: {
apiKey: getFromSecretOrEnv("INKEEP_API_KEY"),
integrationId: getFromSecretOrEnv("INKEEP_INTEGRATION_ID"),
organizationId: getFromSecretOrEnv("INKEEP_ORGANIZATION_ID"),
}
})(),
},
clientModules: [
"./src/styles/variables.css",
Expand Down
4 changes: 3 additions & 1 deletion server/youtube-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Gets YouTube video metadate given video ID.
*/

const YOUTUBE_API_KEY = process.env.YOUTUBE_API_KEY;
import { getFromSecretOrEnv } from "../utils/general";

const YOUTUBE_API_KEY = getFromSecretOrEnv("YOUTUBE_API_KEY");

const REQUEST_PATH = "videos";
const YOUTUBE_URL = "https://www.youtube.com/watch";
Expand Down
6 changes: 6 additions & 0 deletions utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ export const filterTextForXSS = (text: string): string => {
}
return text;
};

export const getFromSecretOrEnv = (name: string): string => {
// https://docs.aws.amazon.com/amplify/latest/userguide/environment-secrets.html#access-environment-secrets
const configVars = process.env.secrets ? JSON.parse(process.env.secrets) : process.env;
return configVars[name]
};

0 comments on commit 307ba21

Please sign in to comment.