-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed frontend to use the new secrets routes
- Loading branch information
1 parent
b6189a9
commit 486aa13
Showing
23 changed files
with
649 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Fragment } from 'react'; | ||
import { useTranslation } from "next-i18next"; | ||
import { faDownload } from '@fortawesome/free-solid-svg-icons'; | ||
import { Menu, Transition } from '@headlessui/react'; | ||
|
||
import Button from '../basic/buttons/Button'; | ||
import downloadDotEnv from '../utilities/secrets/downloadDotEnv'; | ||
import downloadYaml from '../utilities/secrets/downloadYaml'; | ||
|
||
|
||
interface SecretDataProps { | ||
type: 'personal' | 'shared'; | ||
pos: number; | ||
key: string; | ||
value: string; | ||
id: string; | ||
comment: string; | ||
} | ||
|
||
/** | ||
* This is the menu that is used to download secrets as .env ad .yml files (in future we may have more options) | ||
* @param {object} obj | ||
* @param {SecretDataProps[]} obj.data - secrets that we want to downlaod | ||
* @param {string} obj.env - the environment which we're downloading (used for naming the file) | ||
*/ | ||
const DownloadSecretMenu = ({ data, env }: { data: SecretDataProps[]; env: string; }) => { | ||
const { t } = useTranslation(); | ||
|
||
return <Menu | ||
as="div" | ||
className="relative inline-block text-left" | ||
> | ||
<Menu.Button | ||
as="div" | ||
className="inline-flex w-full justify-center text-sm font-medium text-gray-200 rounded-md hover:bg-white/10 duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75" | ||
> | ||
<Button | ||
color="mineshaft" | ||
size="icon-md" | ||
icon={faDownload} | ||
onButtonPressed={() => {}} | ||
/> | ||
</Menu.Button> | ||
<Transition | ||
as={Fragment} | ||
enter="transition ease-out duration-100" | ||
enterFrom="transform opacity-0 scale-95" | ||
enterTo="transform opacity-100 scale-100" | ||
leave="transition ease-in duration-75" | ||
leaveFrom="transform opacity-100 scale-100" | ||
leaveTo="transform opacity-0 scale-95" | ||
> | ||
<Menu.Items className="absolute z-50 drop-shadow-xl right-0 mt-0.5 w-[12rem] origin-top-right rounded-md bg-bunker border border-mineshaft-500 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none p-2 space-y-2"> | ||
<Menu.Item> | ||
<Button | ||
color="mineshaft" | ||
onButtonPressed={() => downloadDotEnv({ data, env })} | ||
size="md" | ||
text="Download as .env" | ||
/> | ||
</Menu.Item> | ||
<Menu.Item> | ||
<Button | ||
color="mineshaft" | ||
onButtonPressed={() => downloadYaml({ data, env })} | ||
size="md" | ||
text="Download as .yml" | ||
/> | ||
</Menu.Item> | ||
</Menu.Items> | ||
</Transition> | ||
</Menu> | ||
} | ||
|
||
export default DownloadSecretMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
interface SecretDataProps { | ||
type: 'personal' | 'shared'; | ||
pos: number; | ||
key: string; | ||
value: string; | ||
id: string; | ||
comment: string; | ||
} | ||
|
||
/** | ||
* This function downloads the secrets as a .env file | ||
* @param {object} obj | ||
* @param {SecretDataProps[]} obj.data - secrets that we want to check for overrides | ||
* @returns | ||
*/ | ||
const checkOverrides = async ({ data }: { data: SecretDataProps[]; }) => { | ||
let secrets : SecretDataProps[] = data!.map((secret) => Object.create(secret)); | ||
const overridenSecrets = data!.filter( | ||
(secret) => secret.type === 'personal' | ||
); | ||
if (overridenSecrets.length) { | ||
overridenSecrets.forEach((secret) => { | ||
const index = secrets!.findIndex( | ||
(_secret) => _secret.key === secret.key && _secret.type === 'shared' | ||
); | ||
secrets![index].value = secret.value; | ||
}); | ||
secrets = secrets!.filter((secret) => secret.type === 'shared'); | ||
} | ||
return secrets; | ||
} | ||
|
||
export default checkOverrides; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { envMapping } from "../../../public/data/frequentConstants"; | ||
import checkOverrides from './checkOverrides'; | ||
|
||
|
||
interface SecretDataProps { | ||
type: 'personal' | 'shared'; | ||
pos: number; | ||
key: string; | ||
value: string; | ||
id: string; | ||
comment: string; | ||
} | ||
|
||
/** | ||
* This function downloads the secrets as a .env file | ||
* @param {object} obj | ||
* @param {SecretDataProps[]} obj.data - secrets that we want to download | ||
* @param {string} obj.env - the environment which we're downloading (used for naming the file) | ||
*/ | ||
const downloadDotEnv = async ({ data, env }: { data: SecretDataProps[]; env: string; }) => { | ||
if (!data) return; | ||
const secrets = await checkOverrides({ data }); | ||
|
||
const file = secrets! | ||
.map( | ||
(item: SecretDataProps) => | ||
`${ | ||
item.comment | ||
? item.comment | ||
.split('\n') | ||
.map((comment) => '# '.concat(comment)) | ||
.join('\n') + '\n' | ||
: '' | ||
}` + [item.key, item.value].join('=') | ||
) | ||
.join('\n'); | ||
|
||
const blob = new Blob([file]); | ||
const fileDownloadUrl = URL.createObjectURL(blob); | ||
const alink = document.createElement('a'); | ||
alink.href = fileDownloadUrl; | ||
alink.download = envMapping[env] + '.env'; | ||
alink.click(); | ||
} | ||
|
||
export default downloadDotEnv; |
Oops, something went wrong.