From e7d927ac775803f531e36b981157c24a7541d843 Mon Sep 17 00:00:00 2001 From: Patricia Vale Date: Wed, 21 Sep 2022 16:58:39 +0200 Subject: [PATCH 1/2] feat: add org propagation --- src/analysis.ts | 1 + src/bundles.ts | 25 ++++++++++++++++---- src/http.ts | 5 ++++ src/interfaces/analysis-options.interface.ts | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/analysis.ts b/src/analysis.ts index 7696e506..9571aa12 100644 --- a/src/analysis.ts +++ b/src/analysis.ts @@ -98,6 +98,7 @@ export async function analyzeFolders(options: FileAnalysisOptions): Promise { // deepcode ignore PrototypePollution: FP this is an internal code d[f.bundlePath] = f.hash; @@ -91,7 +91,15 @@ interface UpdateRemoteBundleOptions extends ConnectionOptions { export async function uploadRemoteBundle(options: UpdateRemoteBundleOptions): Promise { let uploadedFiles = 0; emitter.uploadBundleProgress(0, options.files.length); - const apiParams = pick(options, ['baseURL', 'sessionToken', 'source', 'bundleHash', 'requestId', 'base64Encoding']); + const apiParams = pick(options, [ + 'baseURL', + 'sessionToken', + 'source', + 'bundleHash', + 'requestId', + 'base64Encoding', + 'org', + ]); const uploadFileChunks = async (bucketFiles: FileInfo[]): Promise => { // Note: we specifically create __new__ isolated bundles here to faster files upload @@ -129,7 +137,7 @@ async function fullfillRemoteBundle(options: FullfillRemoteBundleOptions): Promi // Check remove bundle to make sure no missing files left let attempts = 0; let { remoteBundle } = options; - const connectionOptions = pick(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'base64Encoding']); + const connectionOptions = pick(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'base64Encoding', 'org']); while (remoteBundle.missingFiles.length && attempts < (options.maxAttempts || MAX_UPLOAD_ATTEMPTS)) { const missingFiles = await resolveBundleFiles(options.baseDir, remoteBundle.missingFiles); @@ -156,7 +164,15 @@ interface RemoteBundleFactoryOptions extends PrepareRemoteBundleOptions { export async function remoteBundleFactory(options: RemoteBundleFactoryOptions): Promise { let remoteBundle: RemoteBundle | null = null; - const baseOptions = pick(options, ['baseURL', 'sessionToken', 'source', 'baseDir', 'requestId', 'base64Encoding']); + const baseOptions = pick(options, [ + 'baseURL', + 'sessionToken', + 'source', + 'baseDir', + 'requestId', + 'base64Encoding', + 'org', + ]); const bundleFactory = prepareRemoteBundle(omit(options, ['baseDir'])); for await (const response of bundleFactory) { if (response.type === 'error') { @@ -253,6 +269,7 @@ export async function createBundleFromFolders(options: CreateBundleFromFoldersOp ...pick(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'base64Encoding']), baseDir, files: bundleFiles, + ...(options.analysisContext?.org?.name ? { org: options.analysisContext.org.name } : {}), }; // Create remote bundle diff --git a/src/http.ts b/src/http.ts index 51cd4203..6c32e7bb 100644 --- a/src/http.ts +++ b/src/http.ts @@ -29,6 +29,7 @@ export interface ConnectionOptions { source: string; requestId?: string; base64Encoding: boolean; + org?: string; } // The trick to typecast union type alias @@ -246,6 +247,7 @@ export async function createBundle( source: options.source, ...(options.requestId && { 'snyk-request-id': options.requestId }), ...(base64Encoding ? { 'content-type': 'application/octet-stream', 'content-encoding': 'gzip' } : null), + ...(options.org ? { org: options.org } : {}), }, url: `${options.baseURL}/bundle`, method: 'post', @@ -283,6 +285,7 @@ export async function checkBundle(options: CheckBundleOptions): Promise Date: Fri, 30 Sep 2022 14:26:01 +0200 Subject: [PATCH 2/2] chore: header changes for org --- src/http.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/http.ts b/src/http.ts index 6c32e7bb..5be86ba2 100644 --- a/src/http.ts +++ b/src/http.ts @@ -247,7 +247,7 @@ export async function createBundle( source: options.source, ...(options.requestId && { 'snyk-request-id': options.requestId }), ...(base64Encoding ? { 'content-type': 'application/octet-stream', 'content-encoding': 'gzip' } : null), - ...(options.org ? { org: options.org } : {}), + ...(options.org && { 'snyk-org-name': options.org }), }, url: `${options.baseURL}/bundle`, method: 'post', @@ -285,7 +285,7 @@ export async function checkBundle(options: CheckBundleOptions): Promise