New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@leaflink/oast

Package Overview
Dependencies
Maintainers
8
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leaflink/oast - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

src/libs/utils/global-transform.js

3

package.json
{
"name": "@leaflink/oast",
"version": "1.2.0",
"version": "1.3.0",
"description": "",

@@ -60,4 +60,5 @@ "main": "index.js",

"module-alias": "^2.2.2",
"octokit": "^2.0.9",
"yup": "^0.32.11"
}
}

@@ -6,2 +6,3 @@ const { loadYamlToJsonWithRequest, writeObjectAsYamlToPath } = require('@src/libs/utils/file-io');

const { performTransformations } = require('@src/transformer/transformer');
const { fetchGlobalTransforms } = require('@src/libs/utils/global-transform');
// load env

@@ -11,5 +12,6 @@ require('dotenv').config();

module.exports.handleCIIngestion = async (args) => {
const { changedFiles, origin, branch, token, outputPath } = this.checkAndSetIngestionCIArgs(args);
// get processed arg values
const { changedFiles, origin, branch, token, outputPath, configFolderName, specFolderName, applyGlobalTransforms } = this.checkAndSetIngestionCIArgs(args);
const configurationUrls = this.processFilesChanged(changedFiles, origin, branch);
const configurationUrls = this.processFilesChanged(changedFiles, origin, branch, configFolderName);
// TODO: implement flow for handling multiple configs

@@ -21,8 +23,17 @@ // processFilesChanged returns an array to support future multiple configs, for now we just pop()

// Get the spec github raw Url using source from the config
const { url, fileName } = buildSpecUrlFromConfig(configurationObject, configurationUrl, args.b || args.branch);
const { url, fileName } = buildSpecUrlFromConfig(configurationObject, configurationUrl, args.b || args.branch, specFolderName);
// load the spec yaml into JSON
const specObject = await loadYamlToJsonWithRequest(url, token);
const transformedSpec = await performTransformations(configurationObject, specObject);
let transformedSpec = await performTransformations(configurationObject, specObject);
// fetch and apply the global transforms
if (applyGlobalTransforms) {
outputLog.info('Fetching and applying global-transformation files...');
// fetch the global config files
const globalTransformConfigCollection = await fetchGlobalTransforms('/configurations', token);
// apply them to the spec
transformedSpec = await performTransformations(globalTransformConfigCollection, transformedSpec);
}
// write the output to outputs/ using the filename
await writeObjectAsYamlToPath(transformedSpec, (outputPath + fileName));

@@ -60,3 +71,11 @@ };

};
let applyGlobalTransforms = false;
if (args.g || args.global) {
applyGlobalTransforms = true;
}
// optional spec and config folder override
const specFolderName = args.sf || args.specFolder || 'specfiles';
const configFolderName = args.cf || args.configFolder || 'configurations';
const changedFiles = args.f || args.files;

@@ -70,3 +89,3 @@ const origin = args.or || args.origin;

return { changedFiles, origin, branch, token, outputPath };
return { changedFiles, origin, branch, token, outputPath, specFolderName, configFolderName, applyGlobalTransforms };
};

@@ -79,5 +98,6 @@

* @param {string} branch current branch or tag
* @param {string} configFolderName override the default configFolderName
* @returns Array of github raw URLs
*/
module.exports.processFilesChanged = (changedFiles, origin, branch = 'main') => {
module.exports.processFilesChanged = (changedFiles, origin, branch = 'main', configFolderName) => {
const changedFilesArr = changedFiles.split(',');

@@ -88,3 +108,3 @@ const configurationURLs = [];

if (filePath.includes('.specfile.')) {
const { path } = buildConfigPathFromSpecPath(filePath);
const { path } = buildConfigPathFromSpecPath(filePath, configFolderName);
filePath = path;

@@ -91,0 +111,0 @@ }

@@ -14,3 +14,3 @@ const githubRawUrl = 'https://raw.githubusercontent.com';

const specPathArray = specPath.split('/');
// change preceding folder to configuration folder
// change preceding folder to the folderName
specPathArray[specPathArray.length - 2] = folderName;

@@ -31,4 +31,4 @@ // change extension to configuration type

*/
module.exports.buildConfigPathFromSpecPath = (specPath) => {
return replaceFolderAndExtensionOnPath(specPath, 'configurations', 'config', 'specfile');
module.exports.buildConfigPathFromSpecPath = (specPath, configFolderName) => {
return replaceFolderAndExtensionOnPath(specPath, configFolderName, 'config', 'specfile');
};

@@ -41,4 +41,4 @@

*/
module.exports.buildSpecPathFromConfigPath = (specPath) => {
return replaceFolderAndExtensionOnPath(specPath, 'specfiles', 'specfile', 'config');
module.exports.buildSpecPathFromConfigPath = (specPath, specFolderName) => {
return replaceFolderAndExtensionOnPath(specPath, specFolderName, 'specfile', 'config');
};

@@ -51,9 +51,11 @@

* @param {string} branch branch or tag of origin request from github
* @param {string} specFolderName name of the spec folder
* @returns object containing the github url, and fileName used for output
*/
module.exports.buildSpecUrlFromConfig = (config, configURL, branch) => {
module.exports.buildSpecUrlFromConfig = (config, configURL, branch, specFolderName) => {
console.log(specFolderName);
// split off branch, and take last half of url, this is the path for config
const [rootRawURL, configPath] = configURL.split(branch);
// build spec path from config path conversion
let { path, fileName } = this.buildSpecPathFromConfigPath(configPath);
let { path, fileName } = this.buildSpecPathFromConfigPath(configPath, specFolderName);
// remove extension from filename, this will be the output name

@@ -60,0 +62,0 @@ fileName = fileName.replace('.config', '');

@@ -5,5 +5,7 @@

const transformer = require('@src/transformer/transformer');
const fetchTransforms = require('@src/libs/utils/global-transform');
jest.mock('../../libs/utils/file-io');
jest.mock('../../transformer/transformer');
jest.mock('../../libs/utils/global-transform');
describe('Ingest-CI tests', () => {

@@ -13,3 +15,2 @@ const processFilesSpy = jest.spyOn(ingestCI, 'processFilesChanged');

const writeFileSpy = jest.spyOn(fileIo, 'writeObjectAsYamlToPath');
test('Changed files results in github raw urls', () => {

@@ -19,3 +20,3 @@ const changedFiles = 'oas/specfiles/spec.specfile.yaml,/configuration/test.configuration.yaml';

const branch = 'main';
expect(ingestCI.processFilesChanged(changedFiles, origin, branch)).toStrictEqual(['https://raw.githubusercontent.com/leaflink/main/oas/configurations/spec.config.yaml', 'https://raw.githubusercontent.com/leaflink/main//configuration/test.configuration.yaml']);
expect(ingestCI.processFilesChanged(changedFiles, origin, branch, 'configurations')).toStrictEqual(['https://raw.githubusercontent.com/leaflink/main/oas/configurations/spec.config.yaml', 'https://raw.githubusercontent.com/leaflink/main//configuration/test.configuration.yaml']);
});

@@ -44,3 +45,6 @@

transformer.performTransformations.mockResolvedValueOnce({});
await ingestCI.handleCIIngestion({ _: ['ingest-ci'], b: 'main', f: 'specfiles/spec.specfile.yaml', or: 'leaflink', t: 'token' });
expect(transformer.performTransformations).toHaveBeenCalled();
expect(processFilesSpy).toHaveBeenCalled();

@@ -50,2 +54,15 @@ expect(checkArgSpy).toHaveBeenCalled();

});
test('HandleCIIngestion processes correctly with global flag', async () => {
fileIo.loadYamlToJsonWithRequest.mockResolvedValueOnce({ source: { location: { git: { branch: 'main' } } } });
transformer.performTransformations.mockResolvedValueOnce({});
fetchTransforms.fetchGlobalTransforms.mockResolvedValueOnce([{}]);
await ingestCI.handleCIIngestion({ _: ['ingest-ci'], b: 'main', f: 'specfiles/spec.specfile.yaml', or: 'leaflink', t: 'token', g: true });
expect(transformer.performTransformations).toHaveBeenCalledTimes(3);
expect(fetchTransforms.fetchGlobalTransforms).toHaveBeenCalled();
expect(processFilesSpy).toHaveBeenCalled();
expect(checkArgSpy).toHaveBeenCalled();
expect(writeFileSpy).toHaveBeenCalled();
});
});

@@ -9,7 +9,7 @@ const { buildGithubRawPath, buildConfigPathFromSpecPath, buildSpecPathFromConfigPath, buildSpecUrlFromConfig } = require('@src/libs/utils/github-paths');

test('Converts spec to config path', () => {
expect(buildConfigPathFromSpecPath('/specfiles/spec.specfile.yaml')).toStrictEqual({ fileName: 'spec.specfile.yaml', path: '/configurations/spec.config.yaml' });
expect(buildConfigPathFromSpecPath('/specfiles/spec.specfile.yaml', 'configurations')).toStrictEqual({ fileName: 'spec.specfile.yaml', path: '/configurations/spec.config.yaml' });
});
test('Converts config to spec path', () => {
expect(buildSpecPathFromConfigPath('/configurations/spec.config.yaml')).toStrictEqual({ fileName: 'spec.config.yaml', path: '/specfiles/spec.specfile.yaml' });
expect(buildSpecPathFromConfigPath('/configurations/spec.config.yaml', 'specfiles')).toStrictEqual({ fileName: 'spec.config.yaml', path: '/specfiles/spec.specfile.yaml' });
});

@@ -28,4 +28,4 @@

const configURL = 'https://raw.githubusercontent.com/leaflink/main/configurations/spec.config.yaml';
expect(buildSpecUrlFromConfig(config, configURL, 'main')).toStrictEqual({ fileName: 'spec.yaml', url: 'https://raw.githubusercontent.com/leaflink/main/specfiles/spec.specfile.yaml' });
expect(buildSpecUrlFromConfig(config, configURL, 'main', 'specfiles')).toStrictEqual({ fileName: 'spec.yaml', url: 'https://raw.githubusercontent.com/leaflink/main/specfiles/spec.specfile.yaml' });
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc