Skip to content

Commit

Permalink
Add Dlp Jobs page and integration in fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tomijange committed Jan 18, 2024
1 parent 6bfe738 commit dca101e
Show file tree
Hide file tree
Showing 38 changed files with 483 additions and 152 deletions.
26 changes: 26 additions & 0 deletions src/actions/dlp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AnyAction } from 'redux';

import { Dispatch } from "react";
import { getDlpFindingsForField, getJobs, getResult } from 'gateways/dlp';

export const fetchDlpJobs = (dispatch: Dispatch<AnyAction>) => {
dispatch({ type: "DLP_JOB_REQUEST" });
getJobs()
.then(jobs => dispatch({ type: "DLP_JOB_SUCCESS", payload: jobs }))
.catch(error => dispatch({ type: "DLP_JOB_FAILURE", payload: error }))
}


export const fetchDlpResults = (dispatch: Dispatch<AnyAction>, resultId: string) => {
dispatch({ type: "DLP_RESULT_REQUEST" });
getResult(resultId)
.then(result => dispatch({ type: "DLP_RESULT_SUCCESS", payload: result }))
.catch(error => dispatch({ type: "DLP_RESULT_FAILURE", payload: error }))
}

export const fetchDlpFindingsByField = (dispatch: Dispatch<AnyAction>, fieldId: string) => {
dispatch({ type: "DLP_FINDINGS_BY_FIELD_REQUEST" });
getDlpFindingsForField(fieldId)
.then(findings => dispatch({ type: "DLP_FINDINGS_BY_FIELD_SUCCESS", payload: { id: fieldId, findings } }))
.catch(error => dispatch({ type: "DLP_FINDINGS_BY_FIELD_FAILURE", payload: error }))
}
2 changes: 1 addition & 1 deletion src/actions/fields.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {deleteField, getFields, postField, putField} from "gateways/fields";
import { Dispatch } from "react";
import { AnyAction } from "redux";
import { Field } from "types";
import { Field } from "types/types";
import {
CREATE_FIELD_FAILURE,
CREATE_FIELD_REQUEST,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "gateways/mappings";
import {Dispatch} from "react";
import {AnyAction} from "redux";
import {AnyMapping} from "types";
import {AnyMapping} from "types/types";
import {
CREATE_MAPPING_FAILURE,
CREATE_MAPPING_REQUEST,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Footer/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export default function Footer(props) {
>
<List display="flex">
<ListItem me={{ base: "20px", md: "44px", }}>
<Link color="gray.400" href="https://github.com/TUB-CNPE-TB/">TUB-CNPE-TB</Link>
<Link color="gray.400" href="https://github.com/PrivacyEngineering/">TUB PrivacyEngineering</Link>
</ListItem>
<ListItem me={{ base: "20px", md: "44px", }}>
<Link color="gray.400" href="https://github.com/TUB-CNPE-TB/transparency-log/">Github</Link>
<Link color="gray.400" href="https://github.com/PrivacyEngineering/hawk-monitor.git">Github</Link>
</ListItem>
</List>
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebar/CustomNavLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, Flex, Icon, Text, useColorModeValue } from "@chakra-ui/react";
import { IconBox } from "components/Icons/IconBox";
import { useEffect, useState } from "react";
import { NavLink, useLocation } from "react-router-dom";
import { SidebarVariant } from "types";
import { SidebarVariant } from "types/types";

interface Props {
path: string;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Sidebar/SidebarTS.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Link, Stack, Text, useColorModeValue } from "@chakra-ui/react";
import { DocumentIcon } from "components/Icons/Icons";
import { useEffect, useState } from "react";
import { SidebarVariant } from "types";
import { SidebarVariant } from "types/types";
import { Separator } from "../Separator/Separator";
import { CustomNavLink } from "./CustomNavLink";

Expand Down Expand Up @@ -45,6 +45,7 @@ export const SidebarTS = (props: Props) => {
<CustomNavLink path='legalBases' label='Legal Bases' icon={<DocumentIcon />} sidebarVariant={sidebarVariant} />
<CustomNavLink path='fields' label='Fields' icon={<DocumentIcon />} sidebarVariant={sidebarVariant} />
<CustomNavLink path='mappings' label='Mappings' icon={<DocumentIcon />} sidebarVariant={sidebarVariant} />
<CustomNavLink path='dlp/jobs' label='DLP Jobs' icon={<DocumentIcon />} sidebarVariant={sidebarVariant} />
</Stack>
</Box>
</Box>
Expand Down
8 changes: 8 additions & 0 deletions src/gateways/dlp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { URL_BASE } from "index";
import { DlpFinding, DlpJob, DlpJobResult } from "types/dlp";

export const getJobs = (): Promise<DlpJob[]> => fetch(`${URL_BASE}/api/dlp`).then(response => response.json());

export const getResult = (resultId: string): Promise<DlpJobResult> => fetch(`${URL_BASE}/api/dlp/results/${resultId}`).then(response => response.json());

export const getDlpFindingsForField= (fieldId: string): Promise<DlpFinding[]> => fetch(`${URL_BASE}/api/fields/${fieldId}/dlp`).then(response => response.json());
2 changes: 1 addition & 1 deletion src/gateways/fields.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {HEADER_JSON, URL_BASE} from "index";
import { Field } from "types";
import { Field } from "types/types";

export const getFields = (): Promise<Field[]> => fetch(`${URL_BASE}/api/fields`).then(response => response.json());

Expand Down
2 changes: 1 addition & 1 deletion src/gateways/mappings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {HEADER_JSON, URL_BASE} from "index";
import {AnyMapping, GroupedUsageField, Mapping} from "types";
import {AnyMapping, GroupedUsageField, Mapping} from "types/types";

export const getMappings = (): Promise<Mapping[]> => fetch(`${URL_BASE}/api/mappings`).then(response => response.json());

Expand Down
7 changes: 6 additions & 1 deletion src/layouts/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AdminNavbar } from "../components/Navbars/AdminNavbar";
import { MainPanel, PanelContainer, PanelContent } from "components/StyledComponent";
import Configurator from "components/Configurator/Configurator";
import { Navigate, Route, Routes } from "react-router-dom";
import { SidebarVariant } from "types";
import { SidebarVariant } from "types/types";
import { FieldPage } from "views/FieldPage";
import { FieldsPage } from "views/FieldsPage";
import { MappingPage } from "views/MappingPage";
Expand All @@ -17,6 +17,8 @@ import { LegalBasesPage } from "views/LegalBasesPage";
import { useThunkDispatch } from "index";
import { fetchFields } from "actions/fields";
import { fetchMappings } from "actions/mappings";
import { DlpJobs } from "views/dlp/DlpJobs";
import { DlpFindings } from "views/dlp/DlpFindings";

export const App = () => {
const dispatch = useThunkDispatch();
Expand All @@ -42,6 +44,9 @@ export const App = () => {
<Route path="/mappings/update/:id" element={<MappingPage />} />
<Route path="/mappings/new" element={<MappingPage />} />
<Route path="/mappings" element={<MappingsPage />} />
<Route path="/dlp/jobs" element={<DlpJobs />} />
<Route path="/dlp/findings/byField/:fieldId" element={<DlpFindings/>} />
<Route path="/dlp/findings/:id" element={<DlpFindings/>} />
<Route path="*" element={<Navigate to="/mappings" />} />
</Routes>
</PanelContainer>
Expand Down
31 changes: 31 additions & 0 deletions src/reducers/dlp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { FetchDlpFindingsByFieldActionTypes, FetchDlpJobResultActionTypes, FetchDlpJobsActionTypes } from "types/actions/Dlp";
import { DlpFinding, DlpJob, DlpJobResult } from "types/dlp";


export const dlpJobs = (state: DlpJob[] = [], action: FetchDlpJobsActionTypes) => {
switch (action.type) {
case "DLP_JOB_SUCCESS":
return action.payload;
default:
return state;
}
}

export const dlpResults = (state: {[k: string]: DlpJobResult} = {}, action: FetchDlpJobResultActionTypes) => {
switch (action.type) {
case "DLP_RESULT_SUCCESS":
return {...state, [action.payload.id]: action.payload};
default:
return state;
}
}


export const dlpFindingsByField = (state: {[k: string]: DlpFinding[]} = {}, action: FetchDlpFindingsByFieldActionTypes) => {
switch (action.type) {
case "DLP_FINDINGS_BY_FIELD_SUCCESS":
return {...state, [action.payload.id]: action.payload.findings};
default:
return state;
}
}
2 changes: 1 addition & 1 deletion src/reducers/fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, NormalizedState } from "../types";
import { Field, NormalizedState } from "../types/types";
import {
CreateFieldActionTypes,
CreateFieldSuccessAction,
Expand Down
6 changes: 5 additions & 1 deletion src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
mappingsBeingDeleted,
mappingsBeingUpdated, requestedFieldSuggestions, unmappedEndpoints
} from './mappings';
import { dlpJobs, dlpResults, dlpFindingsByField } from './dlp';

export const app = combineReducers({
fields,
Expand All @@ -23,7 +24,10 @@ export const app = combineReducers({
requestedFieldSuggestions,
mappingsBeingCreated,
mappingsBeingUpdated,
mappingsBeingDeleted
mappingsBeingDeleted,
dlpJobs,
dlpResults,
dlpFindingsByField
});

export type RootState = ReturnType<typeof app>
47 changes: 2 additions & 45 deletions src/reducers/infoTypes.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,7 @@
// from https://github.com/PrivacyEngineering/hawk-dlp/blob/master/hawk-dlp-common/src/main/kotlin/io/hawk/dlp/common/InfoType.kt
import { InfoType, InfoTypeType } from "types/dlp";

/**
* Represents a type of data identified, e.g. E-Mail address or a last name.
* In Google Cloud DLP terms, this is equivalent to an Info Type.
* In AWS Macie terms, this would be a (managed) data identifier.
*/
enum InfoType {
// G = Google Cloud DLP
// A = AWS Macie
ADVERTISING_ID, // G
AGE, // G
AUTH_TOKEN, // G
CREDENTIALS, // G[AWS_CREDENTIALS, GCP_CREDENTIALS, AZURE_CREDENTIALS]; A[AWS_CREDENTIALS]
CREDIT_CARD_NUMBER, // G, A
CREDIT_CARD_EXPIRATION, // A
CREDIT_CARD_SECURITY_CODE, // A
DATE, // G
DATE_OF_BIRTH, // G, A
DOMAIN_NAME, // G
EMAIL_ADDRESS, // G
ENCRYPTION_KEY, // G, A[OPENSSH_PRIVATE_KEY, PGP_PRIVATE_KEY, PKCS, PUTTY_PRIVATE_KEY]
ETHNIC_GROUP, // G
GENDER, // G
GENERIC_ID, // G
IBAN_CODE, // G
IMEI_NUMBER, // G
IP_ADDRESS, // G
JSON_WEB_TOKEN, // G, A
LOCATION, // G[LOCATION, LOCATION_COORDINATES], A[LATITUDE_LONGITUDE]
MAC_ADDRESS, // G
MEDICAL_TERM, // G
NAME, // G[FEMALE_NAME, FIRST_NAME, MALE_NAME, LAST_NAME]
ORGANIZATION_NAME, // G
PASSPORT_NUMBER, // G, A[ends with _PASSPORT_NUMBER]
PASSWORD, // G
PHONE_NUMBER, // G, A[ends with _PHONE_NUMBER]
ADDRESS, // G[STREET_ADDRESS], A
SWIFT_CODE, // G
TIME, // G
URL, // G
VEHICLE_IDENTIFICATION_NUMBER, // G
WEAK_PASSWORD_HASH, // G
UNKNOWN // Fallback InfoType, if InfoType can't be mapped
}
const infoTypesInitialState = {
infoTypes: Object.values(InfoType).filter(value => typeof value === 'string') as string[]
infoTypes: Object.values(InfoType).filter(value => typeof value === 'string') as InfoTypeType[]
}

export const infoTypes = (state: typeof infoTypesInitialState = infoTypesInitialState) => {
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/legalBases.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LegalBaseExtended } from "types";
import { LegalBaseExtended } from "types/types";

const legalBasesInitialState = [
{ reference: "GDPR-6-1-a", regulation: "GDPR", article: "6", paragraph: "1(a)", description: "Consent" },
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/mappings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GroupedUsageField, Mapping, NormalizedState} from "../types";
import {GroupedUsageField, Mapping, NormalizedState} from "../types/types";
import {
CreateMappingActionTypes,
CreateMappingSuccessAction,
Expand Down
25 changes: 0 additions & 25 deletions src/routes.js

This file was deleted.

54 changes: 54 additions & 0 deletions src/types/actions/Dlp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { DlpFinding, DlpJob, DlpJobResult } from "types/dlp";

interface FetchDlpJobsRequestAction {
type: "DLP_JOB_REQUEST";
}

interface FetchDlpJobsSuccessAction {
type: "DLP_JOB_SUCCESS";
payload: DlpJob[];
}

interface FetchDlpJobsFailureAction {
type: "DLP_JOB_FAILURE";
payload: string;
}

export type FetchDlpJobsActionTypes = FetchDlpJobsRequestAction | FetchDlpJobsSuccessAction | FetchDlpJobsFailureAction;


interface FetchDlpJobResultRequestAction {
type: "DLP_RESULT_REQUEST";
}

interface FetchDlpJobResultSuccessAction {
type: "DLP_RESULT_SUCCESS";
payload: DlpJobResult;
}

interface FetchDlpJobResultFailureAction {
type: "DLP_RESULT_FAILURE";
payload: string;
}

export type FetchDlpJobResultActionTypes = FetchDlpJobResultRequestAction | FetchDlpJobResultSuccessAction | FetchDlpJobResultFailureAction;


interface FetchDlpFindingsByFieldRequestAction {
type: "DLP_FINDINGS_BY_FIELD_REQUEST";
}

interface FetchDlpFindingsByFieldSuccessAction {
type: "DLP_FINDINGS_BY_FIELD_SUCCESS";
payload: {
id: string;
findings: DlpFinding[];
};
}

interface FetchDlpFindingsByFieldFailureAction {
type: "DLP_FINDINGS_BY_FIELD_FAILURE";
payload: string;
}

export type FetchDlpFindingsByFieldActionTypes = FetchDlpFindingsByFieldRequestAction | FetchDlpFindingsByFieldSuccessAction | FetchDlpFindingsByFieldFailureAction;
2 changes: 1 addition & 1 deletion src/types/actions/Fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field } from '../../types';
import { Field } from '../types';

import * as types from './Types';

Expand Down
2 changes: 1 addition & 1 deletion src/types/actions/Mappings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AnyMapping, GroupedUsageField, Mapping} from '../../types';
import {AnyMapping, GroupedUsageField, Mapping} from '../types';

import * as types from './Types';

Expand Down
Loading

0 comments on commit dca101e

Please sign in to comment.