diff --git a/src/api/v2/catalogs.ts b/src/api/v2/catalogs.ts index a618d162..efc49d83 100644 --- a/src/api/v2/catalogs.ts +++ b/src/api/v2/catalogs.ts @@ -10,7 +10,12 @@ const debug = Debug('otomi:api:v2:catalogs') */ export const getAllAplCatalogs = (req: OpenApiRequestExt, res: Response): void => { debug('getAllCatalogs') - const v = req.otomi.getAllAplCatalogs() + const { enabled } = req.query + const filter = {} + if (enabled !== undefined) { + filter['enabled'] = enabled + } + const v = req.otomi.getAllAplCatalogs(filter) res.json(v) } diff --git a/src/openapi/api.yaml b/src/openapi/api.yaml index f72a66c7..7338c3be 100644 --- a/src/openapi/api.yaml +++ b/src/openapi/api.yaml @@ -1724,6 +1724,13 @@ paths: x-eov-operation-handler: v2/catalogs description: Get all catalogs x-aclSchema: AplCatalog + parameters: + - name: enabled + in: query + description: Filter catalogs by enabled status + required: false + schema: + type: boolean responses: '200': description: Successfully obtained app catalogs diff --git a/src/otomi-stack.ts b/src/otomi-stack.ts index ba115f6d..143bf73c 100644 --- a/src/otomi-stack.ts +++ b/src/otomi-stack.ts @@ -1,4 +1,4 @@ -import { CoreV1Api, KubeConfig, User as k8sUser, V1ObjectReference } from '@kubernetes/client-node' +import { CoreV1Api, User as k8sUser, KubeConfig, V1ObjectReference } from '@kubernetes/client-node' import Debug from 'debug' import { getRegions, ObjectStorageKeyRegions } from '@linode/api-v4' @@ -27,7 +27,6 @@ import { AplAIModelResponse, AplBuildRequest, AplBuildResponse, - AplCatalog, AplCatalogRequest, AplCatalogResponse, AplCodeRepoRequest, @@ -1610,9 +1609,13 @@ export default class OtomiStack { } } - getAllAplCatalogs(): AplCatalogResponse[] { + getAllAplCatalogs(catalogFilter: { enabled?: boolean }): AplCatalogResponse[] { const files = this.fileStore.getPlatformResourcesByKind('AplCatalog') - return Array.from(files.values()) as AplCatalogResponse[] + let catalogs = Array.from(files.values()) as AplCatalogResponse[] + if (catalogFilter.enabled !== undefined) { + catalogs = catalogs.filter((catalog) => catalog.spec.enabled === catalogFilter.enabled) + } + return catalogs } async createAplCatalog(data: AplCatalogRequest): Promise { @@ -1640,9 +1643,7 @@ export default class OtomiStack { patch = false, ): Promise { const existing = this.getAplCatalog(name) - const updatedSpec = patch - ? merge(cloneDeep(existing.spec), data.spec) - : ({ ...existing, ...data.spec } as AplCatalog) + const updatedSpec = patch ? merge(cloneDeep(existing.spec), data.spec) : { ...existing.spec, ...data.spec } const platformObject = buildPlatformObject(existing.kind, existing.metadata.name, updatedSpec) const aplRecord = await this.saveCatalog(platformObject)