Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/api/v2/catalogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions src/openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions src/otomi-stack.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -27,7 +27,6 @@ import {
AplAIModelResponse,
AplBuildRequest,
AplBuildResponse,
AplCatalog,
AplCatalogRequest,
AplCatalogResponse,
AplCodeRepoRequest,
Expand Down Expand Up @@ -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<AplCatalogResponse> {
Expand Down Expand Up @@ -1640,9 +1643,7 @@ export default class OtomiStack {
patch = false,
): Promise<AplCatalogResponse> {
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)
Expand Down
Loading