Skip to content

Commit

Permalink
feat: Set static automatic Findings resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
einnhverr committed Dec 16, 2024
1 parent 3816c3b commit fd75f04
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export class Database1732714208822 implements MigrationInterface {
`ALTER TABLE "user_profile" ALTER COLUMN "id" SET DATA TYPE uuid USING "id"::uuid`,
)
await queryRunner.query(
`ALTER TABLE "findings" ALTER COLUMN "resolver" SET DATA TYPE uuid USING "resolver"::uuid`,
`ALTER TABLE "findings" ALTER COLUMN "resolver" SET DATA TYPE uuid
USING CASE
WHEN "resolver" IN ('SYSTEM_ACTOR', 'Yaku', 'Aqua') THEN '00000000-0000-0000-0000-000000000000'::uuid
ELSE "resolver"::uuid
END`,
)
await queryRunner.query(
`ALTER TABLE "comment" ALTER COLUMN "createdBy" SET DATA TYPE uuid USING "createdBy"::uuid`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import { Metric } from '../metrics/entity/metric.entity'
import { MetricService } from '../metrics/metric.service'
import { EntityList } from '@B-S-F/api-commons-lib'
import { RunStatus } from '../run/run.entity'
import { SYSTEM_USER, UsersService } from '../users/users.service'
import { UsersService } from '../users/users.service'
import { UserInNamespaceDto } from '../users/users.utils'
import { SYSTEM_REQUEST_USER, SYSTEM_REQUEST_USER_ID } from '../module.utils'

describe('FindingService', () => {
let findingService: FindingService
Expand Down Expand Up @@ -322,17 +323,17 @@ describe('FindingService', () => {
describe('updateFinding', () => {
it.each([
[
SYSTEM_USER.displayName,
SYSTEM_USER.username,
SYSTEM_USER.id,
SYSTEM_USER.email,
SYSTEM_REQUEST_USER.displayName,
SYSTEM_REQUEST_USER.username,
SYSTEM_REQUEST_USER.id,
SYSTEM_REQUEST_USER.email,
false,
],
[
SYSTEM_USER.displayName,
SYSTEM_USER.username,
SYSTEM_USER.id,
SYSTEM_USER.email,
SYSTEM_REQUEST_USER.displayName,
SYSTEM_REQUEST_USER.username,
SYSTEM_REQUEST_USER.id,
SYSTEM_REQUEST_USER.email,
false,
],
[
Expand Down Expand Up @@ -431,17 +432,17 @@ describe('FindingService', () => {

it.each([
[
SYSTEM_USER.displayName,
SYSTEM_USER.username,
SYSTEM_USER.id,
SYSTEM_USER.email,
SYSTEM_REQUEST_USER.displayName,
SYSTEM_REQUEST_USER.username,
SYSTEM_REQUEST_USER.id,
SYSTEM_REQUEST_USER.email,
false,
],
[
SYSTEM_USER.displayName,
SYSTEM_USER.username,
SYSTEM_USER.id,
SYSTEM_USER.email,
SYSTEM_REQUEST_USER.displayName,
SYSTEM_REQUEST_USER.username,
SYSTEM_REQUEST_USER.id,
SYSTEM_REQUEST_USER.email,
false,
],
[
Expand Down Expand Up @@ -718,7 +719,7 @@ describe('FindingService', () => {
occurrenceCount: 3,
status: 'resolved' as StatusType,
resolvedComment: 'Performance issue addressed and optimized.',
resolver: SYSTEM_USER.id,
resolver: SYSTEM_REQUEST_USER_ID,
createdAt: new Date('2023-08-22T00:00:00Z'),
updatedAt: new Date('2023-08-22T00:00:00Z'),
}
Expand Down Expand Up @@ -966,7 +967,7 @@ describe('FindingService', () => {
status: 'resolved' as StatusType,
resolvedComment: `This finding was automatically resolved by run ${lastRunData.id}`,
resolvedDate: new Date('2020-01-01').toISOString(),
resolver: SYSTEM_USER.id,
resolver: SYSTEM_REQUEST_USER_ID,
runId: lastRunData.id,
runCompletionTime: '2023-06-12T12:44:44.000Z',
runOverallResult: 'RED' as RunOverallStatusType,
Expand Down Expand Up @@ -1109,7 +1110,7 @@ describe('FindingService', () => {
status: 'resolved' as StatusType,
resolvedComment: `This finding was automatically resolved by run ${lastRunData.id}`,
resolvedDate: new Date('2020-01-01').toISOString(),
resolver: SYSTEM_USER.id,
resolver: SYSTEM_REQUEST_USER_ID,
runId: lastRunData.id,
runCompletionTime: '2023-06-12T12:44:44.000Z',
runOverallResult: 'ERROR' as RunOverallStatusType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import { CreateMetricDTO } from '../metrics/dto/createMetric.dto'
import { UpdateFindingDTO as UpdateFindingMetricDTO } from '../metrics/dto/updateFinding.dto'
import { ServiceType } from '../metrics/utils/enums/serviceType.enum'
import { MetricService } from '../metrics/metric.service'
import { DELETED_USER, SYSTEM_USER, UsersService } from '../users/users.service'
import { DELETED_USER, UsersService } from '../users/users.service'
import { UserInNamespaceDto } from '../users/users.utils'
import { SYSTEM_REQUEST_USER, SYSTEM_REQUEST_USER_ID } from '../module.utils'

const allowedFilteringParameters = [
'configId',
Expand Down Expand Up @@ -177,11 +178,7 @@ export class FindingService {
runStatus: incomingFinding.runStatus,
metadata: incomingFinding.metadata,
}
if (
existingFinding.resolver === 'Yaku' ||
existingFinding.resolver === 'Aqua' ||
existingFinding.resolver === SYSTEM_USER.id
)
if (existingFinding.resolver === SYSTEM_REQUEST_USER_ID)
updateFindingDto = {
...updateFindingDto,
status: 'unresolved' as StatusType,
Expand Down Expand Up @@ -220,13 +217,9 @@ export class FindingService {
return findingDto
}

if (
resolver === 'Yaku' ||
resolver === 'Aqua' ||
resolver === SYSTEM_USER.id
) {
if (resolver === SYSTEM_REQUEST_USER_ID) {
findingDto.resolvedManually = false
findingDto.resolver = SYSTEM_USER
findingDto.resolver = SYSTEM_REQUEST_USER as UserInNamespaceDto
} else {
findingDto.resolvedManually = true
const resolverToGet =
Expand Down Expand Up @@ -370,7 +363,7 @@ export class FindingService {
const updateFindingDto: UpdateFindingDTO = {
status: 'resolved' as StatusType,
resolvedComment: `This finding was automatically resolved by run ${lastRun.id}`,
resolver: SYSTEM_USER.id,
resolver: SYSTEM_REQUEST_USER_ID,
runId: lastRun.id,
runCompletionTime: lastRun.completionTime,
runOverallResult: lastRun.overallResult as RunOverallStatusType,
Expand Down Expand Up @@ -458,13 +451,7 @@ export class FindingService {
updateFindingDto.resolvedDate = new Date().toISOString()
}
if (updateFindingDto.resolver) {
if (
updateFindingDto.resolver === 'Yaku' ||
updateFindingDto.resolver === 'Aqua' ||
updateFindingDto.resolver === SYSTEM_USER.id
) {
updateFindingDto.resolver = SYSTEM_USER.id
} else {
if (updateFindingDto.resolver !== SYSTEM_REQUEST_USER_ID) {
const user = await this.usersService.getUser(updateFindingDto.resolver)
if (user.id === DELETED_USER.id) {
throw new BadRequestException(
Expand Down
2 changes: 1 addition & 1 deletion yaku-ui/qg-service-ui/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const OSS_COMPLIANCE_LINK = '/oss-compliance-information'
export const MONACO_CONTEXT_MENU_GROUP_YAKU = '9_yaku'

/** The resolver's name associated when a finding is automatically resolved */
export const AUTOMATIC_RESOLVER_NAME = 'Yaku'
export const AUTOMATIC_RESOLVER_ID = '00000000-0000-0000-0000-000000000000'

/** separator for values inside the url */
export const DOUBLE_HYPHEN = '--'
10 changes: 5 additions & 5 deletions yaku-ui/qg-service-ui/src/helpers/checkResolversName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// SPDX-License-Identifier: MIT

import { NamespaceUser } from '~/api'
import { AUTOMATIC_RESOLVER_NAME } from '~/config/app'
import { AUTOMATIC_RESOLVER_ID } from '~/config/app'

export const isAutoResolved = (resolver: string | NamespaceUser | null) => {
if ((typeof resolver as string) === 'string') {
export const isAutoResolved = (resolver: NamespaceUser | null) => {
if (resolver) {
return (
resolver?.toString().toLowerCase() ===
AUTOMATIC_RESOLVER_NAME.toLowerCase()
resolver.id?.toString().toLowerCase() ===
AUTOMATIC_RESOLVER_ID.toLowerCase()
)
}
return false
Expand Down

0 comments on commit fd75f04

Please sign in to comment.