Refactor infisical-node to config file for birds eye view of envars

This commit is contained in:
Tuan Dang
2023-03-15 00:09:40 +07:00
parent 31111fc63b
commit a6c8638345
33 changed files with 264 additions and 262 deletions
+30 -17
View File
@@ -1,4 +1,3 @@
import infisical from 'infisical-node';
import * as Sentry from '@sentry/node';
import request from '../config/request';
import {
@@ -15,6 +14,20 @@ import {
INTEGRATION_GITHUB_TOKEN_URL,
INTEGRATION_GITLAB_TOKEN_URL
} from '../variables';
import {
getSiteURL,
getClientIdAzure,
getClientSecretAzure,
getClientSecretHeroku,
getClientIdVercel,
getClientSecretVercel,
getClientIdNetlify,
getClientSecretNetlify,
getClientIdGitHub,
getClientSecretGitHub,
getClientIdGitLab,
getClientSecretGitLab
} from '../config';
interface ExchangeCodeAzureResponse {
token_type: string;
@@ -146,9 +159,9 @@ const exchangeCodeAzure = async ({
grant_type: 'authorization_code',
code: code,
scope: 'https://vault.azure.net/.default openid offline_access',
client_id: infisical.get('CLIENT_ID_AZURE')!,
client_secret: infisical.get('CLIENT_SECRET_AZURE')!,
redirect_uri: `${infisical.get('SITE_URL')!}/integrations/azure-key-vault/oauth2/callback`
client_id: getClientIdAzure(),
client_secret: getClientSecretAzure(),
redirect_uri: `${getSiteURL()}/integrations/azure-key-vault/oauth2/callback`
} as any)
)).data;
@@ -191,7 +204,7 @@ const exchangeCodeHeroku = async ({
new URLSearchParams({
grant_type: 'authorization_code',
code: code,
client_secret: infisical.get('CLIENT_SECRET_HEROKU')!
client_secret: getClientSecretHeroku()
} as any)
)).data;
@@ -229,9 +242,9 @@ const exchangeCodeVercel = async ({ code }: { code: string }) => {
INTEGRATION_VERCEL_TOKEN_URL,
new URLSearchParams({
code: code,
client_id: infisical.get('CLIENT_ID_VERCEL')!,
client_secret: infisical.get('CLIENT_SECRET_VERCEL')!,
redirect_uri: `${infisical.get('SITE_URL')!}/integrations/vercel/oauth2/callback`
client_id: getClientIdVercel(),
client_secret: getClientSecretVercel(),
redirect_uri: `${getSiteURL()}/integrations/vercel/oauth2/callback`
} as any)
)
).data;
@@ -269,9 +282,9 @@ const exchangeCodeNetlify = async ({ code }: { code: string }) => {
new URLSearchParams({
grant_type: 'authorization_code',
code: code,
client_id: infisical.get('CLIENT_ID_NETLIFY')!,
client_secret: infisical.get('CLIENT_SECRET_NETLIFY')!,
redirect_uri: `${infisical.get('SITE_URL')!}/integrations/netlify/oauth2/callback`
client_id: getClientIdNetlify(),
client_secret: getClientSecretNetlify(),
redirect_uri: `${getSiteURL()}/integrations/netlify/oauth2/callback`
} as any)
)
).data;
@@ -320,10 +333,10 @@ const exchangeCodeGithub = async ({ code }: { code: string }) => {
res = (
await request.get(INTEGRATION_GITHUB_TOKEN_URL, {
params: {
client_id: infisical.get('CLIENT_ID_GITHUB')!,
client_secret: infisical.get('CLIENT_SECRET_GITHUB')!,
client_id: getClientIdGitHub(),
client_secret: getClientSecretGitHub(),
code: code,
redirect_uri: `${infisical.get('SITE_URL')!}/integrations/github/oauth2/callback`
redirect_uri: `${getSiteURL()}/integrations/github/oauth2/callback`
},
headers: {
'Accept': 'application/json',
@@ -366,9 +379,9 @@ const exchangeCodeGitlab = async ({ code }: { code: string }) => {
new URLSearchParams({
grant_type: 'authorization_code',
code: code,
client_id: infisical.get('CLIENT_ID_GITLAB')!,
client_secret: infisical.get('CLIENT_SECRET_GITLAB')!,
redirect_uri: `${infisical.get('SITE_URL')}/integrations/gitlab/oauth2/callback`
client_id: getClientIdGitLab(),
client_secret: getClientSecretGitLab(),
redirect_uri: `${getSiteURL()}/integrations/gitlab/oauth2/callback`
} as any),
{
headers: {
+14 -14
View File
@@ -1,4 +1,3 @@
import infisical from 'infisical-node';
import * as Sentry from '@sentry/node';
import request from '../config/request';
import {
@@ -9,13 +8,6 @@ import {
INTEGRATION_HEROKU,
INTEGRATION_GITLAB,
} from '../variables';
// import {
// CLIENT_ID_AZURE,
// CLIENT_ID_GITLAB,
// CLIENT_SECRET_AZURE,
// CLIENT_SECRET_HEROKU,
// CLIENT_SECRET_GITLAB
// } from '../config';
import {
INTEGRATION_AZURE_TOKEN_URL,
INTEGRATION_HEROKU_TOKEN_URL,
@@ -24,6 +16,14 @@ import {
import {
IntegrationService
} from '../services';
import {
getSiteURL,
getClientIdAzure,
getClientSecretAzure,
getClientSecretHeroku,
getClientIdGitLab,
getClientSecretGitLab
} from '../config';
interface RefreshTokenAzureResponse {
token_type: string;
@@ -133,11 +133,11 @@ const exchangeRefreshAzure = async ({
const { data }: { data: RefreshTokenAzureResponse } = await request.post(
INTEGRATION_AZURE_TOKEN_URL,
new URLSearchParams({
client_id: infisical.get('CLIENT_ID_AZURE')!,
client_id: getClientIdAzure(),
scope: 'openid offline_access',
refresh_token: refreshToken,
grant_type: 'refresh_token',
client_secret: infisical.get('CLIENT_SECRET_AZURE')!
client_secret: getClientSecretAzure()
} as any)
);
@@ -180,7 +180,7 @@ const exchangeRefreshHeroku = async ({
new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: refreshToken,
client_secret: infisical.get('CLIENT_SECRET_HEROKU')!
client_secret: getClientSecretHeroku()
} as any)
);
@@ -223,9 +223,9 @@ const exchangeRefreshGitLab = async ({
new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: refreshToken,
client_id: infisical.get('CLIENT_ID_GITLAB')!,
client_secret: infisical.get('CLIENT_SECRET_GITLAB')!,
redirect_uri: `${infisical.get('SITE_URL')!}/integrations/gitlab/oauth2/callback`
client_id: getClientIdGitLab,
client_secret: getClientSecretGitLab(),
redirect_uri: `${getSiteURL()}/integrations/gitlab/oauth2/callback`
} as any),
{
headers: {