Skip to content

Commit 15e8e67

Browse files
committed
refactor: support for future autogenerated route sources
1 parent 9d86f73 commit 15e8e67

File tree

10 files changed

+203
-120
lines changed

10 files changed

+203
-120
lines changed

node-packages/commons/src/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ export async function getEnvironmentByName(
714714
value
715715
scope
716716
}
717-
apiRoutes{
717+
apiRoutes(source: API){
718718
domain
719719
service
720720
alternativeNames{
@@ -778,7 +778,7 @@ export async function getEnvironmentByIdWithVariables(
778778
value
779779
scope
780780
}
781-
apiRoutes{
781+
apiRoutes(source: API){
782782
domain
783783
service
784784
alternativeNames{

node-packages/commons/src/tasks.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
deployTargetPullrequest,
2727
deployTargetPromote
2828
} from './deploy-tasks';
29-
import { InternalEnvVariableScope, DeployData, DeployType, RemoveData } from './types';
29+
import { InternalEnvVariableScope, DeployData, DeployType, RemoveData, RouteSource } from './types';
3030
// @ts-ignore
3131
import sha1 from 'sha1';
3232
import crypto from 'crypto';
@@ -689,9 +689,14 @@ export const getEnvironmentsRouterPatternAndVariables = async function(
689689
let apiRoutes = environment.apiRoutes
690690
if (apiRoutes.length > 0) {
691691
for (let i = 0; i < apiRoutes.length; i++) {
692-
// remove any yaml sourced apiRoutes from the list (these don't get send to builds from the api as they are configured by lagoon.yml)
693-
if (apiRoutes[i].source == "YAML") {
694-
delete apiRoutes[i]
692+
// remove any yaml/autogenerated sourced apiRoutes from the list
693+
// these don't get send to builds from the api as they are configured by lagoon.yml
694+
// or are created by the autogenerated route configuration
695+
if ([RouteSource.YAML, RouteSource.AUTOGENERATED].includes(apiRoutes[i].source.toLowerCase())) {
696+
// the environment queries have (source: API) on the environments apiRoutes request
697+
// this check is just a fallback check
698+
apiRoutes.splice(i, 1);
699+
i--;
695700
continue;
696701
}
697702
// the structure of annotations in the build-deploy-tool are `map[string]string`

node-packages/commons/src/types.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ export enum AuditType {
5858
FILE = 'file',
5959
}
6060

61-
6261
export enum RouteType {
63-
Standard = "standard",
64-
Standby = "standby",
65-
Active = "active"
62+
STANDARD = 'standard',
63+
STANDBY = 'standby',
64+
ACTIVE = 'active'
65+
}
66+
67+
export enum RouteSource {
68+
API = 'api',
69+
YAML = 'yaml',
70+
AUTOGENERATED = 'autogenerated'
6671
}
6772

6873
export interface DeployData {

services/api/database/migrations/20250925000000_routes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ exports.up = async function(knex) {
2323
table.integer('hsts_max_age').defaultTo(3153600);
2424
table.boolean('primary').notNullable().defaultTo(0); // default to false
2525
table.boolean('disable_request_verification').notNullable().defaultTo(0); // default to false
26-
// table.text('annotations');
2726
table.text('path_routes');
28-
table.enu('source', ['api','yaml']).notNullable().defaultTo('api');
27+
table.enu('source', ['api','yaml','autogenerated']).notNullable().defaultTo('api');
2928
table.enu('type', ['standard', 'active', 'standby']).notNullable().defaultTo('standard');
3029
// table.boolean('wildcard').notNullable().defaultTo(0); // TBD
3130
// table.boolean('wildcard_apex').notNullable().defaultTo(0); // TBD

services/api/src/resolvers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ async function getResolvers() {
481481
RouteSource: {
482482
API: 'api',
483483
YAML: 'yaml',
484+
AUTOGENERATED: 'autogenerated',
484485
},
485486
RouteType: {
486487
STANDARD: 'standard',

services/api/src/resources/environment/helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export const Helpers = (sqlClientPool: Pool) => {
9595
// remove all route associations from environment
9696
// but leave the routes in the api attached to the project
9797
await routeHelpers(sqlClientPool).removeAllRoutesFromEnvironment(eid)
98+
// delete any autogenerated routes, these are not reusable and are only associated to the environment they are on
99+
await routeHelpers(sqlClientPool).deleteAutogeneratedRoutesForEnvironment(eid)
100+
// delete any lagoon.yml managed routes from the api, if they want to manage them in the api
101+
// they should be modified in the api to update the source to the api to nullify the lagoon.yml source
102+
await routeHelpers(sqlClientPool).deleteLagoonYAMLRoutesForEnvironment(eid)
98103

99104
// delete the environment backups rows
100105
// logger.debug(`deleting environment ${name}/id:${eid}/project:${pid} environment backups`)

services/api/src/resources/routes/helpers.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ export const Helpers = (sqlClientPool: Pool) => {
1111
Sql.removeAllRoutesFromEnvironment(environmentId)
1212
)
1313
}
14+
const deleteAutogeneratedRoutesForEnvironment = async (environmentId: number) => {
15+
await query(
16+
sqlClientPool,
17+
Sql.deleteAutogeneratedRoutesForEnvironment(environmentId)
18+
)
19+
}
20+
const deleteLagoonYAMLRoutesForEnvironment = async (environmentId: number) => {
21+
await query(
22+
sqlClientPool,
23+
Sql.deleteLagoonYAMLRoutesForEnvironment(environmentId)
24+
)
25+
}
1426
const removeRouteFromEnvironment = async (domain: string, environmentId: number) => {
1527
const routes = await query(
1628
sqlClientPool,
@@ -73,6 +85,8 @@ export const Helpers = (sqlClientPool: Pool) => {
7385

7486
return {
7587
removeAllRoutesFromEnvironment,
88+
deleteAutogeneratedRoutesForEnvironment,
89+
deleteLagoonYAMLRoutesForEnvironment,
7690
removeRouteFromEnvironment,
7791
addRouteAnnotation,
7892
addRouteAnnotations,

0 commit comments

Comments
 (0)