From 03a750c800fe380193c8eccc9e8c3b68c0a85fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Louren=C3=A7o?= Date: Sat, 13 Jul 2024 22:40:43 +0100 Subject: [PATCH 1/2] refactor: default SNYK_API to api.snyk.io/v1 `snyk.io/api/v1` is the deprecated way to access v1 endpoints. The standard way is now `api.snyk.io/v1`. --- docs/import.md | 2 +- docs/sync.md | 2 +- src/lib/get-snyk-host.ts | 2 +- test/lib/fixtures/non-empty.logx | 2 +- test/scripts/__mocks__/snyk-request-manager.ts | 2 +- test/scripts/polling.test.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/import.md b/docs/import.md index 25bdc894..09895dea 100644 --- a/docs/import.md +++ b/docs/import.md @@ -190,7 +190,7 @@ If you have any tests ot fixtures that should be ignored, please set the `exclus - `SNYK_TOKEN` - your [Snyk api token](https://app.snyk.io/account) - `SNYK_LOG_PATH` - the path to folder where all logs should be saved,it is recommended creating a dedicated logs folder per import you have running. (Note: all logs will append) - `CONCURRENT_IMPORTS` (optional) defaults to 15 repos at a time, which is the recommended amount to import at once as a max. Just 1 repo may have many projects inside which can trigger a many files at once to be requested from the user's SCM instance and some may have rate limiting in place. This script aims to help reduce the risk of hitting a rate limit. -- `SNYK_API` (optional) defaults to `https://snyk.io/api/v1` +- `SNYK_API` (optional) defaults to `https://api.snyk.io/v1` ## 3. Download & run diff --git a/docs/sync.md b/docs/sync.md index d084f1f3..5034b9d2 100644 --- a/docs/sync.md +++ b/docs/sync.md @@ -92,7 +92,7 @@ The command will produce detailed logs for projects that were `updated` and thos - `SNYK_TOKEN` - your [Snyk api token](https://app.snyk.io/account) - `SNYK_LOG_PATH` - the path to folder where all logs should be saved,it is recommended creating a dedicated logs folder per import you have running. (Note: all logs will append) -- `SNYK_API` (optional) defaults to `https://snyk.io/api/v1` +- `SNYK_API` (optional) defaults to `https://api.snyk.io/v1` - `GITHUB_TOKEN` - SCM token that has read level or similar permissions to see information about repos like default branch & can list files in a repo ## 2. Download & run diff --git a/src/lib/get-snyk-host.ts b/src/lib/get-snyk-host.ts index 33ceac33..53f0f2e3 100644 --- a/src/lib/get-snyk-host.ts +++ b/src/lib/get-snyk-host.ts @@ -1,3 +1,3 @@ export function getSnykHost(): string { - return process.env.SNYK_API || 'https://snyk.io/api/v1'; + return process.env.SNYK_API || 'https://api.snyk.io/v1'; } diff --git a/test/lib/fixtures/non-empty.logx b/test/lib/fixtures/non-empty.logx index ad0f6954..17eb9e6e 100644 --- a/test/lib/fixtures/non-empty.logx +++ b/test/lib/fixtures/non-empty.logx @@ -1,2 +1,2 @@ -{"name":"snyk:import-projects-script","hostname":"MacBook-Pro-2.local","pid":46657,"level":30,"target":{"name":"composer-with-vulns","owner":"api-import-circle-test","branch":"master"},"locationUrl":"https://dev.snyk.io/api/v1/org/ORG_ID/integrations/INTEGRATION_ID/import/IMPORT_ID","orgId":"ORG_ID","integrationId":"INTEGRATION_ID","targetId":"ORG_ID:INTEGRATION_ID:composer-with-vulns:api-import-circle-test:master","msg":"Target requested for import","time":"2020-10-26T14:53:20.234Z","v":0} +{"name":"snyk:import-projects-script","hostname":"MacBook-Pro-2.local","pid":46657,"level":30,"target":{"name":"composer-with-vulns","owner":"api-import-circle-test","branch":"master"},"locationUrl":"https://api.dev.snyk.io/v1/org/ORG_ID/integrations/INTEGRATION_ID/import/IMPORT_ID","orgId":"ORG_ID","integrationId":"INTEGRATION_ID","targetId":"ORG_ID:INTEGRATION_ID:composer-with-vulns:api-import-circle-test:master","msg":"Target requested for import","time":"2020-10-26T14:53:20.234Z","v":0} {"name":"snyk:import-projects-script","hostname":"MacBook-Pro-2.local","pid":46657,"level":30,"target":{"name":"composer-with-vulns","owner":"api-import-circle-test","branch":"master"},"locationUrl":null,"orgId":"ORG_ID","integrationId":"INTEGRATION_ID","targetId":"ORG_ID:INTEGRATION_ID:composer-with-vulns:api-import-circle-test:master","msg":"Target exists in Snyk","time":"2020-10-26T14:53:20.234Z","v":0} diff --git a/test/scripts/__mocks__/snyk-request-manager.ts b/test/scripts/__mocks__/snyk-request-manager.ts index 2cfd4863..97111cae 100644 --- a/test/scripts/__mocks__/snyk-request-manager.ts +++ b/test/scripts/__mocks__/snyk-request-manager.ts @@ -20,7 +20,7 @@ export class requestsManager { statusCode: 201, headers: { location: - 'https://app.snyk.io/api/v1/org/ORG-ID/integrations/INTEGRATION-ID/import/IMPORT-ID', + 'https://api.snyk.io/v1/org/ORG-ID/integrations/INTEGRATION-ID/import/IMPORT-ID', }, }); } diff --git a/test/scripts/polling.test.ts b/test/scripts/polling.test.ts index e262adff..64b4107c 100644 --- a/test/scripts/polling.test.ts +++ b/test/scripts/polling.test.ts @@ -49,7 +49,7 @@ describe('Logs failed polls', () => { await new Promise((r) => setTimeout(r, 300)); const failedLog = fs.readFileSync(failedPollsLogName, 'utf8'); expect(failedLog).toMatch( - `"level":50,"orgId":"ORG-ID","locationUrl":"https://app.snyk.io/api/v1/org/ORG-ID/integrations/INTEGRATION-ID/import/IMPORT-ID","errorMessage":{"statusCode":500,"error":{"message":"Error calling Snyk api"}},"msg":"Failed to poll url"`, + `"level":50,"orgId":"ORG-ID","locationUrl":"https://api.snyk.io/v1/org/ORG-ID/integrations/INTEGRATION-ID/import/IMPORT-ID","errorMessage":{"statusCode":500,"error":{"message":"Error calling Snyk api"}},"msg":"Failed to poll url"`, ); }, 240000); }); From af1439506de2d547f9325a97d2035e2347863106 Mon Sep 17 00:00:00 2001 From: Noa-Savransky Date: Tue, 24 Sep 2024 14:43:14 +0300 Subject: [PATCH 2/2] fix: test and vuln --- package.json | 2 +- test/system/orgs:data/gitlab.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index df08ebb2..0ea0f39e 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "bunyan": "1.8.15", "debug": "4.3.4", "lodash": "4.17.21", - "micromatch": "4.0.6", + "micromatch": "4.0.8", "needle": "2.9.1", "p-map": "4.0.0", "parse-link-header": "2.0.0", diff --git a/test/system/orgs:data/gitlab.test.ts b/test/system/orgs:data/gitlab.test.ts index 39f1cc72..4181e5c0 100644 --- a/test/system/orgs:data/gitlab.test.ts +++ b/test/system/orgs:data/gitlab.test.ts @@ -26,7 +26,7 @@ describe('General `snyk-api-import orgs:data <...>`', () => { expect(stderr).toEqual(''); expect(err).toBeNull(); expect(stdout).toMatch( - 'Found 6 group(s). Written the data to file: group-hello-gitlab-orgs.json', + 'Found 7 group(s). Written the data to file: group-hello-gitlab-orgs.json', ); deleteFiles([ path.resolve(__dirname, `group-${groupId}-gitlab-orgs.json`),