Skip to content

Commit

Permalink
some minor renames for the api interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanSh authored and orouz committed Jan 13, 2022
1 parent 6dabbcb commit 0cee201
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
AggregationsKeyedBucketKeys,
} from '@elastic/elasticsearch/lib/api/types';
import type { SecuritySolutionPluginRouter } from '../../types';
import type { CloudPostureStats, PostureScore, EvaluationStats } from '../types';
import type { CloudPostureStats, BenchmarkStats, EvaluationStats } from '../types';

const FINDINGS_INDEX = `kubebeat*`;

Expand All @@ -26,11 +26,11 @@ const getFindingsEsQuery = (
): CountRequest => {
const filter: QueryDslQueryContainer[] = [{ term: { 'run_id.keyword': cycleId } }];

if (!!benchmark) {
if (benchmark) {
filter.push({ term: { 'rule.benchmark.keyword': benchmark } });
}

if (!!evaluationResult) {
if (evaluationResult) {
filter.push({ term: { 'result.evaluation.keyword': evaluationResult } });
}

Expand Down Expand Up @@ -71,13 +71,13 @@ const getEvaluationPerFilenameEsQuery = (
],
},
};
if (!!resources) {
if (resources) {
query.bool!.must = { terms: { 'resource.filename.keyword': resources } };
}
return {
index: FINDINGS_INDEX,
size: size,
query: query,
size,
query,
aggs: {
group: {
terms: { field: 'resource.filename.keyword' },
Expand Down Expand Up @@ -115,7 +115,7 @@ const getBenchmarks = async (esClient: ElasticsearchClient) => {
};

interface GroupFilename {
//TODO find the 'key', 'doc_count' interface
// TODO find the 'key', 'doc_count' interface
key: string;
doc_count: number;
group_docs: AggregationsTermsAggregate<AggregationsKeyedBucketKeys>;
Expand Down Expand Up @@ -159,7 +159,7 @@ const getEvaluationPerFilename = async (
const getAllFindingsStats = async (
esClient: ElasticsearchClient,
cycleId: string
): Promise<PostureScore> => {
): Promise<BenchmarkStats> => {
const findings = await esClient.count(getFindingsEsQuery(cycleId));
const passedFindings = await esClient.count(getFindingsEsQuery(cycleId, 'passed'));
const failedFindings = await esClient.count(getFindingsEsQuery(cycleId, 'failed'));
Expand All @@ -179,7 +179,7 @@ const getScorePerBenchmark = async (
esClient: ElasticsearchClient,
cycleId: string,
benchmarks: string[]
): Promise<PostureScore[]> => {
): Promise<BenchmarkStats[]> => {
const benchmarkScores = Promise.all(
benchmarks.map(async (benchmark) => {
const benchmarkFindings = await esClient.count(getFindingsEsQuery(benchmark, cycleId));
Expand Down
18 changes: 11 additions & 7 deletions x-pack/plugins/security_solution/server/cloud_posture/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
* 2.0.
*/

export interface PostureScore {
export type Evaluation = 'passed' | 'failed' | 'NA';

export interface BenchmarkStats {
name: string;
totalFindings?: number;
postureScore: number | undefined;
totalFindings?: number;
totalPassed: number | undefined;
totalFailed: number | undefined;
}
export interface CloudPostureStats extends PostureScore {
statsPerBenchmark: PostureScore[];
evaluationsPerResource: EvaluationStats[];
}

export interface EvaluationStats {
resource: string;
value: number;
evaluation: 'passed' | 'failed' | 'NA';
evaluation: Evaluation;
}

export interface CloudPostureStats extends BenchmarkStats {
statsPerBenchmark: BenchmarkStats[];
evaluationsPerResource: EvaluationStats[];
}

0 comments on commit 0cee201

Please sign in to comment.