Skip to content

Commit

Permalink
Bed 3375 UI (#109)
Browse files Browse the repository at this point in the history
* feat: add domainsid filtering to posture endpoint in bhe js client

* chore: add types and sort by param to posture endpoint in js api client
  • Loading branch information
urangel authored Sep 19, 2023
1 parent 4b8170c commit b3fb3b7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/javascript/js-client-library/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import axios, { AxiosInstance } from 'axios';
import * as types from './types';
import { CreateAuthTokenResponse, ListAuthTokensResponse } from './responses';
import { CreateAuthTokenResponse, ListAuthTokensResponse, PostureResponse } from './responses';

class BHEAPIClient {
baseClient: AxiosInstance;
Expand Down Expand Up @@ -188,19 +188,25 @@ class BHEAPIClient {
);
};

getPostureStats = (from: Date, to: Date, options?: types.RequestOptions) =>
this.baseClient.get(
getPostureStats = (from: Date, to: Date, domainSID?: string, sortBy?: string, options?: types.RequestOptions) => {
const params: types.PostureRequest = {
from: from.toISOString(),
to: to.toISOString(),
};

if (domainSID) params.domain_sid = `eq:${domainSID}`;
if (sortBy) params.sort_by = sortBy;

return this.baseClient.get<PostureResponse>(
'/api/v2/posture-stats',
Object.assign(
{
params: {
from: from.toISOString(),
to: to.toISOString(),
},
params: params,
},
options
)
);
};

/* ingest */
ingestData = (options?: types.RequestOptions) => this.baseClient.post('/api/v2/ingest', options);
Expand Down
10 changes: 10 additions & 0 deletions packages/javascript/js-client-library/src/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ type TimestampFields = {
};
};

type PostureStat = TimestampFields & {
domain_sid: string;
exposure_index: number;
tier_zero_count: number;
critical_risk_count: number;
id: number;
};

export type PostureResponse = PaginatedResponse<PostureStat[]>;

export type AuthToken = TimestampFields & {
hmac_method: string;
id: string;
Expand Down
7 changes: 7 additions & 0 deletions packages/javascript/js-client-library/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ export interface GetCollectorsResponse {
};
}

export type PostureRequest = {
from: string;
to: string;
domain_sid?: string;
sort_by?: string;
};

export type GraphNode = {
label: string;
kind: string;
Expand Down

0 comments on commit b3fb3b7

Please sign in to comment.