-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from snyk-tech-services/feat/delete-projects
feat: delete created projects to clean up tests
- Loading branch information
Showing
8 changed files
with
177 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ dist | |
package-lock.json | ||
yarn.lock | ||
.eslintcache | ||
local.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getSnykHost(): string { | ||
return process.env.SNYK_HOST || 'https://snyk.io'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './import'; | ||
export * from './poll-import'; | ||
export * from './project'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'source-map-support/register'; | ||
import * as needle from 'needle'; | ||
import * as debugLib from 'debug'; | ||
import { getApiToken } from '../get-api-token'; | ||
import { getSnykHost } from '../get-snyk-host'; | ||
const debug = debugLib('snyk:api-import'); | ||
|
||
export async function deleteProjects( | ||
orgId: string, | ||
projects: string[], | ||
): Promise<boolean> { | ||
const apiToken = getApiToken(); | ||
if (!(orgId && projects)) { | ||
throw new Error( | ||
`Missing required parameters. Please ensure you have provided: orgId & projectIds.`, | ||
); | ||
} | ||
debug('Deleting projectIds:', projects.join(', ')); | ||
|
||
try { | ||
const SNYK_HOST = getSnykHost(); | ||
const body = { | ||
projects, | ||
}; | ||
const res = await needle( | ||
'post', | ||
`${SNYK_HOST}/api/v1/org/${orgId}/projects/bulk-delete`, | ||
body, | ||
{ | ||
json: true, | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
read_timeout: 30000, | ||
headers: { | ||
'content-type': 'application/json', | ||
Authorization: `token ${apiToken}`, | ||
}, | ||
}, | ||
); | ||
if (res.statusCode !== 200) { | ||
throw new Error( | ||
`Expected a 200 response, instead received statusCode: ${ | ||
res.statusCode | ||
}, | ||
body: ${JSON.stringify(res.body)}`, | ||
); | ||
} | ||
return res.body; | ||
} catch (error) { | ||
debug('Could not delete project:', error.message || error); | ||
const err: { | ||
message?: string | undefined; | ||
innerError?: string; | ||
} = new Error('Could not delete project'); | ||
err.innerError = error; | ||
throw err; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { Url } from 'url'; | ||
|
||
export interface ImportTarget { | ||
orgId: string; | ||
integrationId: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters