Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharatkk-metron committed Aug 6, 2024
1 parent 4601362 commit bcde8d8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 74 deletions.
8 changes: 1 addition & 7 deletions src/steps/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import {
IntegrationStepExecutionContext,
} from '@jupiterone/integration-sdk-core';

import {
ACCOUNT_ENTITY_KEY,
Entities,
INGESTION_SOURCE_IDS,
Steps,
} from '../constants';
import { ACCOUNT_ENTITY_KEY, Entities, Steps } from '../constants';
import { createAccountEntity } from './converter';
import { SonarqubeIntegrationConfig } from '../../types';

Expand All @@ -24,7 +19,6 @@ export const accountSteps: IntegrationStep<SonarqubeIntegrationConfig>[] = [
{
id: Steps.ACCOUNT,
name: 'Fetch Account',
ingestionSourceId: INGESTION_SOURCE_IDS.ACCOUNT,
entities: [Entities.ACCOUNT],
executionHandler: fetchAccount,
relationships: [],
Expand Down
2 changes: 0 additions & 2 deletions src/steps/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const V1_SEVERITIES_VALUES = [
'BLOCKER',
];
export const V2_SEVERITIES_VALUES = ['LOW', 'MEDIUM', 'HIGH'];
export const DEFAULT_FINDING_INGEST_SINCE_DAYS = 90;

export const FINDING_STATUSES = {
OPEN: 'OPEN',
Expand All @@ -35,7 +34,6 @@ export const FINDING_TYPES = {
};

export const INGESTION_SOURCE_IDS = {
ACCOUNT: 'accounts',
PROJECT: 'projects',
USERS: 'users',
USER_GROUPS: 'user-groups',
Expand Down
7 changes: 3 additions & 4 deletions src/steps/finding/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@jupiterone/integration-sdk-core';

import {
DEFAULT_FINDING_INGEST_SINCE_DAYS,
Entities,
INGESTION_SOURCE_IDS,
Relationships,
Expand Down Expand Up @@ -43,9 +42,9 @@ function getFilterParams(
if (findingTypes) {
filterParams[typesKey] = findingTypes;
}

filterParams['createdInLast'] =
`${findingsIngestSinceDays || DEFAULT_FINDING_INGEST_SINCE_DAYS}d`;
if (findingsIngestSinceDays) {
filterParams['createdInLast'] = `${findingsIngestSinceDays}d`;
}

return filterParams;
}
Expand Down
124 changes: 63 additions & 61 deletions src/validateInvocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,74 +55,76 @@ export default async function validateInvocation({
config.baseUrl = config.baseUrl.slice(0, -1);
}

if (config.findingSeverities) {
const findingSeverities = (config.findingSeverities as unknown as string)
.split(',')
.map((s) => s.trim());
if (!validSeverities(findingSeverities)) {
throw new IntegrationValidationError(
'Invalid Finding severities. Valid severities are INFO, MINOR, MAJOR, CRITICAL, BLOCKER',
);
}

if (config.apiVersion == APIVersion.V1) {
config.findingSeverities = findingSeverities;
} else {
const findingSeveritiesSet = new Set(
findingSeverities.map(
(findingSeverity) => FINDINGS_SEVERITIES[findingSeverity],
),
);
config.findingSeverities = Array.from(findingSeveritiesSet);
}
}
if (config.findingsIngestSinceDays !== undefined && isNaN(Number(config.findingsIngestSinceDays))) {
throw new IntegrationValidationError(`FINDINGS_INGEST_SINCE_DAYS must be a number if defined. Received: ${config.findingsIngestSinceDays}`);
}

if (config.findingStatus) {
const findingStatus = (config.findingStatus as unknown as string)
.split(',')
.map((s) => s.trim());
if (!validStatuses(findingStatus)) {
throw new IntegrationValidationError(
'Invalid Finding Status. Valid statuses are OPEN, CONFIRMED, REOPENED, RESOLVED, CLOSED',
);
}
const client = createSonarqubeClient(instance.config, logger);
try {
const systemInfo = await client.fetchSystemInfo();
config.apiVersion = getApiVersion(systemInfo);

if (config.apiVersion == APIVersion.V1) {
config.findingSeverities = findingStatus;
} else {
const findingStatusSet = new Set(
findingStatus.map(
(findingStatus) => FINDING_STATUSES[findingStatus],
),
);
config.findingStatus = Array.from(findingStatusSet);
if (config.findingSeverities) {
const findingSeverities = (config.findingSeverities as unknown as string)
.split(',')
.map((s) => s.trim());
if (!validSeverities(findingSeverities)) {
throw new IntegrationValidationError(
'Invalid Finding severities. Valid severities are INFO, MINOR, MAJOR, CRITICAL, BLOCKER',
);
}

if (config.apiVersion == APIVersion.V1) {
config.findingSeverities = findingSeverities;
} else {
const findingSeveritiesSet = new Set(
findingSeverities.map(
(findingSeverity) => FINDINGS_SEVERITIES[findingSeverity],
),
);
config.findingSeverities = Array.from(findingSeveritiesSet);
}
}
}

if (config.findingTypes) {
const findingTypes = (config.findingTypes as unknown as string)
.split(',')
.map((s) => s.trim());
if (!validTypes(findingTypes)) {
throw new IntegrationValidationError(
'Invalid vulnerability severities. Valid types are CODE_SMELL,BUG,VULNERABILITY',
);
if (config.findingStatus) {
const findingStatus = (config.findingStatus as unknown as string)
.split(',')
.map((s) => s.trim());
if (!validStatuses(findingStatus)) {
throw new IntegrationValidationError(
'Invalid Finding Status. Valid statuses are OPEN, CONFIRMED, REOPENED, RESOLVED, CLOSED',
);
}

if (config.apiVersion == APIVersion.V1) {
config.findingStatus = findingStatus;
} else {
const findingStatusSet = new Set(
findingStatus.map((findingStatus) => FINDING_STATUSES[findingStatus]),
);
config.findingStatus = Array.from(findingStatusSet);
}
}

if (config.apiVersion == APIVersion.V1) {
config.findingTypes = findingTypes;
} else {
const findingStatusSet = new Set(
findingTypes.map((findingType) => FINDING_TYPES[findingType]),
);
config.findingTypes = Array.from(findingStatusSet);
if (config.findingTypes) {
const findingTypes = (config.findingTypes as unknown as string)
.split(',')
.map((s) => s.trim());
if (!validTypes(findingTypes)) {
throw new IntegrationValidationError(
'Invalid vulnerability severities. Valid types are CODE_SMELL,BUG,VULNERABILITY',
);
}

if (config.apiVersion == APIVersion.V1) {
config.findingTypes = findingTypes;
} else {
const findingTypesSet = new Set(
findingTypes.map((findingType) => FINDING_TYPES[findingType]),
);
config.findingTypes = Array.from(findingTypesSet);
}
}
}

const client = createSonarqubeClient(instance.config, logger);
try {
const systemInfo = await client.fetchSystemInfo();
config.apiVersion = getApiVersion(systemInfo);

const resp = await client.fetchAuthenticationValidate();
if (!resp.valid) {
Expand Down

0 comments on commit bcde8d8

Please sign in to comment.