Skip to content
25 changes: 5 additions & 20 deletions src/api.authz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 1 addition & 30 deletions src/openapi/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
22 changes: 12 additions & 10 deletions src/otomi-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`)
Expand Down Expand Up @@ -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) => {
Expand Down
14 changes: 9 additions & 5 deletions src/services/TeamConfigService.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Mock UUID to generate predictable values
import { AlreadyExists, NotExistError } from '../error'
import {
App,
Backup,
Expand All @@ -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'),
Expand Down Expand Up @@ -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)
})

Expand Down Expand Up @@ -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)
})
})
Expand Down
1 change: 0 additions & 1 deletion test/env/teams/services.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ teamConfig:
paths: []
port: 80
tlsPass: true
type: public