Skip to content

Commit

Permalink
Modify saveOnDisk to accept blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardDowling committed Oct 31, 2024
1 parent efcd60b commit 5d0f966
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
12 changes: 6 additions & 6 deletions lib/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ var ErrCannotDisableSecondFactor = errors.New("cannot disable multi-factor authe
// ValidateResource performs additional resource checks.
func ValidateResource(res types.Resource) error {
if GetModules().Features().Cloud || !IsInsecureTestMode() {
// switch r := res.(type) {
// case types.AuthPreference:
// if !r.IsSecondFactorEnforced() {
// return trace.Wrap(ErrCannotDisableSecondFactor)
// }
// }
switch r := res.(type) {
case types.AuthPreference:
if !r.IsSecondFactorEnforced() {
return trace.Wrap(ErrCannotDisableSecondFactor)
}
}
}

// All checks below are Cloud-specific.
Expand Down
8 changes: 5 additions & 3 deletions web/packages/shared/utils/saveOnDisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@

/**
* saveOnDisk saves content to local disk.
* @param content content to download.
* @param content content to download (string or Blob).
* @param filename preset file name.
* @param fileType file type.
*/
export function saveOnDisk(
content: string,
content: string | Blob,
filename: string,
fileType: string
): void {
const a = document.createElement('a');
const blob = new Blob([content], { type: fileType });

const blob =
content instanceof Blob ? content : new Blob([content], { type: fileType });
a.href = window.URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
Expand Down
26 changes: 18 additions & 8 deletions web/packages/teleport/src/Integrations/IntegrationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import { Box, Flex } from 'design';
import Table, { Cell } from 'design/DataTable';
import { MenuButton, MenuItem } from 'shared/components/MenuAction';
import { ToolTipInfo } from 'shared/components/ToolTip';
import { useAsync } from 'shared/hooks/useAsync';
import { ResourceIcon } from 'design/ResourceIcon';
import { saveOnDisk } from 'shared/utils/saveOnDisk';

import useStickyClusterId from 'teleport/useStickyClusterId';
import api from 'teleport/services/api';
import { saveOnDisk } from 'shared/utils/saveOnDisk';

import {
getStatusCodeDescription,
Expand Down Expand Up @@ -68,6 +70,17 @@ export function IntegrationList(props: Props<IntegrationLike>) {
return { cursor: 'pointer' };
}

const [downloadAttempt, download] = useAsync(
async (clusterId: string, itemName: string) => {
return api
.fetch(cfg.getMsTeamsAppZipRoute(clusterId, itemName))
.then(response => response.blob())
.then(blob => {
saveOnDisk(blob, 'app.zip', 'application/zip');
});
}
);

const { clusterId } = useStickyClusterId();
return (
<Table
Expand Down Expand Up @@ -116,13 +129,10 @@ export function IntegrationList(props: Props<IntegrationLike>) {
</MenuItem>
)}
{item.kind === 'msteams' && (
<MenuItem onClick={() => {
api.fetch(cfg.getMsTeamsAppZipRoute(clusterId, item.name))
.then(response => response.blob())
.then(blob => {
saveOnDisk(blob, "app.zip", "application/zip")
});
}}>
<MenuItem
disabled={downloadAttempt.status === 'processing'}
onClick={() => download(clusterId, item.name)}
>
Download app.zip
</MenuItem>
)}
Expand Down

0 comments on commit 5d0f966

Please sign in to comment.