diff --git a/.github/ISSUE_TEMPLATE/patch_report.md b/.github/ISSUE_TEMPLATE/patch_report.md index a227bb2..2f09776 100644 --- a/.github/ISSUE_TEMPLATE/patch_report.md +++ b/.github/ISSUE_TEMPLATE/patch_report.md @@ -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. diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 1725cc4..7f8fd51 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Git checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 @@ -25,7 +25,7 @@ jobs: node-version: 20.x - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.9.0 + uses: supercharge/mongodb-github-action@1.10.0 with: mongodb-version: 6.0 @@ -65,20 +65,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@v5 with: push: true platforms: linux/amd64,linux/arm64 @@ -91,28 +91,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-resolver-node/base - echo RELEASE_TIME=`date` > environment-properties.env - kustomize edit set image trackerforce/switcher-resolver-node:latest=trackerforce/switcher-resolver-node@${{ 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-resolver-node: ${{ needs.docker.outputs.digest }}" - git push \ No newline at end of file + kubectl: latest + kustomize: latest + + - name: Update GitOps repository + run: | + cd switcher-resolver-node/base + echo RELEASE_TIME=`date` > environment-properties.env + kustomize edit set image trackerforce/switcher-resolver-node:latest=trackerforce/switcher-resolver-node@${{ 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-resolver-node: ${{ needs.docker.outputs.digest }}" + git push \ No newline at end of file diff --git a/.github/workflows/re-release.yml b/.github/workflows/re-release.yml new file mode 100644 index 0000000..95bc35e --- /dev/null +++ b/.github/workflows/re-release.yml @@ -0,0 +1,90 @@ +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 20.x + uses: actions/setup-node@v3 + with: + node-version: 20.x + + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.10.0 + with: + mongodb-version: 6.0 + + - name: Install dependencies + run: npm install + + - name: Lint + run: npm run lint + + - name: Run tests + run: npm test + env: + MONGODB_URI: mongodb://127.0.0.1:27017/switcher-api-test + JWT_CLIENT_TOKEN_EXP_TIME: 5m + JWT_SECRET: ${{ secrets.JWT_SECRET }} + RELAY_BYPASS_HTTPS: true + RELAY_BYPASS_VERIFICATION: true + METRICS_ACTIVATED: true + MAX_REQUEST_PER_MINUTE: 0 + 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-resolver-node + 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@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3f76212..2255e81 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,7 +11,9 @@ jobs: steps: - name: Git checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Use Node.js 20.x uses: actions/setup-node@v3 @@ -19,7 +21,7 @@ jobs: node-version: 20.x - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.9.0 + uses: supercharge/mongodb-github-action@1.10.0 with: mongodb-version: 6.0 @@ -49,28 +51,28 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: trackerforce/switcher-resolver-node - 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 - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: context: . push: true diff --git a/package.json b/package.json index c6ac178..ea9180d 100644 --- a/package.json +++ b/package.json @@ -41,23 +41,23 @@ "jsonwebtoken": "^9.0.2", "moment": "^2.29.4", "mongodb": "^6.3.0", - "mongoose": "^8.0.2", - "pino": "^8.16.2", - "pino-pretty": "^10.2.3", + "mongoose": "^8.0.3", + "pino": "^8.17.1", + "pino-pretty": "^10.3.0", "swagger-ui-express": "^5.0.0", "switcher-client": "^3.2.0", "validator": "^13.11.0" }, "devDependencies": { "@babel/cli": "^7.23.4", - "@babel/core": "^7.23.5", + "@babel/core": "^7.23.6", "@babel/node": "^7.22.19", - "@babel/preset-env": "^7.23.5", + "@babel/preset-env": "^7.23.6", "@babel/register": "^7.22.15", "babel-jest": "^29.7.0", "babel-polyfill": "^6.26.0", "env-cmd": "^10.1.0", - "eslint": "^8.55.0", + "eslint": "^8.56.0", "jest": "^29.7.0", "jest-sonar-reporter": "^2.0.0", "node-notifier": "^10.0.1", diff --git a/src/api-docs/paths/path-client.js b/src/api-docs/paths/path-client.js index 66b9e08..d8800b4 100644 --- a/src/api-docs/paths/path-client.js +++ b/src/api-docs/paths/path-client.js @@ -9,10 +9,10 @@ export default { description: 'Execute criteria query against the API settings', security: [{ appAuth: [] }], parameters: [ - queryParameter('key', 'string', 'Switcher Key', true), - queryParameter('showReason', 'boolean', 'Show criteria execution reason (default: true)', false), - queryParameter('showStrategy', 'boolean', 'Show criteria execution strategy (default: true)', false), - queryParameter('bypassMetric', 'boolean', 'Bypass metric check (default: true)', false) + queryParameter('key', 'Switcher Key', true, 'string'), + queryParameter('showReason', 'Show criteria execution reason (default: true)', false, 'boolean'), + queryParameter('showStrategy', 'Show criteria execution strategy (default: true)', false, 'boolean'), + queryParameter('bypassMetric', 'Bypass metric check (default: true)', false, 'boolean') ], requestBody: { content: { @@ -56,7 +56,7 @@ export default { }, strategies: { type: 'array', - items: configStrategy + items: configStrategy.ConfigStrategy } } } @@ -66,13 +66,13 @@ export default { } } }, - '/criteria/snapshot_check/:version': { + '/criteria/snapshot_check/{version}': { get: { tags: ['Client API'], description: 'Check if snapshot version is up to date', security: [{ appAuth: [] }], parameters: [ - pathParameter('version', 'string', 'Snapshot version', true) + pathParameter('version', 'Snapshot version', true) ], responses: { 200: { diff --git a/src/api-docs/schemas/config-strategy.js b/src/api-docs/schemas/config-strategy.js index 076e81b..9217694 100644 --- a/src/api-docs/schemas/config-strategy.js +++ b/src/api-docs/schemas/config-strategy.js @@ -1,6 +1,6 @@ import { OperationsType, StrategiesType } from '../../models/config-strategy'; -export const configStrategy = { +const configStrategy = { type: 'object', properties: { _id: { @@ -22,9 +22,12 @@ export const configStrategy = { type: 'string', enum: Object.values(StrategiesType) }, - values: [{ - type: 'string' - }], + values: { + type: 'array', + items: { + type: 'string' + } + }, operation: { type: 'string', enum: Object.values(OperationsType) @@ -40,14 +43,14 @@ export const configStrategy = { format: 'uuid' }, owner: { - type: 'uuid', + type: 'string', description: 'The owner id of the config strategy' }, admin: { type: 'object', properties: { _id: { - type: 'uuid', + type: 'string', description: 'The unique identifier of the admin' }, name: { diff --git a/src/api-docs/swagger-document.js b/src/api-docs/swagger-document.js index b7457c6..90e4f55 100644 --- a/src/api-docs/swagger-document.js +++ b/src/api-docs/swagger-document.js @@ -1,7 +1,6 @@ import pathClient from './paths/path-client'; import { commonSchema } from './schemas/common'; -import configStrategySchema from './schemas/config-strategy'; import info from './swagger-info'; export default { @@ -17,14 +16,11 @@ export default { description: 'Cloud API' } ], - consumes: ['application/json'], - produces: ['application/json'], components: { securitySchemes: { appAuth: { type: 'http', scheme: 'bearer', - name: 'JWT' }, apiKey: { type: 'apiKey', @@ -33,8 +29,7 @@ export default { } }, schemas: { - ...commonSchema, - ...configStrategySchema + ...commonSchema } }, paths: {