Skip to content

Commit

Permalink
feat: convert ruby to send back multi project result
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Oct 7, 2019
1 parent 54169eb commit 0127e0a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function webAuth(via: AuthCliCommands) {

// validate that via comes from our code, and not from user & CLI
if (redirects[via]) {
urlStr += '&redirectUri=' + new Buffer(redirects[via]).toString('base64');
urlStr += '&redirectUri=' + Buffer.from(redirects[via]).toString('base64');
}

const msg =
Expand Down
35 changes: 19 additions & 16 deletions src/lib/plugins/rubygems/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import { inspectors, Spec } from './inspectors';
import * as types from '../types';
import { MissingTargetFileError } from '../../errors/missing-targetfile-error';

interface RubyGemsInspectResult extends types.InspectResult {
package: {
name: string;
targetFile: string;
files: any;
};
}
import gemfileLockToDependencies = require('./gemfile-lock-to-dependencies');
import _ = require('lodash');
import { MultiProjectResult } from '@snyk/cli-interface/legacy/plugin';

export async function inspect(
root: string,
targetFile: string,
): Promise<RubyGemsInspectResult> {
): Promise<MultiProjectResult> {
if (!targetFile) {
throw MissingTargetFileError(root);
}
const specs = await gatherSpecs(root, targetFile);
const gemfileLockBase64 = _.get(specs, 'files.gemfileLock.contents');
const gemfileLockContents = Buffer.from(
gemfileLockBase64,
'base64',
).toString();
const dependencies = gemfileLockToDependencies(gemfileLockContents);

return {
plugin: {
name: 'bundled:rubygems',
runtime: 'unknown',
},
// TODO: must be a depTree!
package: {
name: specs.packageName,
targetFile: specs.targetFile,
files: specs.files,
},
scannedProjects: [
{
depTree: {
name: specs.packageName,
targetFile: specs.targetFile,
dependencies,
},
},
],
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/plugins/rubygems/inspectors/try-get-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function tryGetSpec(
if (await fs.exists(filePath)) {
return {
name,
contents: new Buffer(await fs.readFile(filePath)).toString('base64'),
contents: Buffer.from(await fs.readFile(filePath)).toString('base64'),
};
}
return null;
Expand Down
9 changes: 0 additions & 9 deletions src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,6 @@ async function assembleLocalPayloads(
}
}

if (_.get(pkg, 'files.gemfileLock.contents')) {
const gemfileLockBase64 = pkg.files.gemfileLock.contents;
const gemfileLockContents = Buffer.from(
gemfileLockBase64,
'base64',
).toString();
pkg.dependencies = gemfileLockToDependencies(gemfileLockContents);
}

let policyLocations: string[] = [options['policy-path'] || root];
if (options.docker) {
policyLocations = policyLocations.filter((loc) => {
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4311,7 +4311,7 @@ function chdirWorkspaces(subdir: string = '') {
}

function decode64(str) {
return new Buffer(str, 'base64').toString('utf8');
return Buffer.from(str, 'base64').toString('utf8');
}

// fixture can be fixture path or object
Expand Down

0 comments on commit 0127e0a

Please sign in to comment.