Skip to content

Commit 1fe6405

Browse files
ElderMattdennisvankekemsvcAPLBot
authored
feat: byo catalog support (#919)
* feat: getall and create catalog * feat: catalog endpoints * fix: create and filemap for catalogs * fix: workload catalog * feat: get charts from byo catalog * feat: refactor getting catalog charts * fix: tests * feat: added tests for helper functions * feat: removed v1 object and additional properties * fix: remove commented code and definition appcatalog --------- Co-authored-by: Dennis van Kekem <38350840+dennisvankekem@users.noreply.github.com> Co-authored-by: svcAPLBot <174728082+svcAPLBot@users.noreply.github.com>
1 parent 7f454c8 commit 1fe6405

12 files changed

Lines changed: 973 additions & 84 deletions

File tree

package-lock.json

Lines changed: 35 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/v2/catalogs.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Debug from 'debug'
2+
import { Response } from 'express'
3+
import { AplCatalogRequest, OpenApiRequestExt } from 'src/otomi-models'
4+
5+
const debug = Debug('otomi:api:v2:catalogs')
6+
7+
/**
8+
* GET /v2/catalogs
9+
* Get all catalogs
10+
*/
11+
export const getAllAplCatalogs = (req: OpenApiRequestExt, res: Response): void => {
12+
debug('getAllCatalogs')
13+
const v = req.otomi.getAllAplCatalogs()
14+
res.json(v)
15+
}
16+
17+
/**
18+
* POST /v2/catalogs
19+
* Create a catalog
20+
*/
21+
export const createAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
22+
debug('createCatalog')
23+
const data = await req.otomi.createAplCatalog(req.body as AplCatalogRequest)
24+
res.json(data)
25+
}

src/api/v2/catalogs/{catalogId}.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Debug from 'debug'
2+
import { Response } from 'express'
3+
import { AplCatalogRequest, OpenApiRequestExt } from 'src/otomi-models'
4+
5+
const debug = Debug('otomi:api:v2:catalogs')
6+
7+
/**
8+
* GET /v2/catalogs/{catalogId}
9+
* Get a specific catalog
10+
*/
11+
export const getAplCatalog = (req: OpenApiRequestExt, res: Response): void => {
12+
const { catalogId } = req.params
13+
debug(`getAplCatalog(${catalogId})`)
14+
const data = req.otomi.getAplCatalog(decodeURIComponent(catalogId))
15+
res.json(data)
16+
}
17+
18+
/**
19+
* PUT /v2/catalogs/{catalogId}
20+
* Edit a catalog
21+
*/
22+
export const editAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
23+
const { catalogId } = req.params
24+
debug(`editAplCatalog(${catalogId})`)
25+
const data = await req.otomi.editAplCatalog(decodeURIComponent(catalogId), req.body as AplCatalogRequest)
26+
res.json(data)
27+
}
28+
29+
/**
30+
* PATCH /v2/catalogs/{catalogId}
31+
* Partially update a catalog
32+
*/
33+
export const patchAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
34+
const { catalogId } = req.params
35+
debug(`patchAplCatalog(${catalogId})`)
36+
const data = await req.otomi.editAplCatalog(decodeURIComponent(catalogId), req.body as AplCatalogRequest, true)
37+
res.json(data)
38+
}
39+
40+
/**
41+
* DELETE /v2/catalogs/{catalogId}
42+
* Delete a catalog
43+
*/
44+
export const deleteAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
45+
const { catalogId } = req.params
46+
debug(`deleteAplCatalog(${catalogId})`)
47+
await req.otomi.deleteAplCatalog(decodeURIComponent(catalogId))
48+
res.json({})
49+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Debug from 'debug'
2+
import { Response } from 'express'
3+
import { OpenApiRequestExt } from 'src/otomi-models'
4+
5+
const debug = Debug('otomi:api:v2:catalogs:charts')
6+
7+
/**
8+
* GET /v2/catalogs/{catalogId}/charts
9+
* Get charts for a specific catalog
10+
*/
11+
export const getAplCatalogsCharts = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
12+
const { catalogId } = req.params
13+
debug(`getAplCatalog(${catalogId})`)
14+
const data = await req.otomi.getAplCatalogCharts(decodeURIComponent(catalogId))
15+
res.json(data)
16+
}

src/fileStore/file-map.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ export function getFileMaps(envDir: string): Map<AplKind, FileMap> {
9191
name: 'otomi',
9292
})
9393

94+
maps.set('AplCatalog', {
95+
kind: 'AplCatalog',
96+
envDir,
97+
pathGlob: `${envDir}/env/catalogs/*.{yaml,yaml.dec}`,
98+
pathTemplate: 'env/catalogs/{name}.yaml',
99+
name: 'catalogs',
100+
})
101+
94102
maps.set('AplBackupCollection', {
95103
kind: 'AplBackupCollection',
96104
envDir,

src/fileStore/file-store.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,25 @@ export class FileStore {
167167
return filePath
168168
}
169169

170+
deleteTeamResource(kind: AplKind, teamId: string, name: string): string {
171+
const filePath = getResourceFilePath(kind, name, teamId)
172+
this.store.delete(filePath)
173+
return filePath
174+
}
175+
176+
getPlatformResource(kind: AplKind, name: string): AplObject | undefined {
177+
const filePath = getResourceFilePath(kind, name)
178+
return this.store.get(filePath)
179+
}
180+
170181
setPlatformResource(aplPlatformObject: AplPlatformObject): string {
171182
const filePath = getResourceFilePath(aplPlatformObject.kind, aplPlatformObject.metadata.name)
172183
this.store.set(filePath, aplPlatformObject)
173184
return filePath
174185
}
175186

176-
deleteTeamResource(kind: AplKind, teamId: string, name: string): string {
177-
const filePath = getResourceFilePath(kind, name, teamId)
187+
deletePlatformResource(kind: AplKind, name: string): string {
188+
const filePath = getResourceFilePath(kind, name)
178189
this.store.delete(filePath)
179190
return filePath
180191
}

0 commit comments

Comments
 (0)