Skip to content

Commit de8a355

Browse files
committed
fix: remove projects
1 parent d9ce6f9 commit de8a355

File tree

7 files changed

+2
-180
lines changed

7 files changed

+2
-180
lines changed

src/middleware/authz.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,11 @@ export function authorize(req: OpenApiRequestExt, res, next, authz: Authz, repoS
7777
Build: 'builds',
7878
Workload: 'workloads',
7979
Settings: 'otomi',
80-
Project: 'projects',
8180
Netpol: 'netpols',
8281
Policy: 'policies',
8382
SealedSecret: 'sealedSecrets',
8483
}
85-
const teamSpecificCollections = [
86-
'builds',
87-
'services',
88-
'workloads',
89-
'netpols',
90-
'projects',
91-
'policies',
92-
'sealedSecrets',
93-
] // <-- These are fetched per team
84+
const teamSpecificCollections = ['builds', 'services', 'workloads', 'netpols', 'policies', 'sealedSecrets'] // <-- These are fetched per team
9485

9586
const selector = renameKeys(req.params)
9687
const collectionId = schemaToRepoMap[schemaName]
@@ -133,7 +124,6 @@ export function authorize(req: OpenApiRequestExt, res, next, authz: Authz, repoS
133124
return next()
134125
}
135126
export function authzMiddleware(authz: Authz): RequestHandler {
136-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
137127
return async function nextHandler(req: OpenApiRequestExt, res, next): Promise<any> {
138128
if (req.user) {
139129
req.isSecurityHandler = true

src/otomi-stack.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ describe('Data validation', () => {
164164
services: [],
165165
sealedsecrets: [],
166166
backups: [],
167-
projects: [],
168167
netpols: [],
169168
settings: teamSettings,
170169
apps: [],
@@ -195,7 +194,6 @@ describe('Data validation', () => {
195194
services: [],
196195
sealedsecrets: [],
197196
backups: [],
198-
projects: [],
199197
netpols: [],
200198
settings: teamSettings,
201199
apps: [],
@@ -245,7 +243,6 @@ describe('Data validation', () => {
245243
services: [],
246244
sealedsecrets: [],
247245
backups: [],
248-
projects: [],
249246
netpols: [],
250247
settings: teamSettings,
251248
apps: [],
@@ -288,7 +285,6 @@ describe('Data validation', () => {
288285
services: [],
289286
sealedsecrets: [],
290287
backups: [],
291-
projects: [],
292288
netpols: [],
293289
settings: teamSettings,
294290
apps: [],

src/repo.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,6 @@ export function getFileMaps(envDir: string): Array<FileMap> {
338338
loadToSpec: true,
339339
v2: true,
340340
},
341-
{
342-
kind: 'AplTeamProject',
343-
envDir,
344-
jsonPathExpression: '$.teamConfig.*.projects[*]',
345-
pathGlob: `${envDir}/env/teams/*/projects/*.yaml`,
346-
processAs: 'arrayItem',
347-
resourceGroup: 'team',
348-
resourceDir: 'projects',
349-
loadToSpec: true,
350-
v2: true,
351-
},
352341
{
353342
kind: 'AplTeamNetworkControl',
354343
envDir,

src/services/RepoService.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,5 @@ describe('RepoService', () => {
198198
})
199199
expect(service.getAllBuilds()).toHaveLength(1)
200200
})
201-
202-
test('should return all projects', () => {
203-
service.getTeamConfigService('team1').createProject({
204-
kind: 'AplTeamProject',
205-
metadata: { name: 'Project1' },
206-
spec: {},
207-
})
208-
expect(service.getAllProjects()).toHaveLength(1)
209-
})
210201
})
211202
})

src/services/RepoService.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
AplCodeRepoResponse,
99
AplNetpolResponse,
1010
AplPolicyResponse,
11-
AplProjectResponse,
1211
AplSecretResponse,
1312
AplServiceResponse,
1413
AplTeamSettingsRequest,
@@ -27,8 +26,8 @@ import {
2726
User,
2827
Versions,
2928
} from '../otomi-models'
30-
import { TeamConfigService } from './TeamConfigService'
3129
import { createAplObject } from '../utils/manifests'
30+
import { TeamConfigService } from './TeamConfigService'
3231

3332
function mergeCustomizer(prev, next) {
3433
return next
@@ -136,7 +135,6 @@ export class RepoService {
136135
services: [],
137136
sealedsecrets: [],
138137
backups: [],
139-
projects: [],
140138
netpols: [],
141139
settings: {} as AplTeamSettingsResponse,
142140
apps: [],
@@ -241,10 +239,6 @@ export class RepoService {
241239
return this.getTeamIds().flatMap((teamName) => this.getTeamConfigService(teamName).getNetpols())
242240
}
243241

244-
public getAllProjects(): AplProjectResponse[] {
245-
return this.getTeamIds().flatMap((teamName) => this.getTeamConfigService(teamName).getProjects())
246-
}
247-
248242
public getAllBuilds(): AplBuildResponse[] {
249243
return this.getTeamIds().flatMap((teamName) => this.getTeamConfigService(teamName).getBuilds())
250244
}

src/services/TeamConfigService.test.ts

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
AplBackupRequest,
55
AplBuildRequest,
66
AplNetpolRequest,
7-
AplProjectRequest,
87
AplSecretRequest,
98
AplServiceRequest,
109
AplWorkloadRequest,
@@ -41,7 +40,6 @@ describe('TeamConfigService', () => {
4140
services: [],
4241
sealedsecrets: [],
4342
backups: [],
44-
projects: [],
4543
netpols: [],
4644
apps: [],
4745
policies: [],
@@ -296,41 +294,6 @@ describe('TeamConfigService', () => {
296294
})
297295
})
298296

299-
describe('Projects', () => {
300-
const project: AplProjectRequest = {
301-
kind: 'AplTeamProject',
302-
metadata: { name: 'TestProject' },
303-
spec: {},
304-
}
305-
306-
test('should create a project', () => {
307-
const created = service.createProject(project)
308-
expect(created).toEqual({
309-
kind: 'AplTeamProject',
310-
metadata: {
311-
name: 'TestProject',
312-
labels: {
313-
'apl.io/teamId': 'team1',
314-
},
315-
},
316-
spec: { name: 'TestProject' },
317-
status: {},
318-
})
319-
expect(service.getProject(created.metadata.name)).toEqual(created)
320-
})
321-
322-
test('should throw an error when creating duplicate project', () => {
323-
service.createProject(project)
324-
expect(() => service.createProject(project)).toThrow(AlreadyExists)
325-
})
326-
327-
test('should delete a project', () => {
328-
const created = service.createProject(project)
329-
service.deleteProject(created.metadata.name)
330-
expect(() => service.getProject(created.metadata.name)).toThrow(NotExistError)
331-
})
332-
})
333-
334297
describe('Netpols', () => {
335298
const netpol: AplNetpolRequest = {
336299
kind: 'AplTeamNetworkControl',
@@ -468,61 +431,6 @@ describe('TeamConfigService', () => {
468431
})
469432
})
470433

471-
describe('doesProjectNameExist', () => {
472-
test('should return false when no projects exist', () => {
473-
expect(service.doesProjectNameExist('NonExistentProject')).toBe(false)
474-
})
475-
476-
test('should return true when a build with the given name exists', () => {
477-
service.createBuild({
478-
kind: 'AplTeamBuild',
479-
metadata: { name: 'ExistingBuild' },
480-
spec: {},
481-
})
482-
expect(service.doesProjectNameExist('ExistingBuild')).toBe(true)
483-
})
484-
485-
test('should return true when a workload with the given name exists', () => {
486-
service.createWorkload({
487-
kind: 'AplTeamWorkload',
488-
metadata: { name: 'ExistingWorkload' },
489-
spec: {
490-
url: 'http://example.com',
491-
values: '',
492-
},
493-
})
494-
expect(service.doesProjectNameExist('ExistingWorkload')).toBe(true)
495-
})
496-
497-
test('should return true when a service with the given name exists', () => {
498-
service.createService({
499-
kind: 'AplTeamService',
500-
metadata: { name: 'ExistingService' },
501-
spec: {},
502-
})
503-
expect(service.doesProjectNameExist('ExistingService')).toBe(true)
504-
})
505-
506-
test('should return false when the name does not match any existing project', () => {
507-
service.createBuild({
508-
kind: 'AplTeamBuild',
509-
metadata: { name: 'SomeBuild' },
510-
spec: {},
511-
})
512-
service.createWorkload({
513-
kind: 'AplTeamWorkload',
514-
metadata: { name: 'SomeWorkload' },
515-
spec: { url: 'http://example.com', values: '' },
516-
})
517-
service.createService({
518-
kind: 'AplTeamService',
519-
metadata: { name: 'SomeService' },
520-
spec: {},
521-
})
522-
expect(service.doesProjectNameExist('NonExistentProject')).toBe(false)
523-
})
524-
})
525-
526434
describe('getCollection', () => {
527435
test('should retrieve an existing collection', () => {
528436
service.getSettings().metadata.name = 'team1'

src/services/TeamConfigService.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import {
1212
AplNetpolResponse,
1313
AplPolicyRequest,
1414
AplPolicyResponse,
15-
AplProjectRequest,
16-
AplProjectResponse,
1715
AplRequestObject,
1816
AplResponseObject,
1917
AplSecretRequest,
@@ -42,7 +40,6 @@ export class TeamConfigService {
4240
this.teamConfig.services ??= []
4341
this.teamConfig.sealedsecrets ??= []
4442
this.teamConfig.backups ??= []
45-
this.teamConfig.projects ??= []
4643
this.teamConfig.netpols ??= []
4744
this.teamConfig.apps ??= []
4845
this.teamConfig.policies ??= []
@@ -304,41 +301,6 @@ export class TeamConfigService {
304301
remove(this.teamConfig.backups, (item) => item.metadata.name === name)
305302
}
306303

307-
// =====================================
308-
// == PROJECTS CRUD ==
309-
// =====================================
310-
311-
public createProject(project: AplProjectRequest): AplProjectResponse {
312-
const { name } = project.metadata
313-
if (find(this.teamConfig.projects, (item) => item.metadata.name === name)) {
314-
throw new AlreadyExists(`Project[${name}] already exists.`)
315-
}
316-
317-
const newProject = this.createAplObject(name, {
318-
kind: project.kind,
319-
metadata: project.metadata,
320-
spec: { name },
321-
}) as AplProjectResponse
322-
this.teamConfig.projects.push(newProject)
323-
return newProject
324-
}
325-
326-
public getProject(name: string): AplProjectResponse {
327-
const project = find(this.teamConfig.projects, (item) => item.metadata.name === name)
328-
if (!project) {
329-
throw new NotExistError(`Project[${name}] does not exist.`)
330-
}
331-
return project
332-
}
333-
334-
public getProjects(): AplProjectResponse[] {
335-
return this.teamConfig.projects ?? []
336-
}
337-
338-
public deleteProject(name: string): void {
339-
remove(this.teamConfig.projects, (item) => item.metadata.name === name)
340-
}
341-
342304
// =====================================
343305
// == NETPOLS CRUD ==
344306
// =====================================
@@ -484,14 +446,6 @@ export class TeamConfigService {
484446
}
485447
}
486448

487-
public doesProjectNameExist(name: string): boolean {
488-
return (
489-
(this.teamConfig.builds && this.teamConfig.builds.some((build) => build.metadata.name === name)) ||
490-
(this.teamConfig.workloads && this.teamConfig.workloads.some((workload) => workload.metadata.name === name)) ||
491-
(this.teamConfig.services && this.teamConfig.services.some((service) => service.metadata.name === name))
492-
)
493-
}
494-
495449
/** Retrieve a collection dynamically from the Teamconfig */
496450
public getCollection(collectionId: string): AplResponseObject[] {
497451
if (!has(this.teamConfig, collectionId)) {

0 commit comments

Comments
 (0)