Skip to content

Commit

Permalink
Rename User and Host records
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Sep 17, 2024
1 parent 4216ff3 commit ab6e773
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import { z } from '@kbn/zod';

export type UserEntityRecord = z.infer<typeof UserEntityRecord>;
export const UserEntityRecord = z.object({
export type UserEntity = z.infer<typeof UserEntity>;
export const UserEntity = z.object({
user: z
.object({
full_name: z.array(z.string()).optional(),
Expand All @@ -44,8 +44,8 @@ export const UserEntityRecord = z.object({
.optional(),
});

export type HostEntityRecord = z.infer<typeof HostEntityRecord>;
export const HostEntityRecord = z.object({
export type HostEntity = z.infer<typeof HostEntity>;
export const HostEntity = z.object({
host: z
.object({
hostname: z.array(z.string()).optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ info:
paths: {}
components:
schemas:
UserEntityRecord:
UserEntity:
type: object
properties:
user:
Expand Down Expand Up @@ -77,7 +77,7 @@ components:
- type
- firstSeenTimestamp
- definitionId
HostEntityRecord:
HostEntity:
type: object
properties:
host:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { z } from '@kbn/zod';
import { ArrayFromString } from '@kbn/zod-helpers';

import { EntityType, InspectQuery } from '../common.gen';
import { UserEntityRecord, HostEntityRecord } from './common.gen';
import { UserEntity, HostEntity } from './common.gen';

export type ListEntitiesRequestQuery = z.infer<typeof ListEntitiesRequestQuery>;
export const ListEntitiesRequestQuery = z.object({
Expand All @@ -36,7 +36,7 @@ export type ListEntitiesRequestQueryInput = z.input<typeof ListEntitiesRequestQu

export type ListEntitiesResponse = z.infer<typeof ListEntitiesResponse>;
export const ListEntitiesResponse = z.object({
records: z.array(z.union([UserEntityRecord, HostEntityRecord])),
records: z.array(z.union([UserEntity, HostEntity])),
page: z.number().int().min(1),
per_page: z.number().int().min(1).max(1000),
total: z.number().int().min(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ paths:
type: array
items:
oneOf:
- $ref: './common.schema.yaml#/components/schemas/UserEntityRecord'
- $ref: './common.schema.yaml#/components/schemas/HostEntityRecord'
- $ref: './common.schema.yaml#/components/schemas/UserEntity'
- $ref: './common.schema.yaml#/components/schemas/HostEntity'
page:
type: integer
minimum: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type { EntityClient } from '@kbn/entityManager-plugin/server/lib/entity_c
import type { SortOrder } from '@elastic/elasticsearch/lib/api/types';
import { createQueryFilterClauses } from '../../../utils/build_query';
import type {
HostEntityRecord,
UserEntityRecord,
HostEntity,
UserEntity,
} from '../../../../common/api/entity_analytics/entity_store/entities/common.gen';
import type {
InitEntityStoreRequestBody,
Expand Down Expand Up @@ -137,7 +137,7 @@ export class EntityStoreDataClient {
}

public async searchEntities(params: SearchEntitiesParams): Promise<{
records: Array<UserEntityRecord | HostEntityRecord>;
records: Array<UserEntity | HostEntity>;
total: number;
inspect: InspectQuery;
}> {
Expand All @@ -154,7 +154,7 @@ export class EntityStoreDataClient {
},
};

const response = await this.options.esClient.search<UserEntityRecord | HostEntityRecord>({
const response = await this.options.esClient.search<UserEntity | HostEntity>({
index,
query,
size: Math.min(perPage, MAX_SEARCH_RESPONSE_SIZE),
Expand All @@ -166,7 +166,7 @@ export class EntityStoreDataClient {

const total = typeof hits.total === 'number' ? hits.total : hits.total?.value ?? 0;

const records = hits.hits.map((hit) => hit._source as UserEntityRecord | HostEntityRecord);
const records = hits.hits.map((hit) => hit._source as UserEntity | HostEntity);

const inspect: InspectQuery = {
dsl: [JSON.stringify({ index, body: query }, null, 2)],
Expand Down

0 comments on commit ab6e773

Please sign in to comment.