From 8f24bb3cc110f3fe8b1a22717199881576d6698c Mon Sep 17 00:00:00 2001 From: Mike Conrad Date: Thu, 7 Sep 2023 08:45:43 -0400 Subject: [PATCH] Simplified code to demonstrate issue with comma --- src/env.d.ts | 12 -------- src/tokenList.ts | 8 ++--- src/tokens.example.ts | 10 ------- src/tokens.ts | 11 ++++++- src/utils/api.ts | 68 ------------------------------------------- src/utils/types.ts | 15 ++++++++++ 6 files changed, 29 insertions(+), 95 deletions(-) delete mode 100644 src/env.d.ts delete mode 100644 src/tokens.example.ts delete mode 100644 src/utils/api.ts create mode 100644 src/utils/types.ts diff --git a/src/env.d.ts b/src/env.d.ts deleted file mode 100644 index b15b3a2..0000000 --- a/src/env.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -interface ImportMetaEnv { - readonly VITE_AKEYLESS_KEY_PATH: string - readonly VITE_AKEYLESS_ACCESS_ID: string - readonly VITE_AKEYLESS_ACCESS_KEY: string - // more env variables... - } - - interface ImportMeta { - readonly env: ImportMetaEnv - } \ No newline at end of file diff --git a/src/tokenList.ts b/src/tokenList.ts index 0f36191..04b0170 100644 --- a/src/tokenList.ts +++ b/src/tokenList.ts @@ -1,9 +1,9 @@ import { displayTokenListItem } from "./tokenListItem"; -import { Token, decryptTokensWithAkeyless } from "./utils/api"; - +import { tokens } from "./tokens"; +import { Token } from "./utils/types"; +console.log('tokens', tokens) export async function tokenList() { - const decryptedTokens = (await decryptTokensWithAkeyless(import.meta.env.VITE_AKEYLESS_KEY_PATH)) - return `
${decryptedTokens.map((token: Token) => + return `${tokens.map((token: Token) => displayTokenListItem(token.account, token.secret) )}
`; } diff --git a/src/tokens.example.ts b/src/tokens.example.ts deleted file mode 100644 index 62db9fd..0000000 --- a/src/tokens.example.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const tokens = [ - { - account: 'Github', - secret: 'AFDAFDAFAFFD', - }, - { - account: 'Gmail', - secret: 'AFDJKADFJsddfsKLAFSJLK', - }, -] \ No newline at end of file diff --git a/src/tokens.ts b/src/tokens.ts index af110e9..b9ab677 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -1 +1,10 @@ -export const tokens = "AQAAAAEIAd3tVg6Vbzp/2fXBP6JdFoK7A5fu5n8daqwUzGKK3CgAYW+SujAoXcK5R3QgGkUp34Vi/DEtjOU9WNd3vGIMZAUQhngRqDS0rfK3i8kN4/C5oBjhkYhWKY6ABbJtmnI9p4EzfnC5RkZlSpHFNK6yAxk2jJVAFU6ynXkqVZKLamtf+aViyYyX8wI=" \ No newline at end of file +export const tokens = [ + { + "account": "Github", + "secret": "AFDAFDAFAFFD" + }, + { + "account": "Gmail", + "secret": "AFDJKADFJsddfsKLAFSJLK" + } +] \ No newline at end of file diff --git a/src/utils/api.ts b/src/utils/api.ts deleted file mode 100644 index 3b5d867..0000000 --- a/src/utils/api.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { tokens } from "../tokens"; - -export interface TokenResponse { - token: string; - creds: null; -} - -export interface Token { - account: string; - secret: string; - } - -export interface GenericAPIResponse { - result: string; -} - -const baseUrl = 'https://api.akeyless.io' -async function fetchAkeylessAuthToken(): Promise { - - const options = { - method: 'POST', - headers: {accept: 'application/json', 'content-type': 'application/json'}, - body: JSON.stringify({ - 'access-type': 'access_key', - 'gcp-audience': 'akeyless.io', - json: false, - 'access-id': import.meta.env.VITE_AKEYLESS_ACCESS_ID, - 'access-key': import.meta.env.VITE_AKEYLESS_ACCESS_KEY - }) - }; - const token = await fetch(`${baseUrl}/auth`, options) - return await token.json() - -} - -async function encryptTokensWithAkeyless(encryptionKeyName: string): Promise{ - const options = { - method: 'POST', - headers: {accept: 'application/json', 'content-type': 'application/json'}, - body: JSON.stringify({ - json: false, - 'key-name': encryptionKeyName, - plaintext: JSON.stringify(tokens), - token: (await fetchAkeylessAuthToken()).token - }) - }; - - const response = await fetch(`${baseUrl}/encrypt`, options) - return await response.json() -} - -async function decryptTokensWithAkeyless(encryptionKeyName: string): Promise{ - const options = { - method: 'POST', - headers: {accept: 'application/json', 'content-type': 'application/json'}, - body: JSON.stringify({ - json: false, - 'key-name': encryptionKeyName, - ciphertext: tokens, - token: (await fetchAkeylessAuthToken()).token - }) - }; - - const response = await fetch(`${baseUrl}/decrypt`, options) - const decodedTokens = await response.json() - return JSON.parse(decodedTokens.result) -} -export {fetchAkeylessAuthToken, encryptTokensWithAkeyless, decryptTokensWithAkeyless} \ No newline at end of file diff --git a/src/utils/types.ts b/src/utils/types.ts new file mode 100644 index 0000000..dae45a1 --- /dev/null +++ b/src/utils/types.ts @@ -0,0 +1,15 @@ +import { tokens } from "../tokens"; + +export interface TokenResponse { + token: string; + creds: null; +} + +export interface Token { + account: string; + secret: string; + } + +export interface GenericAPIResponse { + result: string; +}