UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

88 lines 7.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NETWORK_FUNCTIONS = void 0; const linter_format_1 = require("../linter-format"); const function_finder_util_1 = require("./function-finder-util"); const linter_tags_1 = require("../linter-tags"); const read_functions_1 = require("../../queries/catalog/dependencies-query/function-info/read-functions"); const logic_1 = require("../../util/logic"); const source_functions_1 = require("../../queries/catalog/dependencies-query/function-info/source-functions"); const write_functions_1 = require("../../queries/catalog/dependencies-query/function-info/write-functions"); const identifier_1 = require("../../dataflow/environments/identifier"); const df_helper_1 = require("../../dataflow/graph/df-helper"); const DefaultFunctionPool = new Map(read_functions_1.ReadFunctions.concat(source_functions_1.SourceFunctions, write_functions_1.WriteFunctions).map(f => [identifier_1.Identifier.toString(identifier_1.Identifier.make(f.name, f.package)), f])); exports.NETWORK_FUNCTIONS = { createSearch: (config) => function_finder_util_1.functionFinderUtil.createSearch(config.fns.map(f => identifier_1.Identifier.is(f) ? f : f.name)), processSearchResult: async (e, c, d) => { const df = await d.dataflow(); const fnPool = new Map([ ...DefaultFunctionPool, ...c.fns.flatMap(f => identifier_1.Identifier.is(f) ? [] : f.info === undefined ? [] : [[identifier_1.Identifier.toString(f.name), { name: identifier_1.Identifier.toString(f.name), ...f.info }]]) ]); const onlyTriggerLookup = new Map(c.fns.flatMap(f => identifier_1.Identifier.is(f) ? [] : [[identifier_1.Identifier.toString(f.name), f.onlyTriggerWithArgument]])); return function_finder_util_1.functionFinderUtil.processSearchResult(e, c, d, async (es) => { const res = []; for (const e of es) { const identifier = df_helper_1.Dataflow.qualify(e.node.info.id, df.graph, true) ?? (e.node.lexeme !== undefined ? identifier_1.Identifier.parse(e.node.lexeme) : undefined); if (identifier === undefined) { continue; } // we allow onlyTriggerLookup to contain non-namespaced functions const requireValue = onlyTriggerLookup.get(identifier_1.Identifier.toString(identifier)) ?? onlyTriggerLookup.get(identifier_1.Identifier.getName(identifier)); const val = await function_finder_util_1.functionFinderUtil.requireArgumentValue(e, fnPool, d, requireValue); if (val === logic_1.Ternary.Never) { continue; } const x = e; x.certainty = val === logic_1.Ternary.Always ? linter_format_1.LintingResultCertainty.Certain : linter_format_1.LintingResultCertainty.Uncertain; res.push(x); } return res; }); }, prettyPrint: function_finder_util_1.functionFinderUtil.prettyPrint('network operations'), info: { name: 'Network Functions', tags: [linter_tags_1.LintingRuleTag.Reproducibility, linter_tags_1.LintingRuleTag.Security, linter_tags_1.LintingRuleTag.Performance, linter_tags_1.LintingRuleTag.Smell], // ensures all network functions found are actually network functions through its limited config, but doesn't find all network functions since the config is pre-crawled, and the DFG may be over-approximated certainty: linter_format_1.LintingRuleCertainty.BestEffort, description: 'Marks network functions that execute network operations, such as downloading files or making HTTP requests.', defaultConfig: { fns: [ // subset of default network functions provided by manually reviewed results from analysis based on the signature database, see the dirty-network-funcs-test branch there ...['oauth_endpoint', 'DELETE', 'PATCH', 'HEAD', 'GET', 'POST', 'PUT', 'BROWSE', 'RETRY', 'VERB', 'content', 'handle', 'get_callback', 'VERB'].map(f => identifier_1.Identifier.make(f, 'httr')), ...['read.table', 'read.csv', 'read.csv2', 'read.delim', 'read.delim2', 'download.file'].map(f => identifier_1.Identifier.make(f, 'utils')), ...['socketConnection', 'readRDS', 'url', 'gzcon', 'readlines', 'readLines', 'source', 'load', 'scan'].map(f => identifier_1.Identifier.make(f, 'base')), ...['nslookup', 'new_handle', 'multi_download', 'curl', 'curl_upload', 'curl_echo', 'curl_download', 'curl_fetch_memory'].map(f => identifier_1.Identifier.make(f, 'curl')), ...['read_html', 'read_xml'].map(f => identifier_1.Identifier.make(f, 'xml2')), ...['download_html', 'html_nodes', 'html_text'].map(f => identifier_1.Identifier.make(f, 'rvest')), ...['shared_drive_get', 'shared_drive_rm', 'drive_download', 'drive_get'].map(f => identifier_1.Identifier.make(f, 'googledrive')), ...['s3read_using', 's3write_using'].map(f => identifier_1.Identifier.make(f, 'aws.s3')), ...['url_filename', 'url_accessible', 'url_destination'].map(f => identifier_1.Identifier.make(f, 'xfun')), ...['source_url', 'source_gist'].map(f => identifier_1.Identifier.make(f, 'devtools')), ...['install_bioc', 'install_bitbucket', 'install_cran', 'install_dev', 'install_git', 'install_github', 'install_gitlab', 'install_svn', 'install_url', 'install_version'].flatMap(f => [identifier_1.Identifier.make(f, 'devtools'), identifier_1.Identifier.make(f, 'remotes')]), ...['github_pull', 'update_packages'].map(f => identifier_1.Identifier.make(f, 'remotes')), ...['viewer', 'getDelegatedAzureToken'].map(f => identifier_1.Identifier.make(f, 'rstudioapi')), ...['runGist', 'runUrl', 'httpResponse', 'session'].map(f => identifier_1.Identifier.make(f, 'shiny')), ...['create_from_github', 'use_git_remote', 'use_github_action', 'use_github_file', 'use_tidy_thanks'].map(f => identifier_1.Identifier.make(f, 'usethis')), identifier_1.Identifier.make('copy_to', 'dplyr'), identifier_1.Identifier.make('getURL', 'RCurl'), identifier_1.Identifier.make('fread', 'data.table'), identifier_1.Identifier.make('getForm', 'rBDAT'), identifier_1.Identifier.make('fromJSON', 'jsonlite'), identifier_1.Identifier.make('read.xlsx', 'openxlsx'), identifier_1.Identifier.make('storage_download', 'googleCloudStorageR'), identifier_1.Identifier.make('AnnotationHub', 'AnnotationHub'), identifier_1.Identifier.make('ExperimentHub', 'ExperimentHub'), identifier_1.Identifier.make('datasource', 'readr'), identifier_1.Identifier.make('melt_csv', 'meltr'), identifier_1.Identifier.make('addServer', 'rsconnect'), identifier_1.Identifier.make('vroom', 'vroom'), ].map(f => ({ name: f, onlyTriggerWithArgument: /^(https?|ftps?):\/\// })) } } }; //# sourceMappingURL=network-functions.js.map