diff --git a/src/api.authz.test.ts b/src/api.authz.test.ts index cfcdfbaff..7ad60a8b5 100644 --- a/src/api.authz.test.ts +++ b/src/api.authz.test.ts @@ -7,10 +7,10 @@ import getToken from 'src/fixtures/jwt' import OtomiStack from 'src/otomi-stack' import request, { SuperAgentTest } from 'supertest' import { HttpError } from './error' +import { Git } from './git' import { getSessionStack } from './middleware' import { App, CodeRepo, SealedSecret } from './otomi-models' import * as getValuesSchemaModule from './utils' -import { Git } from './git' const platformAdminToken = getToken(['platform-admin']) const teamAdminToken = getToken(['team-admin', 'team-team1']) @@ -188,24 +188,6 @@ describe('API authz tests', () => { .expect('Content-Type', /json/) }) - test('team member can create its own services', async () => { - jest.spyOn(otomiStack, 'createService').mockResolvedValue({} as any) - await agent - .post('/v1/teams/team1/services') - .send({ - name: 'newservice', - serviceType: 'ksvcPredeployed', - ingress: { type: 'cluster' }, - networkPolicy: { - ingressPrivate: { mode: 'DenyAll' }, - }, - }) - .set('Content-Type', 'application/json') - .set('Authorization', `Bearer ${teamMemberToken}`) - .expect(200) - .expect('Content-Type', /json/) - }) - test('team member can get its services', async () => { await agent .get('/v1/teams/team1/services') @@ -246,7 +228,10 @@ describe('API authz tests', () => { .send({ name: 'service1', serviceType: 'ksvcPredeployed', - ingress: {}, + ingress: { + domain: 'test.net', + subdomain: 'demo-a', + }, }) .set('Authorization', `Bearer ${teamMemberToken}`) .expect(403) diff --git a/src/openapi/api.yaml b/src/openapi/api.yaml index f305dbda1..9bb16343a 100644 --- a/src/openapi/api.yaml +++ b/src/openapi/api.yaml @@ -1731,10 +1731,6 @@ components: $ref: codeRepo.yaml#/CodeRepo Ingress: $ref: service.yaml#/Ingress - IngressCluster: - $ref: service.yaml#/IngressCluster - IngressPublic: - $ref: service.yaml#/IngressPublic K8sService: $ref: k8s.yaml#/K8sService Kubecfg: diff --git a/src/openapi/service.yaml b/src/openapi/service.yaml index 46f840bea..ce70573fa 100644 --- a/src/openapi/service.yaml +++ b/src/openapi/service.yaml @@ -73,10 +73,7 @@ Service: ingress: title: Exposure (ingress) description: Determines loadbalancer related configuration for handling the service ingress. - # Note: the order matters first schema must be nullable empty object - oneOf: - - $ref: '#/IngressCluster' - - $ref: '#/IngressPublic' + $ref: '#/Ingress' required: - name @@ -176,29 +173,3 @@ Ingress: - domain - subdomain type: object - -IngressCluster: - additionalProperties: false - title: No Exposure - type: object - nullable: true - properties: - type: - type: string - enum: - - cluster - default: cluster - -IngressPublic: - allOf: - - $ref: '#/Ingress' - - properties: - type: - type: string - enum: - - public - default: public - nullable: true - type: object - description: Will only accept traffic coming from an external loadbalancer. - title: External diff --git a/src/otomi-stack.ts b/src/otomi-stack.ts index 27c36db30..4f59aaa23 100644 --- a/src/otomi-stack.ts +++ b/src/otomi-stack.ts @@ -261,8 +261,10 @@ export default class OtomiStack { await this.git.pull() //TODO fetch this url from the repo if (await this.git.fileExists(clusterSettingsFilePath)) break + debug(`path: ${clusterSettingsFilePath}`) debug(`Values are not present at ${url}:${branch}`) } catch (e) { + console.log('ERROR getting VALUES: ', e) // Remove password from error message const safeCommand = JSON.stringify(e.task?.commands).replace(env.GIT_PASSWORD, '****') debug(`${e.message.trim()} for command ${JSON.stringify(safeCommand)}`) @@ -1755,16 +1757,16 @@ export default class OtomiStack { const client = this.getApiClient() const collection: K8sService[] = [] - // if (user.isAdmin) { - // const svcList = await client.listServiceForAllNamespaces() - // svcList.body.items.map((item) => { - // collection.push({ - // name: item.metadata!.name ?? 'unknown', - // ports: item.spec?.ports?.map((portItem) => portItem.port) ?? [], - // }) - // }) - // return collection - // } + if (teamId === 'team-admin') { + const svcList = await client.listServiceForAllNamespaces() + svcList.body.items.map((item) => { + collection.push({ + name: item.metadata!.name ?? 'unknown', + ports: item.spec?.ports?.map((portItem) => portItem.port) ?? [], + }) + }) + return collection + } const svcList = await client.listNamespacedService(`team-${teamId}`) svcList.body.items.map((item) => { diff --git a/src/services/TeamConfigService.test.ts b/src/services/TeamConfigService.test.ts index c9ca8ac6c..99d26d160 100644 --- a/src/services/TeamConfigService.test.ts +++ b/src/services/TeamConfigService.test.ts @@ -1,4 +1,5 @@ // Mock UUID to generate predictable values +import { AlreadyExists, NotExistError } from '../error' import { App, Backup, @@ -12,7 +13,6 @@ import { WorkloadValues, } from '../otomi-models' import { TeamConfigService } from './TeamConfigService' -import { AlreadyExists, NotExistError } from '../error' jest.mock('uuid', () => ({ v4: jest.fn(() => 'mocked-uuid'), @@ -114,11 +114,15 @@ describe('TeamConfigService', () => { }) describe('Services', () => { - const serviceData: Service = { name: 'TestService', ingress: {} } + const serviceData: Service = { name: 'TestService', ingress: { domain: 'test.apl.com', subdomain: 'demo-a' } } test('should create a service', () => { const createdService = service.createService(serviceData) - expect(createdService).toEqual({ name: 'TestService', id: 'mocked-uuid', ingress: {} }) + expect(createdService).toEqual({ + name: 'TestService', + id: 'mocked-uuid', + ingress: { domain: 'test.apl.com', subdomain: 'demo-a' }, + }) expect(service.getServices()).toHaveLength(1) }) @@ -331,14 +335,14 @@ describe('TeamConfigService', () => { }) test('should return true when a service with the given name exists', () => { - service.createService({ name: 'ExistingService', ingress: {} }) + service.createService({ name: 'ExistingService', ingress: { domain: 'test.apl.com', subdomain: 'demo-a' } }) expect(service.doesProjectNameExist('ExistingService')).toBe(true) }) test('should return false when the name does not match any existing project', () => { service.createBuild({ name: 'SomeBuild' }) service.createWorkload({ name: 'SomeWorkload', url: 'http://example.com' }) - service.createService({ name: 'SomeService', ingress: {} }) + service.createService({ name: 'SomeService', ingress: { domain: 'test.apl.com', subdomain: 'demo-a' } }) expect(service.doesProjectNameExist('NonExistentProject')).toBe(false) }) }) diff --git a/test/env/teams/services.dev.yaml b/test/env/teams/services.dev.yaml index ac318f223..4849c80b3 100644 --- a/test/env/teams/services.dev.yaml +++ b/test/env/teams/services.dev.yaml @@ -7,4 +7,3 @@ teamConfig: paths: [] port: 80 tlsPass: true - type: public