Skip to content

Commit

Permalink
Adding support package module and view.
Browse files Browse the repository at this point in the history
  • Loading branch information
aHenryJard committed Apr 5, 2024
1 parent b2aa068 commit 320a7dc
Show file tree
Hide file tree
Showing 31 changed files with 670 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Backend start" type="js.build_tools.npm">
<configuration default="false" name="1 - Backend start dev (first platform)" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/opencti-platform/opencti-graphql/package.json" />
<command value="start" />
<command value="run" />
<scripts>
<script value="start" />
</scripts>
<node-interpreter value="project" />
<package-manager value="yarn" />
<envs />
<envs>
<env name="APP__PORT" value="4000" />
</envs>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Frontend start" type="js.build_tools.npm">
<configuration default="false" name="1 - Frontend start dev (first platform)" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/opencti-platform/opencti-front/package.json" />
<command value="start" />
<node-interpreter value="project" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="1 - worker for dev (first dev platform)" type="PythonConfigurationType" factoryName="Python">
<module name="opencti" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
<env name="OPENCTI_URL" value="http://localhost:3000" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.10 (opencti)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/opencti-worker/src" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opencti-worker/src/worker.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2 - Backend start cluster (second platform)" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/opencti-platform/opencti-graphql/package.json" />
<command value="run" />
<scripts>
<script value="start:cluster" />
</scripts>
<node-interpreter value="project" />
<package-manager value="yarn" />
<envs>
<env name="NODE_ENV" value="dev" />
<env name="APP__PORT" value="4001" />
</envs>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2 - Frontend start cluster (second platform)" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/opencti-platform/opencti-front/package.json" />
<command value="start" />
<node-interpreter value="project" />
<package-manager value="yarn" />
<envs>
<env name="BACK_END_URL" value="http://localhost:4001" />
<env name="FRONT_END_URL" value="3001" />
</envs>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="2 - worker for cluster (second dev platform)" type="PythonConfigurationType" factoryName="Python">
<module name="opencti" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
<env name="OPENCTI_URL" value="http://localhost:3001" />
</envs>
<option name="SDK_HOME" value="" />
<option name="SDK_NAME" value="Python 3.10 (opencti)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/opencti-worker/src" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/opencti-worker/src/worker.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
13 changes: 13 additions & 0 deletions opencti-platform/opencti-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Development tools in this folder

- **Backend start dev**:
- start one instance of the backend platform on http://localhost:4000
- requires a development.json file in `opencti-graphql/config` folder or environment variables (except for port)
- **Backend start cluster**: start a second instance of opencti, using port 4001 on http://localhost:4001
- requires a cluster.json file in `opencti-graphql/config` folder or environment variables (except for port)
- **Frontend start dev**:
- start one instance of the frontend with port `3000` using backend on http://localhost:4000
- **Frontend start cluster**:
- start a second instance of the frontend with port `3001` using backend on http://localhost:4001

For day to day development you can only start the "dev" pair (`Backend start dev` and `Frontend start dev`), if you want to have a cluster locally, add the "cluster" pair.
5 changes: 3 additions & 2 deletions opencti-platform/opencti-front/builder/dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const fsExtra = require("fs-extra");
const basePath = "";
const clients = [];
const buildPath = "./builder/dev/build/";
const frontPort = process.env.FRONT_END_URL ?? 3000;
const debounce = (func, timeout = 500) => {
let timer;
return (...args) => {
Expand All @@ -34,7 +35,7 @@ esbuild.context({
publicPath: "/",
bundle: true,
banner: {
js: ' (() => new EventSource("http://localhost:3000/dev").onmessage = () => location.reload())();',
js: ` (() => new EventSource("http://localhost:${frontPort}/dev").onmessage = () => location.reload())();`,
},
loader: {
".js": "jsx",
Expand Down Expand Up @@ -132,6 +133,6 @@ esbuild.context({
}
return res.send(withOptionValued);
});
app.listen(3000);
app.listen(frontPort);
// endregion
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const CustomizationMenu: FunctionComponent = () => {
path: '/dashboard/settings/customization/decay',
label: 'Decay rules',
},
{
path: '/dashboard/settings/customization/support',
label: 'Support package',
},
];
return <NavToolbarMenu entries={entries} />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Roles = lazy(() => import('./Roles'));
const RootRole = lazy(() => import('./roles/Root'));
const Rules = lazy(() => import('./Rules'));
const RootDecay = lazy(() => import('./decay/Root'));
const RootSupport = lazy(() => import('./support/Root'));
const Sessions = lazy(() => import('./Sessions'));
const Settings = lazy(() => import('./Settings'));
const SettingsOrganizations = lazy(() => import('./SettingsOrganizations'));
Expand All @@ -38,8 +39,8 @@ const Root = () => {
return (
<div data-testid="settings-page">
<Suspense fallback={<Loader />}>
<Switch>
<Security needs={[SETTINGS, VIRTUAL_ORGANIZATION_ADMIN]} placeholder={<Redirect to="/dashboard" />}>
<Security needs={[SETTINGS, VIRTUAL_ORGANIZATION_ADMIN]} placeholder={<Redirect to="/dashboard" />}>
<Switch>
<BoundaryRoute exact path="/dashboard/settings" component={Settings} />
<BoundaryRoute
exact
Expand Down Expand Up @@ -221,6 +222,10 @@ const Root = () => {
path="/dashboard/settings/customization/decay"
component={RootDecay}
/>
<BoundaryRoute
path="/dashboard/settings/customization/support"
component={RootSupport}
/>
<BoundaryRoute
path="/dashboard/settings/customization/notifiers"
component={Notifiers}
Expand Down Expand Up @@ -309,8 +314,8 @@ const Root = () => {
</Security>
)}
/>
</Security>
</Switch>
</Switch>
</Security>
</Suspense>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// TODO Remove this when V6
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import SupportPackages from '@components/settings/support/SupportPackages';

const RootSupportPackage = () => {
return (
<Switch>
<Route path="" component={SupportPackages} />
</Switch>
);
};

export default RootSupportPackage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import CustomizationMenu from '@components/settings/CustomizationMenu';
import makeStyles from '@mui/styles/makeStyles';
import Button from '@mui/material/Button';
import { graphql, useMutation } from 'react-relay';
import { useFormatter } from '../../../../components/i18n';
import Breadcrumbs from '../../../../components/Breadcrumbs';
import type { Theme } from '../../../../components/Theme';
import { handleError, MESSAGING$ } from '../../../../relay/environment';

const useStyles = makeStyles<Theme>(() => ({}));

export const supportPackageAddMutation = graphql`
mutation SupportPackagesMutation(
$input: SupportPackageAddInput!
) {
supportPackageAdd(input: $input) {
id
}
}
`;

const SupportPackages = () => {
const { t_i18n, nsdt } = useFormatter();
const classes = useStyles();

const generateSupportPackage = () => {
alert('Go !');
const [commitSupportPackageAdd] = useMutation(supportPackageAddMutation);
const supportPackageName = `support-package-${nsdt(new Date())}`;
commitSupportPackageAdd({
variables: {
input: {
name: supportPackageName,
},
},
onCompleted: () => {
MESSAGING$.notifySuccess(
`Support package request send for ${supportPackageName}.`,
);
},
onError: (error) => {
handleError(error);
},
});
};

return (
<div className={classes.container}>
<CustomizationMenu />
<Breadcrumbs variant="list" elements={[{ label: t_i18n('Settings') }, { label: t_i18n('Customization') }, { label: t_i18n('Support packages'), current: true }]} />
<Button
aria-label="Generate support package"
className={classes.createButton}
onClick={generateSupportPackage}
size="large"
color="primary"
>Generate support package
</Button>
</div>
);
};

export default SupportPackages;
16 changes: 16 additions & 0 deletions opencti-platform/opencti-front/src/schema/relay.schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7406,6 +7406,8 @@ type Query {
publicBookmarks(uriKey: String!, widgetId: String!): StixDomainObjectConnection
publicStixCoreObjects(uriKey: String!, widgetId: String!, startDate: DateTime, endDate: DateTime): StixCoreObjectConnection
publicStixRelationships(uriKey: String!, widgetId: String!, startDate: DateTime, endDate: DateTime): StixRelationshipConnection
supportPackage(id: String!): SupportPackage
supportPackages(first: Int, after: ID, orderBy: DecayRuleOrdering, orderMode: OrderingMode): SupportPackage
}

type Subscription {
Expand Down Expand Up @@ -8173,6 +8175,7 @@ type Mutation {
aiChangeTone(id: ID!, content: String!, format: Format, tone: Tone): String
aiSummarize(id: ID!, content: String!, format: Format): String
aiExplain(id: ID!, content: String!): String
supportPackageAdd(input: SupportPackageAddInput!): SupportPackage
}

type Channel implements BasicObject & StixObject & StixCoreObject & StixDomainObject {
Expand Down Expand Up @@ -11266,4 +11269,17 @@ enum IndicatorFormat {
type AIBus {
bus_id: String!
content: String!
}

type SupportPackage implements InternalObject & BasicObject {
id: ID!
name: String!
standard_id: String!
entity_type: String!
parent_types: [String]!
created_at: DateTime!
}

input SupportPackageAddInput {
name: name_String_NotNull_minLength_2!
}
2 changes: 2 additions & 0 deletions opencti-platform/opencti-graphql/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules
public
config/ssl
config/demo.json
config/cluster.json
config/development.json
config/development.json.bak
config/production.json
Expand All @@ -20,6 +21,7 @@ config/prod-*.json
coverage
test-results
logs
.support
yarn-error.log
graphql.schema.json
__pycache__
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-graphql/graphql-codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ generates:
CsvMapper: ../modules/internal/csvMapper/csvMapper-types#BasicStoreEntityCsvMapper
Playbook: ../modules/playbook/playbook-types#BasicStoreEntityPlaybook
PublicDashboard: ../modules/publicDashboard/publicDashboard-types#BasicStoreEntityPublicDashboard
SupportPackage: ../modules/support/support-types#BasicStoreEntitySupportPackage
./graphql.schema.json:
plugins:
- "introspection"
5 changes: 3 additions & 2 deletions opencti-platform/opencti-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"lint": "cross-env DEBUG=eslint:cli-engine TIMING=1 eslint --max-warnings 0 --cache -c .eslintrc.js src",
"build": "yarn install:python && yarn build:prod",
"start": "NODE_ENV=dev yarn build:dev && node build/back.js",
"start-light": "NODE_ENV=dev node build/back.js",
"start-cluster": "NODE_ENV=cluster node build/back.js",
"start:dev": "NODE_ENV=dev yarn build:dev && node build/back.js",
"start:light": "NODE_ENV=dev node build/back.js",
"start:cluster": "NODE_ENV=cluster node build/back.js",
"serv": "node build/back.js",
"insert:dev": "node build/script-insert-dataset.js",
"test:dev:init": "INIT_TEST_PLATFORM=true vitest run --config vitest.config.dev.ts --testNamePattern=\"Should import creation succeed\" tests/02-integration/00-inject/loader-test.ts",
Expand Down
Loading

0 comments on commit 320a7dc

Please sign in to comment.