Skip to content

Commit

Permalink
Merge pull request #28 from mitre-attack/refactor-hydration-process
Browse files Browse the repository at this point in the history
feat: TAXII Server Hydration System Refactor
  • Loading branch information
seansica authored Nov 17, 2024
2 parents 5ed8f93 + 4a53be8 commit 489e6ba
Show file tree
Hide file tree
Showing 41 changed files with 704 additions and 436 deletions.
9 changes: 6 additions & 3 deletions bruno/Get API Root Information.bru
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ tests {
const data = res.getBody();
expect(data).to.have.property('title').that.is.a('string').and.is.not.empty;
expect(data).to.have.property('description').that.is.a('string').and.is.not.empty;
expect(data).to.have.property('version').that.is.a('string').and.startsWith('application/taxii+json');
expect(data).to.have.property('maxContentLength');
const maxContentLength = data.maxContentLength;
expect(data).to.have.property('versions').that.is.an('array');
data.versions.forEach(version => {
expect(version).startsWith('application/taxii+json');
});
expect(data).to.have.property('max_content_length');
const maxContentLength = data['max_content_length'];

if (typeof maxContentLength === 'string') {
expect(parseInt(maxContentLength)).to.be.a('number').and.not.NaN;
Expand Down
4 changes: 3 additions & 1 deletion bruno/Get Object Versions.bru
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ tests {

test("Verify response body structure", function() {
const data = res.getBody();
expect(data).to.have.property('more').that.is.a('boolean');
if (data.hasOwnProperty('more')) {
expect(data.more).to.be.a('boolean');
}

// The list of object versions returned by the request.
if (data.hasOwnProperty('versions')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class ContentNegotiationMiddleware implements NestMiddleware {
// Get a hook into the request context so we can do logging
const ctx: RequestContext = RequestContextModel.get();

// Do not enforce TAXII headers on health check endpoint
if (req.path == "/health/ping") {
return next();
}

// Extract 'Accept' header
const mediaType: string = req.headers["accept"];

Expand Down
2 changes: 1 addition & 1 deletion src/config/interfaces/taxii-config.service.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface TaxiiConfigServiceInterface {
createAppConnectOptions();
createCollectorConnectOptions();
createHydrateConnectOptions();
createDatabaseConnectOptions();
createStixConnectOptions();
get APP_ADDRESS();
Expand Down
5 changes: 2 additions & 3 deletions src/config/taxii-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { StixConnectOptions } from "../stix/interfaces";
import { isDefined } from "class-validator";
import { AppConnectOptions } from "../interfaces";
import { DatabaseConnectOptions } from "../interfaces/database-connect-options.interface";
import { CollectorConnectOptions } from "../hydrate/collector/interfaces/collector-connect.options";

import { HydrateConnectOptions } from "src/hydrate/interfaces/hydrate-connect.options";
/**
* This provider is responsible for loading all user-definable configuration parameters (imported from
* environment variables) and making them available to all necessary app services
Expand All @@ -23,7 +22,7 @@ export class TaxiiConfigService implements TaxiiConfigServiceInterface {
};
}

createCollectorConnectOptions(): CollectorConnectOptions {
createHydrateConnectOptions(): HydrateConnectOptions {
return {
hydrateOnBoot: this.HYDRATE_ON_BOOT,
...this.createAppConnectOptions(),
Expand Down
8 changes: 1 addition & 7 deletions src/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ export async function bootstrap() {
tempConfigApp.get(TaxiiConfigService);

const app: NestApplication = await NestFactory.create(
HydrateModule.register(tempConfigService.createCollectorConnectOptions())
HydrateModule.register(tempConfigService.createHydrateConnectOptions())
);

// ** Initialize the Nest application ** //
await app.init();

// Start the 'get-attack-objects' cron job to pre-populate the TAXII DB (MongoDB) with STIX
if (tempConfigService.HYDRATE_ON_BOOT) {
const provider = app.get(HydrateService);
await provider.hydrate();
}

console.log(`Bootstrap process completed...cleaning up...`);
await tempConfigApp.close();
}
Expand Down
18 changes: 0 additions & 18 deletions src/hydrate/collector/collector.module.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/hydrate/collector/constants.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/hydrate/collector/interfaces/collector-connect.options.ts

This file was deleted.

74 changes: 0 additions & 74 deletions src/hydrate/collector/providers/collection-collector.service.ts

This file was deleted.

125 changes: 0 additions & 125 deletions src/hydrate/collector/providers/object-collector.service.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/hydrate/collector/schema/attack-object.schema.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/hydrate/collector/schema/taxii-collection.schema.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/hydrate/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const GET_TAXII_RESOURCES_JOB_TOKEN = "GET_TAXII_RESOURCES";
export const HYDRATE_OPTIONS_TOKEN = "HYDRATE_OPTIONS";
Loading

0 comments on commit 489e6ba

Please sign in to comment.