Skip to content

Commit

Permalink
feat: display service instance information (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt authored Sep 11, 2024
1 parent 66dadd9 commit 3d8f8c4
Show file tree
Hide file tree
Showing 34 changed files with 1,922 additions and 840 deletions.
1,263 changes: 689 additions & 574 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"typeorm": "typeorm-ts-node-commonjs"
},
"dependencies": {
"@aws-sdk/client-kinesis": "^3.637.0",
"@aws-sdk/client-kinesis": "^3.650.0",
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.4.1",
"@nestjs/config": "^3.2.3",
Expand All @@ -47,7 +47,7 @@
"libsodium-wrappers": "^0.7.15",
"lodash.merge": "^4.6.2",
"mongodb": "^5.9.2",
"openid-client": "^5.6.5",
"openid-client": "^5.7.0",
"passport": "^0.7.0",
"passport-http": "^0.3.0",
"passport-jwt": "^4.0.1",
Expand All @@ -62,7 +62,7 @@
"uuid": "^10.0.0"
},
"devDependencies": {
"@eslint/js": "^9.9.1",
"@eslint/js": "^9.10.0",
"@golevelup/ts-jest": "^0.5.5",
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.4",
Expand All @@ -76,15 +76,15 @@
"@types/jest": "^29.5.12",
"@types/libsodium-wrappers": "^0.7.14",
"@types/lodash.merge": "^4.6.9",
"@types/node": "^22.5.2",
"@types/node": "^22.5.4",
"@types/passport": "^1.0.16",
"@types/passport-http": "^0.3.11",
"@types/passport-jwt": "^4.0.1",
"@types/supertest": "^6.0.2",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"eslint": "^9.9.1",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
Expand All @@ -95,8 +95,8 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0"
"typescript": "^5.6.2",
"typescript-eslint": "^8.5.0"
},
"jest": {
"moduleFileExtensions": [
Expand Down
19 changes: 19 additions & 0 deletions scripts/db/mongo-setup-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ db.server.insertMany([
hostName: 'lollipop.dmz',
vertex: ObjectId('66034698eb54820a9728bf99'),
architecture: 'x86_64',
osFamily: 'rhel',
osFull: 'Red Hat Enterprise Linux 9.3 (Plow)',
osKernel: '5.14.0-362.24.1.el9_3.x86_64',
osName: 'Red Hat Enterprise Linux',
osType: 'linux',
osVersion: '9.3',
tags: ['edge', 'webserver'],
},
{
Expand All @@ -338,6 +344,12 @@ db.server.insertMany([
hostName: 'bubblegum.dmz',
vertex: ObjectId('660c3aaf12bf4c90fecd9666'),
architecture: 'x86_64',
osFamily: 'rhel',
osFull: 'Red Hat Enterprise Linux 9.3 (Plow)',
osKernel: '5.14.0-362.24.1.el9_3.x86_64',
osName: 'Red Hat Enterprise Linux',
osType: 'linux',
osVersion: '9.3',
tags: ['edge', 'webserver'],
},
{
Expand All @@ -346,6 +358,13 @@ db.server.insertMany([
acquired: ISODate('2024-03-04T00:00:00.000Z'),
hostName: 'peak.internal',
vertex: ObjectId('66034715eb54820a9728bf9a'),
architecture: 'x86_64',
osFamily: 'rhel',
osFull: 'Red Hat Enterprise Linux 9.3 (Plow)',
osKernel: '5.14.0-362.24.1.el9_3.x86_64',
osName: 'Red Hat Enterprise Linux',
osType: 'linux',
osVersion: '9.3',
tags: ['database'],
},
]);
Expand Down
2 changes: 1 addition & 1 deletion src/collection/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class CollectionService {
});
}
for (const instance of service.serviceInstance) {
if (instance.action.source) {
if (instance?.action?.source) {
instance.action.source.intention.auditUrl =
this.actionUtil.auditUrlForIntention(
instance.action.source.intention,
Expand Down
32 changes: 28 additions & 4 deletions src/persistence/mongo/graph-mongo.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ export class GraphMongoRepository implements GraphRepository {
public async getServiceDetails(
id: string,
): Promise<ServiceDetailsResponseDto> {
const serverRepository = getRepositoryFromCollectionName(
const serviceRepository = getRepositoryFromCollectionName(
this.dataSource,
'service',
);
return serverRepository
return serviceRepository
.aggregate([
{ $match: { _id: new ObjectId(id) } },
this.collectionLookup(
Expand All @@ -290,6 +290,13 @@ export class GraphMongoRepository implements GraphRepository {
true,
true,
),
this.collectionLookup(
'server',
{ name: 'installation' },
'forward',
true,
false,
),
{
$lookup: {
from: 'intention',
Expand All @@ -299,7 +306,9 @@ export class GraphMongoRepository implements GraphRepository {
},
},
{ $unwind: '$environment' },
{ $unwind: '$intention' },
{
$unwind: { path: '$intention', preserveNullAndEmptyArrays: true },
},
],
),
])
Expand All @@ -316,6 +325,15 @@ export class GraphMongoRepository implements GraphRepository {
delete instance.environment._id;
}

if (instance.server) {
for (const server of instance.server) {
server.edge.id = server.edge._id;
delete server.edge._id;
server.server.id = server.server._id;
delete server.server._id;
}
}

if (instance.intention) {
const intention = instance.intention;
intention.id = intention._id;
Expand Down Expand Up @@ -426,10 +444,16 @@ export class GraphMongoRepository implements GraphRepository {
as: collection,
pipeline: [
{ $match: edgeMatch },
{
$replaceWith: {
edge: '$$ROOT',
},
},
{
$lookup: {
from: collection,
localField: direction === 'forward' ? 'target' : 'source',
localField:
direction === 'forward' ? 'edge.target' : 'edge.source',
foreignField: 'vertex',
as: collection,
},
Expand Down
Loading

0 comments on commit 3d8f8c4

Please sign in to comment.