Skip to content

Commit 1af39f1

Browse files
committed
feat: add support for get policy api url util
1 parent 5cb60ec commit 1af39f1

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Shared/Services/common.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616

1717
import { getUrlWithSearchParams } from '../../Common'
18-
import { GetResourceApiUrlProps } from './types'
18+
import { GetPolicyApiUrlProps, GetResourceApiUrlProps } from './types'
1919

2020
export const getResourceApiUrl = <T>({ baseUrl, kind, version, queryParams }: GetResourceApiUrlProps<T>) =>
2121
getUrlWithSearchParams(`${baseUrl}/${kind}/${version}`, queryParams)
22+
23+
export const getPolicyApiUrl = <T>({ kind, version, queryParams }: GetPolicyApiUrlProps<T>) =>
24+
getUrlWithSearchParams(`global/policy/${version}/${kind}`, queryParams)

src/Shared/Services/types.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { getUrlWithSearchParams } from '../../Common'
18-
import { ResourceKindType, ResourceVersionType } from '../types'
18+
import { PolicySubKindType, ResourceKindType, ResourceVersionType } from '../types'
1919

2020
export interface ClusterType {
2121
id: number
@@ -26,9 +26,19 @@ export interface ClusterType {
2626
isVirtual: boolean
2727
}
2828

29-
export interface GetResourceApiUrlProps<T> {
29+
/**
30+
* T => Type of query params
31+
* K => Type of kind
32+
* P => Type of version
33+
*/
34+
interface BaseGetApiUrlProps<T, K extends ResourceKindType | PolicySubKindType, P extends ResourceVersionType> {
3035
baseUrl: string
31-
kind: ResourceKindType
32-
version: ResourceVersionType
36+
kind: K
37+
version: P
3338
queryParams?: T extends Parameters<typeof getUrlWithSearchParams>[1] ? T : never
3439
}
40+
41+
export interface GetResourceApiUrlProps<T> extends BaseGetApiUrlProps<T, ResourceKindType, ResourceVersionType> {}
42+
43+
export interface GetPolicyApiUrlProps<T>
44+
extends Omit<BaseGetApiUrlProps<T, PolicySubKindType, ResourceVersionType>, 'baseUrl'> {}

src/Shared/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,18 @@ export enum ResourceKindType {
419419

420420
/**
421421
* Versions support for the resources on BE
422+
*
423+
* TODO: Rename to ApiVersionType
422424
*/
423425
export enum ResourceVersionType {
424426
v1 = 'v1',
425427
alpha1 = 'alpha1',
426428
}
427429

430+
export enum PolicySubKindType {
431+
lockConfiguration = 'config-protection',
432+
}
433+
428434
export interface LastExecutionResultType {
429435
lastExecution: string
430436
severityCount: {

0 commit comments

Comments
 (0)