|
| 1 | +import React from 'react'; |
| 2 | +import { Button, Container, Header } from 'semantic-ui-react'; |
| 3 | + |
| 4 | +import { useEnvironment } from '../../hooks'; |
| 5 | + |
| 6 | +export const MyOpenCRE = () => { |
| 7 | + const { apiUrl } = useEnvironment(); |
| 8 | + // console.log('API URL:', apiUrl); |
| 9 | + |
| 10 | + const downloadCreCsv = async () => { |
| 11 | + try { |
| 12 | + const baseUrl = apiUrl || window.location.origin; |
| 13 | + |
| 14 | + const backendUrl = baseUrl.includes('localhost') ? 'http://127.0.0.1:5000' : baseUrl; |
| 15 | + |
| 16 | + const response = await fetch(`${backendUrl}/cre_csv`, { |
| 17 | + method: 'GET', |
| 18 | + headers: { |
| 19 | + Accept: 'text/csv', |
| 20 | + }, |
| 21 | + }); |
| 22 | + |
| 23 | + if (!response.ok) { |
| 24 | + throw new Error(`HTTP error ${response.status}`); |
| 25 | + } |
| 26 | + |
| 27 | + const blob = await response.blob(); |
| 28 | + const url = window.URL.createObjectURL(blob); |
| 29 | + |
| 30 | + const link = document.createElement('a'); |
| 31 | + link.href = url; |
| 32 | + link.download = 'opencre-cre-mapping.csv'; |
| 33 | + document.body.appendChild(link); |
| 34 | + link.click(); |
| 35 | + |
| 36 | + document.body.removeChild(link); |
| 37 | + window.URL.revokeObjectURL(url); |
| 38 | + } catch (err) { |
| 39 | + console.error('CSV download failed:', err); |
| 40 | + alert('Failed to download CRE CSV'); |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + return ( |
| 45 | + <Container style={{ marginTop: '3rem' }}> |
| 46 | + <Header as="h1">MyOpenCRE</Header> |
| 47 | + |
| 48 | + <p> |
| 49 | + MyOpenCRE allows you to map your own security standard (e.g. SOC2) to OpenCRE Common Requirements |
| 50 | + using a CSV spreadsheet. |
| 51 | + </p> |
| 52 | + |
| 53 | + <p> |
| 54 | + Start by downloading the mapping template below, fill it with your standard’s controls, and map them |
| 55 | + to CRE IDs. |
| 56 | + </p> |
| 57 | + |
| 58 | + <Button primary onClick={downloadCreCsv}> |
| 59 | + Download CRE Catalogue (CSV) |
| 60 | + </Button> |
| 61 | + </Container> |
| 62 | + ); |
| 63 | +}; |
0 commit comments