Skip to content
Merged
40 changes: 35 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/api/v2/catalogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Debug from 'debug'
import { Response } from 'express'
import { AplCatalogRequest, OpenApiRequestExt } from 'src/otomi-models'

const debug = Debug('otomi:api:v2:catalogs')

/**
* GET /v2/catalogs
* Get all catalogs
*/
export const getAllAplCatalogs = (req: OpenApiRequestExt, res: Response): void => {
debug('getAllCatalogs')
const v = req.otomi.getAllAplCatalogs()
res.json(v)
}

/**
* POST /v2/catalogs
* Create a catalog
*/
export const createAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
debug('createCatalog')
const data = await req.otomi.createAplCatalog(req.body as AplCatalogRequest)
res.json(data)
}
49 changes: 49 additions & 0 deletions src/api/v2/catalogs/{catalogId}.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Debug from 'debug'
import { Response } from 'express'
import { AplCatalogRequest, OpenApiRequestExt } from 'src/otomi-models'

const debug = Debug('otomi:api:v2:catalogs')

/**
* GET /v2/catalogs/{catalogId}
* Get a specific catalog
*/
export const getAplCatalog = (req: OpenApiRequestExt, res: Response): void => {
const { catalogId } = req.params
debug(`getAplCatalog(${catalogId})`)
const data = req.otomi.getAplCatalog(decodeURIComponent(catalogId))
res.json(data)
}

/**
* PUT /v2/catalogs/{catalogId}
* Edit a catalog
*/
export const editAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
const { catalogId } = req.params
debug(`editAplCatalog(${catalogId})`)
const data = await req.otomi.editAplCatalog(decodeURIComponent(catalogId), req.body as AplCatalogRequest)
res.json(data)
}

/**
* PATCH /v2/catalogs/{catalogId}
* Partially update a catalog
*/
export const patchAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
const { catalogId } = req.params
debug(`patchAplCatalog(${catalogId})`)
const data = await req.otomi.editAplCatalog(decodeURIComponent(catalogId), req.body as AplCatalogRequest, true)
res.json(data)
}

/**
* DELETE /v2/catalogs/{catalogId}
* Delete a catalog
*/
export const deleteAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
const { catalogId } = req.params
debug(`deleteAplCatalog(${catalogId})`)
await req.otomi.deleteAplCatalog(decodeURIComponent(catalogId))
res.json({})
}
16 changes: 16 additions & 0 deletions src/api/v2/catalogs/{catalogId}/charts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Debug from 'debug'
import { Response } from 'express'
import { OpenApiRequestExt } from 'src/otomi-models'

const debug = Debug('otomi:api:v2:catalogs:charts')

/**
* GET /v2/catalogs/{catalogId}/charts
* Get charts for a specific catalog
*/
export const getAplCatalogsCharts = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
const { catalogId } = req.params
debug(`getAplCatalog(${catalogId})`)
const data = await req.otomi.getAplCatalogCharts(decodeURIComponent(catalogId))
res.json(data)
}
8 changes: 8 additions & 0 deletions src/fileStore/file-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export function getFileMaps(envDir: string): Map<AplKind, FileMap> {
name: 'otomi',
})

maps.set('AplCatalog', {
kind: 'AplCatalog',
envDir,
pathGlob: `${envDir}/env/catalogs/*.{yaml,yaml.dec}`,
pathTemplate: 'env/catalogs/{name}.yaml',
name: 'catalogs',
})

maps.set('AplBackupCollection', {
kind: 'AplBackupCollection',
envDir,
Expand Down
15 changes: 13 additions & 2 deletions src/fileStore/file-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,25 @@ export class FileStore {
return filePath
}

deleteTeamResource(kind: AplKind, teamId: string, name: string): string {
const filePath = getResourceFilePath(kind, name, teamId)
this.store.delete(filePath)
return filePath
}

getPlatformResource(kind: AplKind, name: string): AplObject | undefined {
const filePath = getResourceFilePath(kind, name)
return this.store.get(filePath)
}

setPlatformResource(aplPlatformObject: AplPlatformObject): string {
const filePath = getResourceFilePath(aplPlatformObject.kind, aplPlatformObject.metadata.name)
this.store.set(filePath, aplPlatformObject)
return filePath
}

deleteTeamResource(kind: AplKind, teamId: string, name: string): string {
const filePath = getResourceFilePath(kind, name, teamId)
deletePlatformResource(kind: AplKind, name: string): string {
const filePath = getResourceFilePath(kind, name)
this.store.delete(filePath)
return filePath
}
Expand Down
Loading
Loading