Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Project Services and Routes #1946

Merged
merged 10 commits into from
Jul 18, 2024
2 changes: 1 addition & 1 deletion backend/lib/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
'/cloudprofiles': require('./cloudprofiles'),
'/seeds': require('./seeds'),
'/gardenerextensions': require('./gardenerExtensions'),
'/namespaces': require('./namespaces'),
'/namespaces': require('./namespaces'), // TODO delete this legacy route
petersutter marked this conversation as resolved.
Show resolved Hide resolved
'/namespaces/:namespace/shoots': require('./shoots'),
'/namespaces/:namespace/tickets': require('./tickets'),
'/namespaces/:namespace/cloudprovidersecrets': require('./cloudProviderSecrets'),
Expand Down
14 changes: 7 additions & 7 deletions backend/lib/routes/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict'

const express = require('express')
const { projects } = require('../services')
const { namespaces } = require('../services')
const { metricsRoute } = require('../middleware')

const router = module.exports = express.Router()
Expand All @@ -19,7 +19,7 @@ router.route('/')
.get(async (req, res, next) => {
try {
const user = req.user
res.send(await projects.list({ user }))
res.send(await namespaces.list({ user }))
} catch (err) {
next(err)
}
Expand All @@ -28,7 +28,7 @@ router.route('/')
try {
const user = req.user
const body = req.body
res.send(await projects.create({ user, body }))
res.send(await namespaces.create({ user, body }))
} catch (err) {
next(err)
}
Expand All @@ -40,7 +40,7 @@ router.route('/:namespace')
try {
const user = req.user
const name = req.params.namespace
res.send(await projects.read({ user, name }))
res.send(await namespaces.read({ user, name }))
} catch (err) {
next(err)
}
Expand All @@ -50,7 +50,7 @@ router.route('/:namespace')
const user = req.user
const name = req.params.namespace
const body = req.body
res.send(await projects.patch({ user, name, body }))
res.send(await namespaces.patch({ user, name, body }))
} catch (err) {
next(err)
}
Expand All @@ -60,7 +60,7 @@ router.route('/:namespace')
const user = req.user
const name = req.params.namespace
const body = req.body
res.send(await projects.patch({ user, name, body }))
res.send(await namespaces.patch({ user, name, body }))
} catch (err) {
next(err)
}
Expand All @@ -69,7 +69,7 @@ router.route('/:namespace')
try {
const user = req.user
const name = req.params.namespace
res.send(await projects.remove({ user, name }))
res.send(await namespaces.remove({ user, name }))
} catch (err) {
next(err)
}
Expand Down
1 change: 1 addition & 0 deletions backend/lib/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module.exports = {
cloudprofiles: require('./cloudprofiles'),
seeds: require('./seeds'),
namespaces: require('./namespaces'),
projects: require('./projects'),
shoots: require('./shoots'),
cloudProviderSecrets: require('./cloudProviderSecrets'),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`api projects should create a project 1`] = `
exports[`api namespaces should create a project 1`] = `
[
[
{
Expand Down Expand Up @@ -45,7 +45,7 @@ exports[`api projects should create a project 1`] = `
]
`;

exports[`api projects should create a project 2`] = `
exports[`api namespaces should create a project 2`] = `
{
"data": {
"createdBy": "[email protected]",
Expand All @@ -66,7 +66,7 @@ exports[`api projects should create a project 2`] = `
}
`;

exports[`api projects should delete a project 1`] = `
exports[`api namespaces should delete a project 1`] = `
[
[
{
Expand Down Expand Up @@ -119,7 +119,7 @@ exports[`api projects should delete a project 1`] = `
]
`;

exports[`api projects should delete a project 2`] = `
exports[`api namespaces should delete a project 2`] = `
{
"data": {
"createdBy": "[email protected]",
Expand All @@ -140,7 +140,7 @@ exports[`api projects should delete a project 2`] = `
}
`;

exports[`api projects should patch a project 1`] = `
exports[`api namespaces should patch a project 1`] = `
[
[
{
Expand All @@ -160,7 +160,7 @@ exports[`api projects should patch a project 1`] = `
]
`;

exports[`api projects should patch a project 2`] = `
exports[`api namespaces should patch a project 2`] = `
{
"data": {
"createdBy": "[email protected]",
Expand All @@ -181,7 +181,7 @@ exports[`api projects should patch a project 2`] = `
}
`;

exports[`api projects should reject request with authorization error 1`] = `
exports[`api namespaces should reject request with authorization error 1`] = `
[
[
{
Expand All @@ -195,7 +195,7 @@ exports[`api projects should reject request with authorization error 1`] = `
]
`;

exports[`api projects should reject request with authorization error 2`] = `
exports[`api namespaces should reject request with authorization error 2`] = `
{
"code": 403,
"details": Any<Object>,
Expand All @@ -205,7 +205,7 @@ exports[`api projects should reject request with authorization error 2`] = `
}
`;

exports[`api projects should return all projects 1`] = `
exports[`api namespaces should return all projects 1`] = `
[
[
{
Expand All @@ -231,7 +231,7 @@ exports[`api projects should return all projects 1`] = `
]
`;

exports[`api projects should return all projects 2`] = `
exports[`api namespaces should return all projects 2`] = `
[
{
"data": {
Expand Down Expand Up @@ -341,7 +341,7 @@ exports[`api projects should return all projects 2`] = `
]
`;

exports[`api projects should return the foo project 1`] = `
exports[`api namespaces should return the foo project 1`] = `
[
[
{
Expand All @@ -355,7 +355,7 @@ exports[`api projects should return the foo project 1`] = `
]
`;

exports[`api projects should return the foo project 2`] = `
exports[`api namespaces should return the foo project 2`] = `
{
"data": {
"createdBy": "[email protected]",
Expand All @@ -376,7 +376,7 @@ exports[`api projects should return the foo project 2`] = `
}
`;

exports[`api projects should return three projects 1`] = `
exports[`api namespaces should return three projects 1`] = `
[
[
{
Expand All @@ -402,7 +402,7 @@ exports[`api projects should return three projects 1`] = `
]
`;

exports[`api projects should return three projects 2`] = `
exports[`api namespaces should return three projects 2`] = `
[
{
"data": {
Expand Down Expand Up @@ -453,7 +453,7 @@ exports[`api projects should return three projects 2`] = `
]
`;

exports[`api projects should timeout when creating a project 1`] = `
exports[`api namespaces should timeout when creating a project 1`] = `
[
[
{
Expand Down Expand Up @@ -498,7 +498,7 @@ exports[`api projects should timeout when creating a project 1`] = `
]
`;

exports[`api projects should timeout when creating a project 2`] = `
exports[`api namespaces should timeout when creating a project 2`] = `
{
"code": 504,
"details": Any<Object>,
Expand All @@ -508,7 +508,7 @@ exports[`api projects should timeout when creating a project 2`] = `
}
`;

exports[`api projects should update a project 1`] = `
exports[`api namespaces should update a project 1`] = `
[
[
{
Expand Down Expand Up @@ -539,7 +539,7 @@ exports[`api projects should update a project 1`] = `
]
`;

exports[`api projects should update a project 2`] = `
exports[`api namespaces should update a project 2`] = `
{
"data": {
"createdBy": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('api', function () {
mockRequest.mockReset()
})

describe('projects', function () {
describe('namespaces', function () {
const user = fixtures.auth.createUser({
id: '[email protected]',
groups: ['group1']
Expand All @@ -52,7 +52,7 @@ describe('api', function () {
const purpose = 'purpose'

beforeAll(() => {
require('../../lib/services/projects').projectInitializationTimeout = 10
require('../../lib/services/namespaces').projectInitializationTimeout = 10
})

it('should return three projects', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

'use strict'

const projects = require('../lib/services/projects')
const projects = require('../lib/services/namespaces')
const cache = require('../lib/cache')
const authorization = require('../lib/services/authorization')

describe('services', function () {
describe('projects', function () {
describe('namespaces', function () {
const projectList = [
{
spec: {
Expand Down