Simplified code to demonstrate issue with comma

This commit is contained in:
Mike Conrad
2023-09-07 08:45:43 -04:00
parent fe8ea62a98
commit 8f24bb3cc1
6 changed files with 29 additions and 95 deletions

12
src/env.d.ts vendored
View File

@ -1,12 +0,0 @@
/// <reference types="vite/client" />
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
}

View File

@ -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 `<form id="tokens">${decryptedTokens.map((token: Token) =>
return `<form id="tokens">${tokens.map((token: Token) =>
displayTokenListItem(token.account, token.secret)
)}</form>`;
}

View File

@ -1,10 +0,0 @@
export const tokens = [
{
account: 'Github',
secret: 'AFDAFDAFAFFD',
},
{
account: 'Gmail',
secret: 'AFDJKADFJsddfsKLAFSJLK',
},
]

View File

@ -1 +1,10 @@
export const tokens = "AQAAAAEIAd3tVg6Vbzp/2fXBP6JdFoK7A5fu5n8daqwUzGKK3CgAYW+SujAoXcK5R3QgGkUp34Vi/DEtjOU9WNd3vGIMZAUQhngRqDS0rfK3i8kN4/C5oBjhkYhWKY6ABbJtmnI9p4EzfnC5RkZlSpHFNK6yAxk2jJVAFU6ynXkqVZKLamtf+aViyYyX8wI="
export const tokens = [
{
"account": "Github",
"secret": "AFDAFDAFAFFD"
},
{
"account": "Gmail",
"secret": "AFDJKADFJsddfsKLAFSJLK"
}
]

View File

@ -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<TokenResponse> {
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<GenericAPIResponse>{
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<Token[]>{
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}

15
src/utils/types.ts Normal file
View File

@ -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;
}