Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: switcherapi/switcher-api
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.2.7
Choose a base ref
...
head repository: switcherapi/switcher-api
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 16,504 additions and 5,875 deletions.
  1. +14 −6 .env-cmdrc-template
  2. +0 −26 .eslintrc.json
  3. +1 −3 .github/FUNDING.yml
  4. +2 −4 .github/ISSUE_TEMPLATE/patch_report.md
  5. +34 −29 .github/workflows/master.yml
  6. +97 −0 .github/workflows/re-release.yml
  7. +20 −15 .github/workflows/release.yml
  8. +6 −0 .vscode/settings.json
  9. +7 −7 Dockerfile
  10. +1 −1 LICENSE
  11. +11 −25 README.md
  12. +0 −12 babel.config.js
  13. +12 −4 config/.env.dev
  14. +25 −5 docker-compose.yml
  15. +24 −0 eslint.config.js
  16. +0 −193 jest.config.js
  17. +6,804 −0 npm-shrinkwrap.json
  18. +37 −34 package.json
  19. +29 −9 requests/Switcher API (dev).postman_environment.json
  20. +1,434 −790 requests/Switcher API.postman_collection.json
  21. +2 −2 sonar-project.properties
  22. +7 −4 src/api-docs/paths/path-admin.js
  23. +0 −201 src/api-docs/paths/path-client.js
  24. +9 −9 src/api-docs/paths/path-component.js
  25. +18 −16 src/api-docs/paths/path-config-strategy.js
  26. +40 −4 src/api-docs/paths/path-config.js
  27. +52 −5 src/api-docs/paths/path-domain.js
  28. +8 −8 src/api-docs/paths/path-environment.js
  29. +213 −0 src/api-docs/paths/path-gitops.js
  30. +11 −11 src/api-docs/paths/path-group-config.js
  31. +28 −28 src/api-docs/paths/path-metric.js
  32. +18 −18 src/api-docs/paths/path-permission.js
  33. +35 −54 src/api-docs/paths/path-slack.js
  34. +11 −11 src/api-docs/paths/path-team.js
  35. +3 −0 src/api-docs/schemas/admin.js
  36. +2 −2 src/api-docs/schemas/component.js
  37. +28 −9 src/api-docs/schemas/config-strategy.js
  38. +23 −3 src/api-docs/schemas/config.js
  39. +24 −2 src/api-docs/schemas/domain.js
  40. +1 −1 src/api-docs/schemas/environment.js
  41. +239 −0 src/api-docs/schemas/gitops.js
  42. +14 −1 src/api-docs/schemas/group-config.js
  43. +1 −1 src/api-docs/schemas/metric.js
  44. +13 −1 src/api-docs/schemas/permission.js
  45. +22 −12 src/api-docs/schemas/slack.js
  46. +32 −37 src/api-docs/swagger-document.js
  47. +1 −1 src/api-docs/swagger-info.js
  48. +19 −0 src/app-server.js
  49. +47 −52 src/app.js
  50. +22 −18 src/client/configuration-resolvers.js
  51. +47 −18 src/client/configuration-type.js
  52. +1 −25 src/client/criteria-type.js
  53. +33 −14 src/client/permission-resolvers.js
  54. +1 −1 src/client/permission-type.js
  55. +17 −56 src/client/relay/index.js
  56. +50 −144 src/client/resolvers.js
  57. +10 −32 src/client/schema.js
  58. +14 −10 src/exceptions/index.js
  59. +125 −0 src/external/gitops.js
  60. +4 −2 src/external/google-recaptcha.js
  61. +4 −1 src/external/oauth-bitbucket.js
  62. +4 −1 src/external/oauth-git.js
  63. +2 −1 src/external/sendgrid.js
  64. +155 −87 src/external/switcher-api-facade.js
  65. +63 −0 src/helpers/cache.js
  66. +79 −49 src/helpers/index.js
  67. +0 −17 src/helpers/ipcidr.js
  68. +20 −4 src/helpers/logger.js
  69. +36 −25 src/helpers/permission.js
  70. +0 −106 src/helpers/timed-match/index.js
  71. +0 −15 src/helpers/timed-match/match-proc.js
  72. +1 −1 src/index.js
  73. +32 −55 src/middleware/auth.js
  74. +92 −0 src/middleware/gitops.js
  75. +17 −0 src/middleware/limiter.js
  76. +6 −30 src/middleware/validators.js
  77. +8 −6 src/models/admin.js
  78. +35 −30 src/models/common/index.js
  79. +8 −45 src/models/component.js
  80. +14 −152 src/models/config-strategy.js
  81. +34 −6 src/models/config.js
  82. +21 −8 src/models/domain.js
  83. +1 −1 src/models/environment.js
  84. +11 −4 src/models/group-config.js
  85. +0 −16 src/models/metric.js
  86. +7 −1 src/models/permission.js
  87. +11 −9 src/models/slack.js
  88. +28 −13 src/models/slack_ticket.js
  89. +4 −4 src/models/team.js
  90. +34 −14 src/routers/admin.js
  91. +0 −85 src/routers/client-api.js
  92. +29 −0 src/routers/common/index.js
  93. +5 −5 src/routers/component.js
  94. +13 −12 src/routers/config-strategy.js
  95. +45 −18 src/routers/config.js
  96. +40 −11 src/routers/domain.js
  97. +5 −6 src/routers/environment.js
  98. +167 −0 src/routers/gitops.js
  99. +24 −14 src/routers/group-config.js
  100. +4 −4 src/routers/metric.js
  101. +26 −15 src/routers/permission.js
  102. +37 −39 src/routers/slack.js
  103. +15 −12 src/routers/team.js
  104. +12 −11 src/services/admin.js
  105. +10 −3 src/services/common.js
  106. +13 −5 src/services/component.js
  107. +44 −22 src/services/config-strategy.js
  108. +128 −45 src/services/config.js
  109. +42 −16 src/services/domain.js
  110. +22 −14 src/services/environment.js
  111. +86 −0 src/services/gitops/index.js
  112. +81 −0 src/services/gitops/push-changed.js
  113. +72 −0 src/services/gitops/push-deleted.js
  114. +121 −0 src/services/gitops/push-new.js
  115. +49 −23 src/services/group-config.js
  116. +6 −7 src/services/history.js
  117. +10 −11 src/services/metric.js
  118. +22 −14 src/services/permission.js
  119. +141 −76 src/services/slack.js
  120. +22 −22 src/services/team.js
  121. +1 −7 src/start.js
  122. +166 −53 tests/admin.test.js
  123. +37 −0 tests/app.test.js
  124. +0 −108 tests/client-api-payload.test.js
  125. +226 −746 tests/client-api.test.js
  126. +9 −9 tests/component.test.js
  127. +541 −0 tests/config-relay.test.js
  128. +32 −26 tests/config-strategy.test.js
  129. +118 −269 tests/config.test.js
  130. +47 −19 tests/domain.test.js
  131. +15 −15 tests/environment.test.js
  132. +47 −6 tests/fixtures/db_api.js
  133. +35 −11 tests/fixtures/db_client.js
  134. +5 −7 tests/fixtures/db_client_payload.js
  135. +3 −2 tests/fixtures/db_factory.js
  136. +4 −4 tests/fixtures/db_metrics.js
  137. +42 −2 tests/fixtures/db_team_permission.js
  138. +808 −0 tests/gitops-account.test.js
  139. +1,040 −0 tests/gitops.test.js
  140. +92 −28 tests/graphql-utils/index.js
  141. +20 −20 tests/group-config.test.js
  142. +17 −1 tests/metric.test.js
  143. +237 −0 tests/model/common-index.test.js
  144. +84 −11 tests/permission.test.js
  145. +0 −325 tests/relay.test.js
  146. +22 −2 tests/services/history.test.js
  147. +384 −110 tests/slack.test.js
  148. +168 −81 tests/team.test.js
  149. +127 −0 tests/unit-test/cache.test.js
  150. +0 −661 tests/unit-test/config-strategy.test.js
  151. +1 −1 tests/unit-test/helpers.test.js
  152. +50 −0 tests/unit-test/helpers/logger.test.js
  153. +55 −0 tests/unit-test/routers/common-index.test.js
  154. +52 −31 tests/unit-test/switcher-api-facade.test.js
  155. +0 −90 tests/unit-test/try-match.test.js
  156. +198 −63 tests/unit-test/verify-ownership.test.js
20 changes: 14 additions & 6 deletions .env-cmdrc-template
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"test": {
"NODE_OPTIONS": "--experimental-vm-modules",
"ENV": "TEST",
"PORT": "3000",
"SSL_CERT": "",
"SSL_KEY": "",
"SENDGRID_API_KEY": "SG.MOCK_API_TOKEN",
"SENDGRID_MAIL_FROM": "MOCK_MAIL_FROM",
"SENDGRID_CONFIRMATION_TEMPLATE": "SG.CONFIRMATION_TEMPLATE",
"SENDGRID_RECOVERY_TEMPLATE": "SG.RECOVERY_TEMPLATE",
"MONGODB_URI": "MOCK_MONGODB_URI",
"RESOURCE_SECRECT": "[MOCK_RESOURCE_SECRECT]",
"RESOURCE_SECRET": "[MOCK_RESOURCE_SECRET]",
"JWT_SECRET": "MOCK_JWT_SECRET",
"JWT_CLIENT_TOKEN_EXP_TIME": "5m",
"JWT_ADMIN_TOKEN_RENEW_INTERVAL": "5m",
"MAX_STRATEGY_OPERATION": 100,
"RELAY_BYPASS_HTTPS": true,
"RELAY_BYPASS_VERIFICATION": true,
"PERMISSION_CACHE_ACTIVATED": true,
"HISTORY_ACTIVATED": true,
"METRICS_ACTIVATED": true,
"METRICS_MAX_PAGE": 50,
"REGEX_MAX_TIMEOUT": 3000,
"REGEX_MAX_BLACLIST": 50,
"MAX_REQUEST_PER_MINUTE": 1000,
"GIT_OAUTH_CLIENT_ID": "MOCK_GIT_OAUTH_CLIENT_ID",
"GIT_OAUTH_SECRET": "MOCK_GIT_OAUTH_SECRET",
"BITBUCKET_OAUTH_CLIENT_ID": "MOCK_BITBUCKET_OAUTH_CLIENT_ID",
@@ -25,12 +28,17 @@
"GOOGLE_SKIP_AUTH": true,

"SWITCHER_API_LOGGER": false,
"SWITCHER_API_LOGGER_LEVEL": "debug",

"SWITCHER_API_ENABLE": false,
"SWITCHER_API_THROTTLE": 5000,
"SWITCHER_API_URL": "http://localhost:3000",
"SWITCHER_API_KEY": "MOCK_SWITCHER_API_KEY",
"SWITCHER_API_DOMAIN": "MOCK_SWITCHER_API_DOMAIN",
"SWITCHER_API_ENVIRONMENT": "default",

"SWITCHER_SLACK_JWT_SECRET": "MOCK_SWITCHER_SLACK_JWT_SECRET"
"SWITCHER_SLACK_JWT_SECRET": "MOCK_SWITCHER_SLACK_JWT_SECRET",
"SWITCHER_GITOPS_JWT_SECRET": "MOCK_SWITCHER_GITOPS_JWT_SECRET",
"SWITCHER_GITOPS_URL": "http://localhost:8000"
}
}
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

4 changes: 1 addition & 3 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# These are supported funding model platforms

patreon: switcherapi
ko_fi: petruki
custom: ['https://www.paypal.com/donate/?business=A5R6K3JAD8SW4&no_recurring=0&item_name=Thank+you+for+supporting+the+Open+Source+Community&currency_code=CAD']
github: [petruki]
6 changes: 2 additions & 4 deletions .github/ISSUE_TEMPLATE/patch_report.md
Original file line number Diff line number Diff line change
@@ -11,12 +11,10 @@ assignees: petruki
A clear and concise description of why the patch is needed.

**Current dependency**
- **Name**:
- **Version**:
- **name@version**:

**Optional - Remediation**
- **Name**:
- **Version**:
- **name@version**:

**Additional context**
Links or documentation to the vulnerability or dependency update.
63 changes: 34 additions & 29 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -15,45 +15,48 @@ jobs:

steps:
- name: Git checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node.js 18.x
uses: actions/setup-node@v3
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 22.x

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.9.0
uses: supercharge/mongodb-github-action@1.11.0
with:
mongodb-version: 6.0
mongodb-version: 8.0

- name: Install dependencies
run: npm install
run: npm ci

- name: Lint
run: npm run lint

- name: Run tests
run: npm test
env:
NODE_OPTIONS: "--experimental-vm-modules"
MONGODB_URI: mongodb://127.0.0.1:27017/switcher-api-test
HISTORY_ACTIVATED: true
JWT_ADMIN_TOKEN_RENEW_INTERVAL: 5m
JWT_CLIENT_TOKEN_EXP_TIME: 5m
JWT_SECRET: ${{ secrets.JWT_SECRET }}
SWITCHER_SLACK_JWT_SECRET: ${{ secrets.SWITCHER_SLACK_JWT_SECRET }}
SWITCHER_GITOPS_JWT_SECRET: ${{ secrets.SWITCHER_GITOPS_JWT_SECRET }}
GOOGLE_RECAPTCHA_SECRET: ${{ secrets.GOOGLE_RECAPTCHA_SECRET }}
GOOGLE_SKIP_AUTH: false
MAX_STRATEGY_OPERATION: 100
METRICS_ACTIVATED: true
RELAY_BYPASS_HTTPS: true
RELAY_BYPASS_VERIFICATION: true
PERMISSION_CACHE_ACTIVATED: true
METRICS_MAX_PAGE: 50
SWITCHER_API_ENABLE: false
SWITCHER_API_LOGGER: false

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v1.8
uses: sonarsource/sonarqube-scan-action@v4.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -69,20 +72,20 @@ jobs:

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64
@@ -95,28 +98,30 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'master'

- name: Checkout Kustomize
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.ARGOCD_PAT }}
repository: switcherapi/switcher-deployment
ref: master

- name: Set Image
uses: stefanprodan/kube-tools@v1
- name: Set up arkade-get
uses: alexellis/arkade-get@master
with:
kubectl: 1.24.0
kustomize: 4.5.4
command: |
cd switcher-api/base
echo RELEASE_TIME=`date` > environment-properties.env
kustomize edit set image trackerforce/switcher-api:latest=trackerforce/switcher-api@${{ needs.docker.outputs.digest }}
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git add .
git commit -m "[argocd] switcher-api: ${{ needs.docker.outputs.digest }}"
git push
kubectl: latest
kustomize: latest

- name: Update GitOps repository
run: |
cd switcher-api/base
echo RELEASE_TIME=`date` > environment-properties.env
kustomize edit set image trackerforce/switcher-api:latest=trackerforce/switcher-api@${{ needs.docker.outputs.digest }}
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
git add .
git commit -m "[argocd] switcher-api: ${{ needs.docker.outputs.digest }}"
git push
97 changes: 97 additions & 0 deletions .github/workflows/re-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Re-release CI
run-name: Re-releasing - ${{ github.event.inputs.tag }} by @${{ github.actor }}

on:
workflow_dispatch:
inputs:
tag:
description: 'Tag'
required: true

jobs:
build-test:
name: Build & Test
runs-on: ubuntu-latest

steps:
- name: Git checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.tag }}

- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.11.0
with:
mongodb-version: 8.0

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Run tests
run: npm test
env:
NODE_OPTIONS: "--experimental-vm-modules"
MONGODB_URI: mongodb://127.0.0.1:27017/switcher-api-test
HISTORY_ACTIVATED: true
JWT_ADMIN_TOKEN_RENEW_INTERVAL: 5m
JWT_SECRET: ${{ secrets.JWT_SECRET }}
SWITCHER_SLACK_JWT_SECRET: ${{ secrets.SWITCHER_SLACK_JWT_SECRET }}
SWITCHER_GITOPS_JWT_SECRET: ${{ secrets.SWITCHER_GITOPS_JWT_SECRET }}
GOOGLE_RECAPTCHA_SECRET: ${{ secrets.GOOGLE_RECAPTCHA_SECRET }}
GOOGLE_SKIP_AUTH: false
MAX_STRATEGY_OPERATION: 100
RELAY_BYPASS_HTTPS: true
RELAY_BYPASS_VERIFICATION: true
PERMISSION_CACHE_ACTIVATED: true
METRICS_MAX_PAGE: 50
SWITCHER_API_ENABLE: false
SWITCHER_API_LOGGER: false

docker:
name: Publish Docker Image
needs: [ build-test ]
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.tag }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: trackerforce/switcher-api
tags: ${{ github.event.inputs.tag }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Loading